1. Mikhail Korobov
  2. django-fab-deploy

Commits

Mikhail Korobov  committed 1e5d865

fab_deploy.crontab module. Bump version.

  • Participants
  • Parent commits 6b50738
  • Branches default

Comments (0)

Files changed (3)

File fab_deploy/__init__.py

View file
 from fab_deploy.deploy import *
 from fab_deploy.commands import touch, mysqldump, delete_pyc, pip_install, pip_update, restart_apache
 from fab_deploy.django_commands import migrate, manage, syncdb, compress, test, coverage
+from fab_deploy.crontab import crontab_set, crontab_add, crontab_show, crontab_remove, crontab_update
 from fab_deploy.utils import run_as, update_env
 
 

File fab_deploy/crontab.py

View file
+from __future__ import with_statement
+from fabric.api import *
+
+def _marker(marker):
+    return ' # MARKER:%s' % marker if marker else ''
+
+def _get_current():
+    with settings(hide('warnings', 'stdout'), warn_only=True):
+        output = run('crontab -l')
+        return output if output.succeeded else ''
+
+def crontab_set(content):
+    """ Sets crontab content """
+    run("echo '%s'|crontab -" % content)
+
+def crontab_show():
+    """ Shows current crontab """
+    print _get_current()
+
+def crontab_add(content, marker=None):
+    """ Adds line to crontab. Line can be appended with special marker
+    comment so it'll be possible to reliably remove or update it later. """
+    old_crontab = _get_current()
+    crontab_set(old_crontab + '\n' + content + _marker(marker))
+
+def crontab_remove(marker):
+    """ Removes a line added and marked using crontab_add. """
+    lines = [line for line in _get_current().splitlines()
+             if line and not line.endswith(_marker(marker))]
+    crontab_set("\n".join(lines))
+
+def crontab_update(content, marker):
+    """ Adds or updates a line in crontab. """
+    crontab_remove(marker)
+    crontab_add(content, marker)

File setup.py

View file
 #!/usr/bin/env python
 from distutils.core import setup
 
-version='0.0.8'
+version='0.0.9'
 
 setup(
     name='django-fab-deploy',