Esempio n. 1
0
 def filter_func_unload(
         event: HABApp.core.events.habapp_events.RequestFileUnloadEvent):
     if not func(event.name):
         return None
     name = event.name
     path = event.get_path()
     func_unload(name, path)
Esempio n. 2
0
    def request_file_unload(
            self,
            event: HABApp.core.events.habapp_events.RequestFileUnloadEvent,
            request_lock=True):
        path = event.get_path(HABApp.CONFIG.directories.rules)
        path_str = str(path)

        try:
            if request_lock:
                self.__load_lock.acquire()

            # Only unload already loaded files
            with self.__files_lock:
                already_loaded = path_str in self.files
            if not already_loaded:
                log.warning(
                    f'Rule file {path} is not yet loaded and therefore can not be unloaded'
                )
                return None

            log.debug(f'Removing file: {path}')
            with self.__files_lock:
                rule = self.files.pop(path_str)
            rule.unload()
        except Exception:
            log.error(f"Could not remove {path}!")
            for l in traceback.format_exc().splitlines():
                log.error(l)
            return None
        finally:
            if request_lock:
                self.__load_lock.release()
Esempio n. 3
0
def unload_file(event: HABApp.core.events.habapp_events.RequestFileUnloadEvent):
    path = event.get_path(HABApp.CONFIG.directories.param)

    with LOCK:  # serialize to get proper error messages
        try:
            remove_parameter_file(path.stem)
        except Exception:
            log.error(f"Could not remove parameters from {path.name}!")
            for l in traceback.format_exc().splitlines():
                log.error(l)
            return None

        log.debug(f'Removed params from {path.name}!')
Esempio n. 4
0
def unload_file(event: HABApp.core.events.habapp_events.RequestFileUnloadEvent):
    path = event.get_path(HABApp.CONFIG.directories.param)

    with LOCK:  # serialize to get proper error messages
        try:
            remove_parameter_file(path.stem)
        except Exception as exc:
            e = HABApp.core.logger.HABAppError(log)
            e.add(f"Could not remove parameters from {path.name}!")
            e.add_exception(exc, add_traceback=True)
            e.dump()
            return None

        log.debug(f'Removed params from {path.name}!')