handle /etc/dbuscrontab.d as well as /etc/dbuscrontab
authorKonstantin Stepanov <kstep@p-nut.info>
Tue, 21 Dec 2010 19:02:57 +0000 (21:02 +0200)
committerKonstantin Stepanov <kstep@p-nut.info>
Tue, 21 Dec 2010 19:02:57 +0000 (21:02 +0200)
dbuscron/parser.py
dbuscron/shell/main.py

index 92b2708..59f2f4d 100644 (file)
@@ -44,17 +44,23 @@ class CrontabParserError(SyntaxError):
 
         SyntaxError.__init__(self, msg)
 
-def CrontabParser(filename):
-    if os.path.isfile(filename):
-        parser_class = FileParser
+def CrontabParser(*filenames):
+    for filename in filenames:
+        if not os.path.exists(filename):
+            continue
 
-    elif os.path.isdir(filename):
-        parser_class = DirectoryParser
+        if os.path.isfile(filename):
+            parser_class = FileParser
 
-    else:
-        raise SystemError("I can parse only directories or simple files.")
+        elif os.path.isdir(filename):
+            parser_class = DirectoryParser
+
+        else:
+            raise SystemError("I can parse only directories or simple files.")
+
+        return parser_class(filename)
 
-    return parser_class(filename)
+    raise SystemError("Can't find any config file or directory.")
 
 class FileParser(object):
     __fields_sep = re.compile(r'\s+')
index a27f7f0..4291e60 100644 (file)
@@ -46,7 +46,11 @@ def run():
 
     bus = DbusBus(options.sessionaddr)
     commands = Commands()
-    crontab = CrontabParser(options.config)
+
+    config_files = [ options.config ]
+    if not options.config.endswith('.d'):
+        config_files.insert(0, options.config+'.d')
+    crontab = CrontabParser(*config_files)
 
     # 5. load config file
     def load_config(parser):