How to use the kervi.spine function in kervi

To help you get started, we’ve selected a few kervi examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github kervi / kervi / kervi / build / lib / kervi / application / __init__.py View on Github external
devices = hal.detect_devices()
                print("devices:")
                _pretty_print(devices)
            exit()

        
        #if settings:
        #    self.settings = app_helpers._deep_update(self.settings, settings)
        #self._validateSettings()
        self.started = False
        import kervi.spine as spine
        from kervi.zmq_spine import _ZMQSpine
        self.spine = _ZMQSpine()
        self.config.network.ipc_root_port = nethelper.get_free_port([self.config.network.ipc_root_port])
        self.spine._init_spine("kervi-main", self.config.network.ipc_root_port, None, self.config.network.ipc_root_address)
        spine.set_spine(self.spine)
        #process._start_root_spine(self.config, True, _ZMQSpine)
        #spine._init_spine("application-" + self.settings["info"]["id"])
        self.spine = spine.Spine()
        self.spine.register_query_handler("GetApplicationInfo", self._get_application_info)
        self.spine.register_query_handler("getProcessInfo", self.get_process_info)
        self.spine.register_event_handler("modulePing", self._module_ping)
        self.spine.register_event_handler("processReady", self._process_ready, scope="app-" + self.config.application.id)
        self._module_processes = []
        self._process_info = []
        self._process_info_lock = threading.Lock()

        self._kervi_modules = []
        self._kervi_modules_lock = threading.Lock()

        #from kervi.utility.storage import init_db
        #init_db(script_name)
github kervi / kervi / kervi / kervi / module / __init__.py View on Github external
def stop(self, force_exit=True, restart=False):
        self.spine.send_command("kervi_action_module_exit")
        self.spine.trigger_event(
            "moduleStopped",
            self.config.module.id
        )
        self._logger.warn("stopping processes")
        process._stop_processes("module-" + self.config.module.id)
        self.spine.trigger_event("processTerminating", None, local_only=True)
        time.sleep(1)
        spine.Spine().stop()
        #for thread in threading.enumerate():
        #    print("running thread",thread.name)
        self._logger.info("module stopped")
        if force_exit:
            import os
            os._exit(0)
github kervi / kervi / kervi / build / lib / kervi / application / __init__.py View on Github external
exit()

        
        #if settings:
        #    self.settings = app_helpers._deep_update(self.settings, settings)
        #self._validateSettings()
        self.started = False
        import kervi.spine as spine
        from kervi.zmq_spine import _ZMQSpine
        self.spine = _ZMQSpine()
        self.config.network.ipc_root_port = nethelper.get_free_port([self.config.network.ipc_root_port])
        self.spine._init_spine("kervi-main", self.config.network.ipc_root_port, None, self.config.network.ipc_root_address)
        spine.set_spine(self.spine)
        #process._start_root_spine(self.config, True, _ZMQSpine)
        #spine._init_spine("application-" + self.settings["info"]["id"])
        self.spine = spine.Spine()
        self.spine.register_query_handler("GetApplicationInfo", self._get_application_info)
        self.spine.register_query_handler("getProcessInfo", self.get_process_info)
        self.spine.register_event_handler("modulePing", self._module_ping)
        self.spine.register_event_handler("processReady", self._process_ready, scope="app-" + self.config.application.id)
        self._module_processes = []
        self._process_info = []
        self._process_info_lock = threading.Lock()

        self._kervi_modules = []
        self._kervi_modules_lock = threading.Lock()

        #from kervi.utility.storage import init_db
        #init_db(script_name)
        from kervi.storage.storage_manager import StorageManager
        self._authentication = StorageManager()
github kervi / kervi / kervi / dashboard.py View on Github external
def __init__(self, panel_id, **kwargs):
        #KerviComponent.__init__(self, panel_id, "Dashboard-panel", name)
        self.spine = spine.Spine()
        self.panel_id = panel_id
        self.ui_parameters = {
            "title":kwargs.get("title", ""),
            "width":kwargs.get("width", 0),
            "height":kwargs.get("height", 0),
            "userLog":kwargs.get("user_log", False),
            "logLength":kwargs.get("log_length", 5),
            "gauge_width":kwargs.get("gauge_width", 0),
            "gauge_height":kwargs.get("gauge_height", 0),
        }
        self.dashboard = None
        self.panel_id = panel_id
        self._user_groups = []
github kervi / kervi / kervi-core / kervi / core / utility / component.py View on Github external
def __init__(self, component_id, component_type, name, **kwargs):
        self.spine = kwargs.get("spine", spine.Spine())
        self._configuration = kwargs.get("configuration", Configuration)
        self._component_id = component_id
        self._component_type = component_type
        self._admin_groups = kwargs.get("admin_groups", [])
        self._user_groups = kwargs.get("user_groups", [])
        self._user_groups += self.admin_groups
        self._name = name
        self._icon = None
        self._visible = True
        self._dashboard_links = []
        self._ui_parameters = {}
        self._settings = Settings(self.component_type + "_" + self.component_id)
        if self.spine:
            self.spine.log.debug("component created:{0}", self.component_id)
            self.spine.register_query_handler(
                "getDashboardComponents",
github kervi / kervi / kervi / utility / process.py View on Github external
def __init__(self, scope, name, config, ipcPort, root_close, **kwargs):
        process_id = groups = kwargs.get("process_id", name)
        self.name = name
        self._do_terminate = False
        self._is_connected = False
        self.port = ipcPort
        self.config = config
        spine._init_spine(name, ipcPort, "tcp://" + config.network.ipc_root_address + ":" + str(config.network.ipc_root_port), config.network.ip)
        self.spine = spine.Spine()
        self.spine.register_command_handler("terminateProcess", self.terminate, scope=scope)
        self.spine.register_query_handler("getProcessInfo", self.get_process_info)
        self.init_process()
        self.spine.send_command("startThreads", scope="process")
github kervi / kervi / kervi / kervi / vision / camera.py View on Github external
def __init__(self, camera, mutex):
        KerviThread.__init__(self)
        self.spine = spine.Spine()
        self.alive = False
        self.camera = camera
        self.mutex = mutex
        if self.spine:
            self.spine.register_command_handler("startThreads", self._start_command)
            self.spine.register_command_handler("stopThreads", self._stop_command)
        #KerviThread.__init__(self)
github kervi / kervi / kervi / kervi / plugin / message_bus / bus_manager.py View on Github external
def load(self, process_id, spine_port, root_address = None, ip=None):
        self._plugin_manager.load_managed_plugins()
        
        for plugin in self._plugin_manager.plugins:
            plugin.load(process_id, spine_port, root_address, ip)
            self._current_bus = plugin.bus
            break
        else:
            self._log.error("No message bus plugin found")

        if self._current_bus:
            import kervi.spine as spine
            spine.set_spine(self._current_bus)
github kervi / kervi / kervi / kervi / module / __init__.py View on Github external
self.bus_manager.load(
                "kervi-module", 
                self.config.network.ipc_module_port,
                "tcp://" + self.config.network.ipc_root_address + ":" + str(self.config.network.ipc_root_port),
                self.config.network.ip
            )
        else:
            self.bus_manager.load(
                "kervi-main", 
                self.config.network.ipc_root_port,
                None,
                self.config.network.ipc_root_address
            )
        
        from kervi import spine
        self.spine = spine.Spine()
        
        self.spine.register_event_handler("processReady", self._process_ready, scope="app-" + self.config.application.id)
        self.spine = spine.Spine()

        self._module_processes = []
        self._process_info = []
        self._process_info_lock = threading.Lock()

        import kervi.hal as hal
        hal_driver = hal._load()
        if hal_driver:
            self._logger.verbose("Using HAL driver: %s", hal_driver)

        self._actions = _ModuleActions(self)
github kervi / kervi / kervi / utility / process.py View on Github external
def _start_root_spine(config, reset_log=False):
    global MAIN_SPINE
    k_logging.init_process_logging("kervi-main", config.log)
    k_logging.KerviLog("kervi main")
    spine._init_spine("kervi-main", config.network.ipc_root_port, None, config.network.ipc_root_address)