1 from __future__ import with_statement
3 from dbuscron.bus import DbusBus
7 head, tail = args[0], args[1:]
9 for t in product(*tail):
15 class CrontabParserError(SyntaxError):
18 class CrontabParser(object):
19 __fields_sep = re.compile(r'\s+')
20 __envvar_sep = re.compile(r'\s*=\s*')
33 def __init__(self, fname):
34 self.__bus = DbusBus()
35 self.__filename = fname
36 self.__environ = dict()
43 # bus type sender interface path member destination args command
45 with open(self.__filename) as f:
50 if not line or line.startswith('#'):
53 parts = self.__fields_sep.split(line, 8)
55 parts = self.__envvar_sep(line, 1)
57 self.__environ[parts[0]] = parts[1]
60 raise SyntaxError('Unexpected number of records at line #%d.' % (lineno))
62 rule = [('s','S'), ('signal','method_call','method_return','error'), (None,), (None,), (None,), (None,), (None,), (None,)]
66 rule[p] = parts[p].split(',')
70 for r in product(*rule):
73 r[0] = self.__bus.system
75 r[0] = self.__bus.session
80 r[7] = r[7].split(';')
83 for i, f in enumerate(self.__fields):
87 class OptionsParser(dict):
88 def __init__(self, opts, args=None):
89 super(OptionsParser, self).__init__()
95 from getopt import getopt
96 go, _ = getopt(args, opts)
100 withval = k+':' in opts
104 if isinstance(self[k], list):
107 self[k] = [ self[k], v ]
113 self[k] = v if withval else 1
115 def __getitem__(self, k):
116 if not self.has_key(k):
118 return super(OptionsParser, self).__getitem__(k)
120 def __getattr__(self, k):