How to use the crontab.crontab.SundayError 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
"""Parse a ranged value in a cronjob"""
        if value.count('/') == 1:
            value, seq = value.split('/')
            try:
                self.seq = self.slice.parse_value(seq)
            except SundayError:
                self.seq = 1
                value = "0-0"
            if self.seq < 1 or self.seq > self.slice.max - 1:
                raise ValueError("Sequence can not be divided by zero or max")
        if value.count('-') == 1:
            vfrom, vto = value.split('-')
            self.vfrom = self.slice.parse_value(vfrom, sunday=0)
            try:
                self.vto = self.slice.parse_value(vto)
            except SundayError:
                if self.vfrom == 1:
                    self.vfrom = 0
                else:
                    self.dangling = 0
                self.vto = self.slice.parse_value(vto, sunday=6)
        elif value == '*':
            self.all()
        else:
            raise ValueError('Unknown cron range value "%s"' % value)
github achaudhry / adhan / crontab / crontab.py View on Github external
"""Parse the value of the cron slice and raise any errors needed"""
        if val == '>':
            val = self.max
        elif val == '<':
            val = self.min
        try:
            out = get_cronvalue(val, self.enum)
        except ValueError:
            raise ValueError("Unrecognised '%s'='%s'" % (self.name, val))
        except KeyError:
            raise KeyError("No enumeration '%s' got '%s'" % (self.name, val))

        if self.max == 6 and int(out) == 7:
            if sunday is not None:
                return sunday
            raise SundayError("Detected Sunday as 7 instead of 0!")

        if int(out) < self.min or int(out) > self.max:
            raise ValueError("Invalid value '%s', expected %d-%d for %s" % (
                str(val), self.min, self.max, self.name))
        return out