Exemplo n.º 1
0
 def __init__(self,
              uid=None,
              name=None,
              user=None,
              activated=None,
              periodicity=None,
              logs=None,
              environ=None,
              crontab=None,
              logs_limit=25):
     if not uid:
         uid = self.get_uid()
     self.uid = unicode(uid)
     self._crontab = None
     self.crontab = crontab
     self.name = name
     self.user = user
     self.periodicity = periodicity
     self.logs_limit = logs_limit
     self.activated = asbool(activated)
     if logs is not None and isinstance(logs, list):
         logs = [Log.load(l) for l in logs]
     self.logs = logs
     # 2 pass validation for environ
     if not environ:
         environ = {}
     self.environ = environ
     if isinstance(self.environ, basestring): # pragma: no cover
         environ = json.loads(self.environ)
     if self.logs is None:
         self.logs = []
Exemplo n.º 2
0
 def do_import(self, xmlstring):
     crt = self.crontab
     changed = False
     crons = []
     for xcron in lxml.etree.fromstring(xmlstring).xpath('//crons/cron'):
         attrs = dict(xcron.items())
         delete = utils.asbool(attrs.get('remove', None))
         data = {}
         uid = data['uid'] = unicode(attrs['uid'])
         # first try delete
         if delete:
             if data['uid'] in crt.crons:
                 del crt.crons[uid]
                 changed= True
             continue # pragma: no cover
         for k in ['periodicity', 'activated', 'name']:
             if k in attrs:
                 val = attrs[k]
                 if isinstance(val, basestring):
                     val  = unicode(val)
                 if k in ['activated']:
                     val = utils.asbool(val)
                 data[k] = val
         envs = xcron.xpath('environ')
         environ = None
         if len(envs) > 0:
             env = envs[0]
             senv = env.text.strip()
             if senv:
                 data['environ'] = mcrontab.json.loads(senv)
         # Add cron if not in the crontab
         if not uid in crt.crons:
             cron = mcrontab.Cron.load(data, crontab=crt)
             changed = True
             continue
         # if we got there, we are in edit mode
         # try to find the cron to edit
         cron = crt.crons.get(uid, None)
         if not cron: # pragma: no cover
             continue
         for k in data:
             if getattr(cron, k) != data[k]:
                 setattr(cron, k, data[k])
                 changed = True
     if changed:
         crt.save()
Exemplo n.º 3
0
 def test_asboolt(self):
     tests = {
         False:(0, None, -1, '0', False, 
                'off', 'no', 'n', 'f', 'false',),
         True: (1, True, 'y', 'yes', 
                'YES', 't', 'true', 'True', '1',)
     }
     for dest in tests:
         for orig in tests[dest]:
             self.assertEquals(
                 asbool(orig), dest, repr(orig))