summaryrefslogtreecommitdiff
path: root/kvmd/apps
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2018-11-18 08:11:18 +0300
committerDevaev Maxim <[email protected]>2018-11-18 08:11:18 +0300
commit9762c82d0a6c49f052e2d499a6e54585fde4b0a0 (patch)
treeb9a5e844e4656f77deefe5faa6c46ab5d6fde312 /kvmd/apps
parent51dd9a7428fc0249dd605397ccc955a9fd1cd5cd (diff)
moved lua crutch to kvmd
Diffstat (limited to 'kvmd/apps')
-rw-r--r--kvmd/apps/kvmd/__init__.py10
-rw-r--r--kvmd/apps/kvmd/info.py51
-rw-r--r--kvmd/apps/kvmd/server.py13
3 files changed, 68 insertions, 6 deletions
diff --git a/kvmd/apps/kvmd/__init__.py b/kvmd/apps/kvmd/__init__.py
index 155b8141..519adf0b 100644
--- a/kvmd/apps/kvmd/__init__.py
+++ b/kvmd/apps/kvmd/__init__.py
@@ -8,6 +8,7 @@ from ...logging import Log
from ... import gpio
+from .info import InfoManager
from .hid import Hid
from .atx import Atx
from .msd import MassStorageDevice
@@ -24,6 +25,12 @@ def main() -> None:
log = Log(loop)
+ info_manager = InfoManager(
+ meta_path=str(config["info"]["meta"]),
+ extras_path=str(config["info"]["extras"]),
+ loop=loop,
+ )
+
hid = Hid(
reset=int(config["hid"]["pinout"]["reset"]),
device_path=str(config["hid"]["device"]),
@@ -77,12 +84,13 @@ def main() -> None:
Server(
log=log,
+ info_manager=info_manager,
+
hid=hid,
atx=atx,
msd=msd,
streamer=streamer,
- meta_path=str(config["info"]["meta"]),
heartbeat=float(config["server"]["heartbeat"]),
streamer_shutdown_delay=float(config["streamer"]["shutdown_delay"]),
msd_chunk_size=int(config["msd"]["chunk_size"]),
diff --git a/kvmd/apps/kvmd/info.py b/kvmd/apps/kvmd/info.py
new file mode 100644
index 00000000..57b63b0f
--- /dev/null
+++ b/kvmd/apps/kvmd/info.py
@@ -0,0 +1,51 @@
+import os
+import asyncio
+
+from typing import Dict
+
+import dbus # pylint: disable=import-error
+import dbus.exceptions # pylint: disable=import-error
+
+from ...yaml import load_yaml_file
+
+
+# =====
+class InfoManager:
+ def __init__(
+ self,
+ meta_path: str,
+ extras_path: str,
+ loop: asyncio.AbstractEventLoop,
+ ) -> None:
+
+ self.__meta_path = meta_path
+ self.__extras_path = extras_path
+
+ self.__loop = loop
+
+ async def get_meta(self) -> Dict:
+ return (await self.__loop.run_in_executor(None, load_yaml_file, self.__meta_path))
+
+ async def get_extras(self) -> Dict:
+ return (await self.__loop.run_in_executor(None, self.__sync_get_extras))
+
+ def __sync_get_extras(self) -> Dict:
+ try:
+ bus = dbus.SystemBus()
+
+ def is_enabled(daemon: str) -> bool:
+ obj = bus.get_object("org.freedesktop.systemd1", "/org/freedesktop/systemd1")
+ get_unit_state = obj.get_dbus_method("GetUnitFileState", "org.freedesktop.systemd1.Manager")
+ return (get_unit_state(daemon + ".service") in ["enabled", "enabled-runtime", "static", "indirect", "generated"])
+
+ except dbus.exceptions.DBusException:
+ is_enabled = (lambda daemon: True)
+
+ extras: Dict[str, Dict] = {}
+ for app in os.listdir(self.__extras_path):
+ if app[0] != "." and os.path.isdir(os.path.join(self.__extras_path, app)):
+ extras[app] = load_yaml_file(os.path.join(self.__extras_path, app, "manifest.yaml"))
+ daemon = extras[app].get("daemon", "")
+ if isinstance(daemon, str) and daemon.strip():
+ extras[app]["enabled"] = is_enabled(daemon.strip())
+ return extras
diff --git a/kvmd/apps/kvmd/server.py b/kvmd/apps/kvmd/server.py
index ae66cbc4..5a7e33fe 100644
--- a/kvmd/apps/kvmd/server.py
+++ b/kvmd/apps/kvmd/server.py
@@ -18,10 +18,10 @@ from ...logging import Log
from ...aioregion import RegionIsBusyError
-from ...yaml import load_yaml_file
-
from ... import __version__
+from .info import InfoManager
+
from .hid import Hid
from .atx import Atx
@@ -108,12 +108,13 @@ class Server: # pylint: disable=too-many-instance-attributes
def __init__( # pylint: disable=too-many-arguments
self,
log: Log,
+ info_manager: InfoManager,
+
hid: Hid,
atx: Atx,
msd: MassStorageDevice,
streamer: Streamer,
- meta_path: str,
heartbeat: float,
streamer_shutdown_delay: float,
msd_chunk_size: int,
@@ -122,12 +123,13 @@ class Server: # pylint: disable=too-many-instance-attributes
) -> None:
self.__log = log
+ self.__info_manager = info_manager
+
self.__hid = hid
self.__atx = atx
self.__msd = msd
self.__streamer = streamer
- self.__meta_path = meta_path
self.__heartbeat = heartbeat
self.__streamer_shutdown_delay = streamer_shutdown_delay
self.__msd_chunk_size = msd_chunk_size
@@ -190,7 +192,8 @@ class Server: # pylint: disable=too-many-instance-attributes
"streamer": await self.__streamer.get_version(),
},
"streamer": self.__streamer.get_app(),
- "meta": load_yaml_file(self.__meta_path),
+ "meta": await self.__info_manager.get_meta(),
+ "extras": await self.__info_manager.get_extras(),
})
@_wrap_exceptions_for_web("Log error")