From 0b534c442343f9bd7959f13207da55f45264a5dc Mon Sep 17 00:00:00 2001 From: Graham Bell Date: Mon, 30 Jul 2012 09:59:59 -1000 Subject: [PATCH 1/2] Minor patch for Python 3 compatibility. --- crontab/_crontab.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/crontab/_crontab.py b/crontab/_crontab.py index 6da5af6..d9eafd5 100644 --- a/crontab/_crontab.py +++ b/crontab/_crontab.py @@ -12,6 +12,7 @@ Other licenses may be available upon request. from collections import namedtuple import datetime +import sys _ranges = [ (0, 59), @@ -43,6 +44,12 @@ _aliases = { '@hourly': '0 * * * *', } +if sys.version_info >= (3, 0): + _number_types = (int, float) + xrange = range +else: + _number_types = (int, long, float) + MINUTE = datetime.timedelta(minutes=1) HOUR = datetime.timedelta(hours=1) DAY = datetime.timedelta(days=1) @@ -274,7 +281,7 @@ class CronTab(object): executed. ''' now = now or datetime.datetime.now() - if isinstance(now, (int, long, float)): + if isinstance(now, _number_types): now = datetime.datetime.fromtimestamp(now) # get a reasonable future/past start time future = now.replace(second=0, microsecond=0) + increments[0]() From 1116146ee02993449d2628359ed32d9fb2f7449b Mon Sep 17 00:00:00 2001 From: Graham Bell Date: Fri, 10 Aug 2012 17:25:49 -1000 Subject: [PATCH 2/2] Allow Sunday to be specified as weekday 7. --- crontab/_crontab.py | 20 ++++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/crontab/_crontab.py b/crontab/_crontab.py index d9eafd5..29e9286 100644 --- a/crontab/_crontab.py +++ b/crontab/_crontab.py @@ -195,15 +195,18 @@ class _Matcher(object): end = _end if increment is None: return set([start]) - _assert(_start <= start <= _end, - "range start value %r out of range [%r, %r]", start, _start, _end) - _assert(_start <= end <= _end, - "range end value %r out of range [%r, %r]", end, _start, _end) + _assert(_start <= start <= _end_limit, + "range start value %r out of range [%r, %r]", + start, _start, _end_limit) + _assert(_start <= end <= _end_limit, + "range end value %r out of range [%r, %r]", + end, _start, _end_limit) _assert(start <= end, "range start value %r > end value %r", start, end) return set(range(start, end+1, increment or 1)) _start, _end = _ranges[which] + _end_limit = _end # wildcards if entry in ('*', '?'): if entry == '?': @@ -232,11 +235,20 @@ class _Matcher(object): "you can only use positive increment values, you provided %r", increment) + # allow Sunday to be specified as weekday 7 + if which == 4: + _end_limit = 7 + # handle all of the a,b,c and x-y,a,b entries good = set() for it in entry.split(','): good.update(_parse_piece(it)) + # change Sunday to weekday 0 + if which == 4 and 7 in good: + good.discard(7) + good.add(0) + return good, _end class CronTab(object):