host.message(tr("Saving shot to <br><b>%s</b>") % paths[0]) else: host.error("Can't find channel %s" % self.active_channel) active_channel_handler = ActiveChannelHandler(saver) host.activate_on_gui_event("Focus Changed", active_channel_handler) host.activate_on_shortcut(SSO_BUTTON_ONE, active_channel_handler.save_shot) if EVENT_TYPE: def handler(ev): if not EVENT_OBJECTS or ev.origin_object.name in EVENT_OBJECTS: saver.save_shots() host.activate_on_events(EVENT_TYPE, "", handler) if SSA_INTERVAL: dt_start_ = datetime.datetime.strptime( "%s %s" % (SSA_DAY_START, SSA_TIME_START), "%d.%m.%Y %H:%M:%S" ) dt_end_ = datetime.datetime.strptime( "%s %s" % (SSA_DAY_STOP, SSA_TIME_STOP), "%d.%m.%Y %H:%M:%S" ) assert dt_start_ <= dt_end_, tr("Datetime end must be lower than datetime start") td = datetime.timedelta(minutes=SSA_INTERVAL) while dt_start_ <= dt_end_: saver.save_shots(dt=dt_start_) dt_start_ += td
if self.temp_dict[sensor] >= datetime.now() - timedelta( seconds=self.stop_sensor_time): return logger.debug(sensor) logger.debug(self.temp_dict) for sens in self.temp_dict.copy(): if self.temp_dict[sens] <= datetime.now() - timedelta( seconds=self.stop_sensor_time): del self.temp_dict[sens] alarm_list = self.orion_assotiation.get(sensor) logger.debug("%s сработал для каналов %s" % (sensor, alarm_list)) if alarm_list: obj.fire_event_v2("Association Orion", data=json.dumps({ "associated_channel": alarm_list, "ev_type": ev.type })) self.alarm_obj.attention(alarm_list) self.temp_dict[sensor] = datetime.now() host.stats()["run_count"] += 1 if not all([ALARM_TEMPLATE_AFTER, SERVER_ORION]): raise ValueError("Заполните параметры!") oa = OrionArmed(MON, ALARM_TEMPLATE_AFTER, TIMEOUT, STOP_SENSOR_TIME, SERVER_ORION) for event in orion_event: host.activate_on_events(event, "", oa.catch_event)
def activate_on_events(self): """Add activate on selected events handler""" host.activate_on_events(self.__event_types[0], "", self) host.activate_on_events(self.__event_types[1], "", self)
if ev.type == "Disconnected From %1": server_guid = obj_storage.associations_network_nodes_with_servers.get( ev.p1) if not server_guid: logger.debug( "No server guid found for disconnected server: %s", ev.p1) return res = obj_storage.association_local_grabbers_with_remote_servers.get( server_guid) if not res: logger.debug("No grabbers found for disconnected server: %s", ev.p1) return logger.debug("Disconnection of %s detected", ev.p1) self.disconnected_servers[server_guid] = time.time() if not self._launch_running: self._loop_timer() if __name__ == host.stats().parent().guid: assert host.settings( "" ).guid != "client", "Script starts on Trassir server only, not client" obj_storage = ObjectsStorage() fm = FailoverManager(DELAY_BEFORE_ENABLE_BACKUP_DEVICES) host.activate_on_events("Connected To %1 under %2", "", fm.handler) host.activate_on_events("Disconnected From %1", "", fm.handler)
] logger.debug(carousel_list) for x in [z[1] for z in host.objects_list("IP Device")]: if x in carousel_list: raise ValueError( host.tr("Имеется IP устройство с именем канала %s") % host.object(x).name ) logger.debug("list %s done!" % carousel_list) return {x: z for x, z in enumerate(carousel_list)} def user_login(ev): if ev.username == USER: slide.hand_using_carousel(False) slide = Carousel( initialization(), HAND_USING, ("show_%s" % choice_dict[CHOICE]).lower() ) if ALARM_TEMPLATE: for event_type in event.compil_event(): host.activate_on_events(event_type, "", slide.attention) host.activate_on_shortcut("F1", lambda: slide.hand_using_carousel(False)) host.activate_on_shortcut("F2", lambda: slide.hand_using_carousel(True)) host.activate_on_shortcut("F5", lambda: slide.hand_using_go("up")) host.activate_on_shortcut("F6", lambda: slide.hand_using_go("down")) host.activate_on_gui_event("Focus Changed", slide.mous_handler) if USER: host.activate_on_events("Login Successful, %1 from %2", "", user_login)
config = ConfigManager(*config_fields) def event_handler(ev): if config.borders.is_working_border(ev.origin): with lock: if ev.type in EVENTS_INCREASE: config.peoples_current.value += 1 else: config.peoples_current.value -= 1 host.stats()["run_count"] = config.peoples_current.value for event in EVENTS_INCREASE: host.activate_on_events(event, "", event_handler) for event in EVENTS_DECREASE: host.activate_on_events(event, "", event_handler) @app.route("index") class IndexHandler(BaseHandler): __template__ = "index.mako" title = host.tr("Главная") def get(self, request, *args, **kwargs): return self.render() def post(self, request, *args, **kwargs):
def gpio_handler(ev): global last_user if not USERS: return if ev.origin_object.name == INPUT_OBJECT: if ev.type == "Input Low to High": source = USER_RED else: source = USER_GREEN for user in USERS.split(','): ur.copy_user_rights(source, user) """ Activate """ if SAVE_BASE_REPORT: save_base_rights() if SAVE_ACL_REPORT: save_acl_rights() if USERS: check_params() if WORK_MODE == "Расписание": schedule = ScheduleObject(INPUT_OBJECT, color_change_handler=change_rights) change_rights(schedule) elif WORK_MODE == "Тревожный вход": if not INPUT_OBJECT: raise ValueError("GPIO input not selected") for event in ["Input Low to High", "Input High to Low"]: host.activate_on_events(event, "", gpio_handler) if BTN: host.activate_on_shortcut(BTN, change_rights_by_btn)