Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def test_number_set_value():
spine = MockupSpine()
number = NumberValue("Dynamic Number", value_id="dn", spine=spine)
number.value = 10
assert number.value == 10
def test_instantiation():
spine = MockupSpine()
component = KerviComponent("test_component", "component", "Test component", spine=spine)
assert component.component_id == "test_component"
assert component.component_type == "component"
assert component.name == "Test component"
assert component.visible
assert "getDashboardComponents" in spine.queryHandlers
assert "getComponentInfo" in spine.queryHandlers
def input(input_id, name, value_class=NumberValue):
"""Add input to controller"""
def _init():
return value_class(
name,
input_id=input_id,
is_input=True,
index=-1
)
def _decorator(cls):
setattr(cls, input_id, _init())
return cls
return _decorator
if opt in ("--start-service"):
service_commands += ["start"]
if opt in ("--stop-service"):
service_commands = ["stop"]
if opt in ("--restart-service"):
service_commands = ["restart"]
if opt in ("--service-status"):
service_commands = ["status"]
if service_commands:
import kervi.hal as hal
hal_driver = hal._load(self.config.platform.driver)
if hal_driver:
hal.service_commands(
service_commands,
self.config.application.name,
self.config.application.id,
script_path
)
exit()
if detect_devices:
import kervi.hal as hal
hal_driver = hal._load(self.config.platform.driver)
if hal_driver:
devices = hal.detect_devices()
print("devices:")
_pretty_print(devices)
exit()
service_commands += ["uninstall"]
if opt in ("--start-service"):
service_commands += ["start"]
if opt in ("--stop-service"):
service_commands = ["stop"]
if opt in ("--restart-service"):
service_commands = ["restart"]
if opt in ("--service-status"):
service_commands = ["status"]
if service_commands:
import kervi.hal as hal
hal_driver = hal._load(self.config.platform.driver)
if hal_driver:
hal.service_commands(
service_commands,
self.config.application.name,
self.config.application.id,
script_path
)
exit()
if detect_devices:
import kervi.hal as hal
hal_driver = hal._load(self.config.platform.driver)
if hal_driver:
devices = hal.detect_devices()
print("devices:")
_pretty_print(devices)
service_commands += ["uninstall"]
if opt in ("--start-service"):
service_commands += ["start"]
if opt in ("--stop-service"):
service_commands = ["stop"]
if opt in ("--restart-service"):
service_commands = ["restart"]
if opt in ("--service-status"):
service_commands = ["status"]
if service_commands:
import kervi.hal as hal
hal_driver = hal._load(self.config.platform.driver)
if hal_driver:
hal.service_commands(
service_commands,
self.config.application.name,
self.config.application.id,
script_path
)
exit()
if detect_devices:
import kervi.hal as hal
hal_driver = hal._load(self.config.platform.driver)
if hal_driver:
devices = hal.detect_devices()
print("devices:")
_pretty_print(devices)
import kervi.hal as hal
hal_driver = hal._load(self.config.platform.driver)
if hal_driver:
hal.service_commands(
service_commands,
self.config.application.name,
self.config.application.id,
script_path
)
exit()
if detect_devices:
import kervi.hal as hal
hal_driver = hal._load(self.config.platform.driver)
if hal_driver:
devices = hal.detect_devices()
print("devices:")
_pretty_print(devices)
exit()
self._log_handler = KerviLogHandler(self.config)
self._log_queue = self._log_handler._log_queue
self._logger = KerviLog("application")
#self._validateSettings()
self.started = False
self._webserver_port = None
try:
from kervi.version import VERSION
except:
VERSION="0.0.0"
self._logger.verbose("kervi version: %s", VERSION)
import kervi.hal as hal
hal_driver = hal._load(self.config.platform.driver)
if hal_driver:
hal.service_commands(
service_commands,
self.config.application.name,
self.config.application.id,
script_path
)
exit()
if detect_devices:
import kervi.hal as hal
hal_driver = hal._load(self.config.platform.driver)
if hal_driver:
devices = hal.detect_devices()
print("devices:")
_pretty_print(devices)
exit()
self._log_handler = KerviLogHandler(self.config)
self._log_queue = self._log_handler._log_queue
self._logger = KerviLog("module")
self._logger.info("Starting kervi module, please wait")
try:
from kervi.version import VERSION
except:
VERSION="0.0.0"
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)
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)