How to use the crontab.crontab.CronItem function in crontab

To help you get started, we’ve selected a few crontab examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github achaudhry / adhan / crontab / crontab.py View on Github external
def setall(self, value, *slices):
        """Parses the various ways date/time frequency can be specified"""
        self.clear()
        if isinstance(value, CronItem):
            slices = value.slices
        elif isinstance(value, datetime):
            slices = [value.minute, value.hour, value.day, value.month, '*']
        elif isinstance(value, time):
            slices = [value.minute, value.hour, '*', '*', '*']
        elif isinstance(value, date):
            slices = [0, 0, value.day, value.month, '*']
          # It might be possible to later understand timedelta objects
          # but there's no convincing mathematics to do the conversion yet.
        elif isinstance(value, list):
            slices = value
        elif slices:
            slices = (value,) + slices
        elif isinstance(value, basestring) and value:
            if value.count(' ') == 4:
                slices = value.strip().split(' ')
github achaudhry / adhan / crontab / crontab.py View on Github external
lines = []
        if self.intab is not None:
            lines = self.intab.split('\n')
        elif filename:
            self.filen = filename
            with codecs.open(filename, 'r', encoding='utf-8') as fhl:
                lines = fhl.readlines()
        elif self.user:
            (out, err) = open_pipe(CRONCMD, l='', **self.user_opt).communicate()
            if err and 'no crontab for' in str(err):
                pass
            elif err:
                raise IOError("Read crontab %s: %s" % (self.user, err))
            lines = out.decode('utf-8').split("\n")
        for line in lines:
            self.append(CronItem(line, cron=self), line, read=True)
github achaudhry / adhan / crontab / crontab.py View on Github external
def new(self, command='', comment='', user=None):
        """
        Create a new cron with a command and comment.

        Returns the new CronItem object.
        """
        if not user and self.user is False:
            raise ValueError("User is required for system crontabs.")
        return self.append(CronItem(None, command, comment, user, self))