def __init__(self, interval, period, synchronized=False, start_time_string='', end_time_string='', timezone=None): super(IntervalTimeSpecification, self).__init__() if interval < 1: raise groc.GrocException('interval must be greater than zero') self.interval = interval self.period = period self.synchronized = synchronized if self.period == HOURS: self.seconds = self.interval * 3600 else: self.seconds = self.interval * 60 self.timezone = _GetTimezone(timezone) # This section sets timezone, start_time, and end_time. if self.synchronized: if start_time_string: raise ValueError( 'start_time_string may not be specified if synchronized is true' ) if end_time_string: raise ValueError( 'end_time_string may not be specified if synchronized is true' ) if (self.seconds > 86400) or ((86400 % self.seconds) != 0): raise groc.GrocException( 'can only use synchronized for periods that' ' divide evenly into 24 hours') # 'synchronized' is equivalent to a time range that covers the entire # range. self.start_time = datetime.time(0, 0) self.end_time = datetime.time(23, 59) elif start_time_string: if not end_time_string: raise ValueError( 'end_time_string must be specified if start_time_string is' ) self.start_time = _GetTime(start_time_string) self.end_time = _GetTime(end_time_string) else: if end_time_string: raise ValueError( 'start_time_string must be specified if end_time_string is' ) self.start_time = None self.end_time = None
def __init__(self, interval, period, synchronized=False): super(IntervalTimeSpecification, self).__init__() if interval < 1: raise groc.GrocException('interval must be greater than zero') self.interval = interval self.period = period self.synchronized = synchronized if self.period == HOURS: self.seconds = self.interval * 3600 else: self.seconds = self.interval * 60 if self.synchronized: if (self.seconds > 86400) or ((86400 % self.seconds) != 0): raise groc.GrocException('can only use synchronized for periods that' ' divide evenly into 24 hours')
def GrocTimeSpecification(schedule, timezone=None): """Factory function. Turns a schedule specification into a TimeSpecification. Arguments: schedule: the schedule specification, as a string timezone: the optional timezone as a string for this specification. Defaults to 'UTC' - valid entries are things like 'Australia/Victoria' or 'PST8PDT'. Returns: a TimeSpecification instance """ parser = groc.CreateParser(schedule) parser.timespec() if parser.getTokenStream().LT(1).getText(): raise groc.GrocException( 'Extra token %r' % parser.getTokenStream().LT(1).getText()) if parser.period_string: return IntervalTimeSpecification(parser.interval_mins, parser.period_string, parser.synchronized) else: return SpecificTimeSpecification(parser.ordinal_set, parser.weekday_set, parser.month_set, parser.monthday_set, parser.time_string, timezone)
def __init__(self, interval, period): super(IntervalTimeSpecification, self).__init__() if interval < 1: raise groc.GrocException("interval must be greater than zero") self.interval = interval self.period = period