#NEWLINE# def add_task( name , timespec , user , command , environment = None ) : #NEWLINE# #INDENT# "\n    Add a cron task.\n\n    The *command* will be run as *user* periodically.\n\n    You can use any valid `crontab(5)`_ *timespec*, including the\n    ``@hourly``, ``@daily``, ``@weekly``, ``@monthly`` and ``@yearly``\n    shortcuts.\n\n    You can also provide an optional dictionary of environment variables\n    that should be set when running the periodic command.\n\n    Examples::\n\n        from fabtools.cron import add_task\n\n        # Run every month\n        add_task('cleanup', '@monthly', 'alice', '/home/alice/bin/cleanup.sh')\n\n        # Run every tuesday and friday at 5:30am\n        add_task('reindex', '30 5 * * 2,4', 'bob', '/home/bob/bin/reindex.sh')\n\n    .. _crontab(5): http://manpages.debian.net/cgi-bin/man.cgi?query=crontab&sektion=5\n\n    " #NEWLINE# if ( environment is None ) : #NEWLINE# #INDENT# environment = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# #UNINDENT# lines = [ ] #NEWLINE# for ( key , value ) in environment . iteritems ( ) : #NEWLINE# #INDENT# lines . append ( ( '%(key)s=%(value)s\n' % locals ( ) ) ) #NEWLINE# #UNINDENT# lines . append ( ( '%(timespec)s %(user)s %(command)s\n' % locals ( ) ) ) #NEWLINE# from fabtools.require.files import file as require_file #NEWLINE# require_file ( path = ( '/etc/cron.d/%(name)s' % locals ( ) ) , contents = '' . join ( lines ) , owner = 'root' , mode = '0644' , use_sudo = True )