def __str__(self):
        s = "Period \"{}\": ".format(self.name)
        conditions = []
        if self.begintime:
            conditions.append("starts at {}".format(time_str(self.begintime)))
        if self.endtime:
            conditions.append("ends at {}".format(time_str(self.endtime)))
        if self.weekdays is not None:
            conditions.append("on weekdays ({})".format(set_str(self.weekdays, configuration.WEEKDAY_NAMES)))
        if self.monthdays:
            conditions.append("on monthdays ({})".format(set_str(self.monthdays)))
        if self.months:
            conditions.append("in months ({})".format(set_str(self.months, configuration.MONTH_NAMES, offset=1)))
        s += ", ".join(conditions)

        return s
Ejemplo n.º 2
0
        def check_time(dt):

            t = datetime.time(dt.hour, dt.minute, dt.second)
            ts = time_str(t)

            # no start and stop time, means running all day
            if self.begintime is None and self.endtime is None:
                desired_state = InstanceSchedule.STATE_RUNNING
                self._log_debug(DEBUG_CHECK_DT_UNDEFINED_START_STOP,
                                state_str(True), desired_state)
                return desired_state
            elif self.begintime is None:
                # just the end time, stopped if later than that time
                desired_state = InstanceSchedule.STATE_STOPPED if t >= self.endtime else InstanceSchedule.STATE_ANY
                self._log_debug(
                    DEBUG_CHECK_DT_STOP_TIME,
                    check_running_state_str(desired_state), ts, "before" if
                    desired_state == InstanceSchedule.STATE_ANY else "after",
                    time_str(self.endtime), desired_state)
                return desired_state

            elif self.begintime is not None and self.endtime is None:
                # just the start time, running if later that that time
                desired_state = InstanceSchedule.STATE_RUNNING if t >= self.begintime else InstanceSchedule.STATE_ANY
                self._log_debug(
                    DEBUG_CHECK_DT_START_TIME,
                    check_running_state_str(desired_state), ts, "before" if
                    desired_state == InstanceSchedule.STATE_ANY else "after",
                    time_str(self.begintime), desired_state)
                return desired_state
            else:
                # start and stop time, test if time falls in the period defined by these times
                desired_state = InstanceSchedule.STATE_RUNNING \
                    if self.begintime <= t < self.endtime else InstanceSchedule.STATE_STOPPED

                self._log_debug(
                    DEBUG_CHECK_DT_START_AND_STOP,
                    check_running_state_str(desired_state), ts,
                    "within" if desired_state == InstanceSchedule.STATE_RUNNING
                    else "outside", time_str(self.begintime),
                    time_str(self.endtime), desired_state)

            return desired_state