Repository: privacyidea/crontabparser

Issue:
Time notation does not support forward slashes
See https://github.com/NetKnights-GmbH/privacyidea-appliance/issues/74

Discussion:
coveralls: 
[![Coverage Status](https://coveralls.io/builds/23429453/badge)](https://coveralls.io/builds/23429453)

Coverage increased (+0.1%) to 98.947% when pulling **e1bceb5b1237a838978785ed29a6d92ade7c364b on 3/enable_slash** into **91ec22ab554972bd70873953e5de5c4efca0fe60 on master**.


Patch:
diff --git a/cronjobparser.py b/cronjobparser.py
index c52e0d6..497f4bb 100644
--- a/cronjobparser.py
+++ b/cronjobparser.py
@@ -100,7 +100,7 @@ class CronJob(object):
 
 class CronJobParser(object):
     
-    dtime = Word("0123456789-*")
+    dtime = Word("0123456789-*/")
     command = CharsNotIn("\n#,")
     username = Word(alphanums)
     key = Word(alphanums)
@@ -161,11 +161,12 @@ class CronJobParser(object):
         return the grouped config
         
         """
+        config = []
         # reread the file from dist
         if self.file:
             with codecs.open(self.file, "r", "utf-8") as f:
                 self.content = f.read()
-        config = self.cron_file.parseString(self.content)
+            config = self.cron_file.parseString(self.content)
         return config
     
     def format(self):


Test patch:
diff --git a/test_cronjobparser.py b/test_cronjobparser.py
index 063ef27..1a6fc8f 100644
--- a/test_cronjobparser.py
+++ b/test_cronjobparser.py
@@ -11,6 +11,14 @@ CRONTAB_TMP = "./testdata/tmpfile"
 
 
 class TestCrontabParser(unittest.TestCase):
+    def setUp(self):
+        pass
+
+    def tearDown(self):
+        try:
+            os.unlink(CRONTAB_TMP)
+        except (IOError, OSError):
+            pass
 
     def test_import_from_file(self):
         CP = CronJobParser(CRONTAB_TEST)
@@ -60,8 +68,22 @@ class TestCrontabParser(unittest.TestCase):
         self.assertEqual(len(CP2.config.get("cronjobs")), 7)
         self.assertEqual(CP2.config.get("cronjobs")[6].command, u'bär')
 
-        # remove temporary file
-        os.unlink(CRONTAB_TMP)
+    def test_forward_slash(self):
+        CP = CronJobParser(infile=None)
+        CP.cronjobs.append(CronJob.from_time('cmd', 'user', ['*/5', '*', '*', '*', '*']))
+        config = CP.config
+        self.assertEqual(len(config.get('cronjobs')), 1)
+        self.assertEqual(config.get('cronjobs')[0].minute, '*/5', config.get('cronjobs')[0])
+        CP.save(CRONTAB_TMP)
+        self.assertTrue(os.path.exists(CRONTAB_TMP))
+        # check that we have correctly written the crontab
+        with open(CRONTAB_TMP, 'r') as f:
+            tmp_data = f.read().splitlines()
+            self.assertEqual(tmp_data[-1], str(config.get('cronjobs')[0]), tmp_data)
+        # now re-read the written crontab
+        CP2 = CronJobParser(infile=CRONTAB_TMP)
+        config = CP2.config
+        self.assertEqual(config.get('cronjobs')[0].minute, '*/5', config.get('cronjobs')[0])
 
     def test_cronjob_api(self):
         CP = CronJobParser(CRONTAB_TEST)