示例#1
0
    def _expand_cronspec(cronspec, max_):
        """Takes the given cronspec argument in one of the forms::

            int         (like 7)
            basestring  (like '3-5,*/15', '*', or 'monday')
            set         (like set([0,15,30,45]))
            list        (like [8-17])

        And convert it to an (expanded) set representing all time unit
        values on which the crontab triggers.  Only in case of the base
        type being 'basestring', parsing occurs.  (It is fast and
        happens only once for each crontab instance, so there is no
        significant performance overhead involved.)

        For the other base types, merely Python type conversions happen.

        The argument `max_` is needed to determine the expansion of '*'.

        """
        if isinstance(cronspec, int):
            result = set([cronspec])
        elif isinstance(cronspec, basestring):
            result = crontab_parser(max_).parse(cronspec)
        elif isinstance(cronspec, set):
            result = cronspec
        elif is_iterable(cronspec):
            result = set(cronspec)
        else:
            raise TypeError(
                    "Argument cronspec needs to be of any of the "
                    "following types: int, basestring, or an iterable type. "
                    "'%s' was given." % type(cronspec))

        # assure the result does not exceed the max
        for number in result:
            if number >= max_:
                raise ValueError(
                        "Invalid crontab pattern. Valid "
                        "range is 0-%d. '%d' was found." % (max_ - 1, number))

        return result
示例#2
0
文件: schedules.py 项目: jokar/minion
    def _expand_cronspec(cronspec, max_):
        """Takes the given cronspec argument in one of the forms::

            int         (like 7)
            basestring  (like '3-5,*/15', '*', or 'monday')
            set         (like set([0,15,30,45]))
            list        (like [8-17])

        And convert it to an (expanded) set representing all time unit
        values on which the crontab triggers.  Only in case of the base
        type being 'basestring', parsing occurs.  (It is fast and
        happens only once for each crontab instance, so there is no
        significant performance overhead involved.)

        For the other base types, merely Python type conversions happen.

        The argument `max_` is needed to determine the expansion of '*'.

        """
        if isinstance(cronspec, int):
            result = set([cronspec])
        elif isinstance(cronspec, basestring):
            result = crontab_parser(max_).parse(cronspec)
        elif isinstance(cronspec, set):
            result = cronspec
        elif is_iterable(cronspec):
            result = set(cronspec)
        else:
            raise TypeError(
                "Argument cronspec needs to be of any of the "
                "following types: int, basestring, or an iterable type. "
                "'%s' was given." % type(cronspec))

        # assure the result does not exceed the max
        for number in result:
            if number >= max_:
                raise ValueError("Invalid crontab pattern. Valid "
                                 "range is 0-%d. '%d' was found." %
                                 (max_ - 1, number))

        return result
示例#3
0
 def test_is_iterable(self):
     for a in "f", ["f"], ("f", ), {"f": "f"}:
         self.assertTrue(utils.is_iterable(a))
     for b in object(), 1:
         self.assertFalse(utils.is_iterable(b))
示例#4
0
 def test_is_iterable(self):
     for a in "f", ["f"], ("f", ), {"f": "f"}:
         self.assertTrue(utils.is_iterable(a))
     for b in object(), 1:
         self.assertFalse(utils.is_iterable(b))
示例#5
0
 def test_is_iterable(self):
     for a in 'f', ['f'], ('f', ), {'f': 'f'}:
         self.assertTrue(is_iterable(a))
     for b in object(), 1:
         self.assertFalse(is_iterable(b))
示例#6
0
 def test_is_iterable(self):
     for a in 'f', ['f'], ('f',), {'f': 'f'}:
         self.assertTrue(is_iterable(a))
     for b in object(), 1:
         self.assertFalse(is_iterable(b))