Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
James Socol
committed
Jan 26, 2012
1 parent
6bb6696
commit c907c84
Showing
2 changed files
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# | ||
# {{ header }} | ||
# | ||
|
||
# MAILTO=some-email-list | ||
|
||
HOME=/tmp | ||
|
||
# Every minute! | ||
* * * * * {{ cron }} | ||
|
||
# Every hour. | ||
42 * * * * {{ django }} cleanup | ||
|
||
# Every 2 hours. | ||
1 */2 * * * {{ cron }} something | ||
|
||
# Etc... | ||
|
||
MAILTO=root |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
#!/usr/bin/env python | ||
import os | ||
from optparse import OptionParser | ||
|
||
from jinja2 import Template | ||
|
||
|
||
HEADER = '!!AUTO-GENERATED!! Edit bin/crontab/crontab.tpl instead.' | ||
TEMPLATE = open(os.path.join(os.path.dirname(__file__), 'crontab.tpl')).read() | ||
|
||
|
||
def main(): | ||
parser = OptionParser() | ||
parser.add_option('-w', '--webapp', | ||
help='Location of web app (required)') | ||
parser.add_option('-u', '--user', | ||
help=('Prefix cron with this user. ' | ||
'Only define for cron.d style crontabs.')) | ||
parser.add_option('-p', '--python', default='/usr/bin/python2.6', | ||
help='Python interpreter to use.') | ||
|
||
(opts, args) = parser.parse_args() | ||
|
||
if not opts.webapp: | ||
parser.error('-w must be defined') | ||
|
||
ctx = {'django': 'cd %s; %s manage.py' % (opts.webapp, opts.python)} | ||
ctx['cron'] = '%s cron' % ctx['django'] | ||
|
||
if opts.user: | ||
for k, v in ctx.iteritems(): | ||
ctx[k] = '%s %s' % (opts.user, v) | ||
|
||
# Needs to stay below the opts.user injection. | ||
ctx['python'] = opts.python | ||
ctx['header'] = HEADER | ||
|
||
print Template(TEMPLATE).render(**ctx) | ||
|
||
|
||
if __name__ == '__main__': | ||
main() |