[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[or-cvs] r17583: {projects} Add a way to fetch the current crontab and then install a ne (projects/gettor)



Author: ioerror
Date: 2008-12-11 09:57:53 -0500 (Thu, 11 Dec 2008)
New Revision: 17583

Modified:
   projects/gettor/gettor.py
Log:
Add a way to fetch the current crontab and then install a new crontab that includes the previous one.


Modified: projects/gettor/gettor.py
===================================================================
--- projects/gettor/gettor.py	2008-12-11 14:23:45 UTC (rev 17582)
+++ projects/gettor/gettor.py	2008-12-11 14:57:53 UTC (rev 17583)
@@ -82,13 +82,23 @@
 
 def installCron(rsync):
     # XXX: Check if cron is installed and understands our syntax?
-    echoCmd = ['echo', '3 2 * * * ' + rsync]
+    currentCronTab = getCurrentCrontab()
+    newCronTab = currentCronTab + '\n' + '3 2 * * * ' + rsync
+    echoCmd = ['echo', newCronTab ] 
     cronCmd = ['crontab', '-']
     echoProc = subprocess.Popen(echoCmd, stdout=subprocess.PIPE)
     cronProc = subprocess.Popen(cronCmd, stdin=echoProc.stdout)
     cronProc.communicate()[0]
     return cronProc.returncode
 
+def getCurrentCrontab():
+    # This returns our current crontab
+    savedTab = "# This crontab has been tampered with by gettor.py"
+    currentTab = os.popen("crontab -l")
+    for line in currentTab:
+        savedTab += line
+    return savedTab
+
 def processMail(conf, log, logLang, packageList, blackList, whiteList):
     if packageList is None or len(packageList) < 1:
         log.error(_("Sorry, your package list is unusable."))