diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | kvmd/aiogp.py | 7 | ||||
-rw-r--r-- | kvmd/apps/__init__.py | 2 | ||||
-rw-r--r-- | kvmd/apps/kvmd/info/hw.py | 9 | ||||
-rw-r--r-- | kvmd/env.py | 33 | ||||
-rw-r--r-- | kvmd/plugins/atx/gpio.py | 5 | ||||
-rw-r--r-- | kvmd/plugins/hid/serial.py | 3 | ||||
-rw-r--r-- | kvmd/plugins/msd/otg/__init__.py | 5 | ||||
-rw-r--r-- | kvmd/plugins/msd/otg/drive.py | 6 | ||||
-rw-r--r-- | kvmd/plugins/msd/relay.py | 3 | ||||
-rw-r--r-- | kvmd/plugins/ugpio/gpio.py | 5 | ||||
-rw-r--r-- | kvmd/tools.py | 6 | ||||
-rw-r--r-- | testenv/v2-hdmi-rpi4.override.yaml | 6 | ||||
-rw-r--r-- | testenv/v2-hdmiusb-rpi4.override.yaml | 6 |
14 files changed, 53 insertions, 45 deletions
@@ -91,6 +91,8 @@ run: testenv $(TESTENV_GPIO) --device $(TESTENV_VIDEO):$(TESTENV_VIDEO) \ --device $(TESTENV_GPIO):$(TESTENV_GPIO) \ --env KVMD_GPIO_DEVICE_PATH=$(TESTENV_GPIO) \ + --env KVMD_SYSFS_PREFIX=/fake_sysfs \ + --env KVMD_PROCFS_PREFIX=/fake_procfs \ $(if $(TESTENV_RELAY),--device $(TESTENV_RELAY):$(TESTENV_RELAY),) \ --publish 8080:80/tcp \ -it $(TESTENV_IMAGE) /bin/bash -c " \ diff --git a/kvmd/aiogp.py b/kvmd/aiogp.py index aa7c2778..d4652d53 100644 --- a/kvmd/aiogp.py +++ b/kvmd/aiogp.py @@ -20,7 +20,6 @@ # ========================================================================== # -import os import asyncio import asyncio.queues import threading @@ -36,12 +35,6 @@ from . import aiotools # ===== -# XXX: Do not use this variable for any purpose other than testing. -# It can be removed at any time. -DEVICE_PATH = os.getenv("KVMD_GPIO_DEVICE_PATH", "/dev/gpiochip0") - - -# ===== async def pulse(line: gpiod.Line, delay: float, final: float) -> None: try: line.set_value(1) diff --git a/kvmd/apps/__init__.py b/kvmd/apps/__init__.py index f301e7d5..20d2d4da 100644 --- a/kvmd/apps/__init__.py +++ b/kvmd/apps/__init__.py @@ -302,8 +302,6 @@ def _get_config_scheme() -> Dict: "extras": Option("/usr/share/kvmd/extras", type=valid_abs_dir), "hw": { "vcgencmd_cmd": Option(["/opt/vc/bin/vcgencmd"], type=valid_command), - "procfs_prefix": Option("", type=tools.str_strip), - "sysfs_prefix": Option("", type=tools.str_strip), "state_poll": Option(10.0, type=valid_float_f01), }, }, diff --git a/kvmd/apps/kvmd/info/hw.py b/kvmd/apps/kvmd/info/hw.py index 8df8aee5..e34ace5b 100644 --- a/kvmd/apps/kvmd/info/hw.py +++ b/kvmd/apps/kvmd/info/hw.py @@ -33,6 +33,7 @@ import aiofiles from ....logging import get_logger +from .... import env from .... import aioproc from .base import BaseInfoSubmanager @@ -47,14 +48,10 @@ class HwInfoSubmanager(BaseInfoSubmanager): def __init__( self, vcgencmd_cmd: List[str], - procfs_prefix: str, - sysfs_prefix: str, state_poll: float, ) -> None: self.__vcgencmd_cmd = vcgencmd_cmd - self.__sysfs_prefix = sysfs_prefix - self.__procfs_prefix = procfs_prefix self.__state_poll = state_poll async def get_state(self) -> Dict: @@ -90,7 +87,7 @@ class HwInfoSubmanager(BaseInfoSubmanager): # ===== async def __get_dt_model(self) -> Optional[str]: - model_path = f"{self.__procfs_prefix}/proc/device-tree/model" + model_path = f"{env.PROCFS_PREFIX}/proc/device-tree/model" try: async with aiofiles.open(model_path) as model_file: return (await model_file.read()).strip(" \t\r\n\0") @@ -99,7 +96,7 @@ class HwInfoSubmanager(BaseInfoSubmanager): return None async def __get_cpu_temp(self) -> Optional[float]: - temp_path = f"{self.__sysfs_prefix}/sys/class/thermal/thermal_zone0/temp" + temp_path = f"{env.SYSFS_PREFIX}/sys/class/thermal/thermal_zone0/temp" try: async with aiofiles.open(temp_path) as temp_file: return int((await temp_file.read()).strip()) / 1000 diff --git a/kvmd/env.py b/kvmd/env.py new file mode 100644 index 00000000..3491318a --- /dev/null +++ b/kvmd/env.py @@ -0,0 +1,33 @@ +# ========================================================================== # +# # +# KVMD - The main Pi-KVM daemon. # +# # +# Copyright (C) 2018 Maxim Devaev <[email protected]> # +# # +# This program is free software: you can redistribute it and/or modify # +# it under the terms of the GNU General Public License as published by # +# the Free Software Foundation, either version 3 of the License, or # +# (at your option) any later version. # +# # +# This program is distributed in the hope that it will be useful, # +# but WITHOUT ANY WARRANTY; without even the implied warranty of # +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the # +# GNU General Public License for more details. # +# # +# You should have received a copy of the GNU General Public License # +# along with this program. If not, see <https://www.gnu.org/licenses/>. # +# # +# ========================================================================== # + + +import os + + +# ===== +# XXX: Don't use these variables for any purpose other than testing. +# It can be removed at any time. + +GPIO_DEVICE_PATH = str(os.getenv("KVMD_GPIO_DEVICE_PATH", "/dev/gpiochip0")).strip() + +SYSFS_PREFIX = str(os.getenv("KVMD_SYSFS_PREFIX", "")).strip() +PROCFS_PREFIX = str(os.getenv("KVMD_PROCFS_PREFIX", "")).strip() diff --git a/kvmd/plugins/atx/gpio.py b/kvmd/plugins/atx/gpio.py index 52a52151..b1d6d5d9 100644 --- a/kvmd/plugins/atx/gpio.py +++ b/kvmd/plugins/atx/gpio.py @@ -28,6 +28,7 @@ import gpiod from ...logging import get_logger +from ... import env from ... import aiotools from ... import aiogp @@ -76,7 +77,7 @@ class Plugin(BaseAtx): # pylint: disable=too-many-instance-attributes self.__reset_switch_line: Optional[gpiod.Line] = None self.__reader = aiogp.AioReader( - path=aiogp.DEVICE_PATH, + path=env.GPIO_DEVICE_PATH, consumer="kvmd::atx-gpio::leds", pins={ power_led_pin: aiogp.AioReaderPinParams(power_led_inverted, power_led_debounce), @@ -107,7 +108,7 @@ class Plugin(BaseAtx): # pylint: disable=too-many-instance-attributes assert self.__power_switch_line is None assert self.__reset_switch_line is None - self.__chip = gpiod.Chip(aiogp.DEVICE_PATH) + self.__chip = gpiod.Chip(env.GPIO_DEVICE_PATH) self.__power_switch_line = self.__chip.get_line(self.__power_switch_pin) self.__power_switch_line.request("kvmd::atx-gpio::power_switch", gpiod.LINE_REQ_DIR_OUT, default_vals=[0]) diff --git a/kvmd/plugins/hid/serial.py b/kvmd/plugins/hid/serial.py index c7c1164d..13a2db6d 100644 --- a/kvmd/plugins/hid/serial.py +++ b/kvmd/plugins/hid/serial.py @@ -43,6 +43,7 @@ from ...logging import get_logger from ...keyboard.mappings import KEYMAP +from ... import env from ... import aiotools from ... import aiomulti from ... import aioproc @@ -168,7 +169,7 @@ class _Gpio: if self.__reset_pin >= 0: assert self.__chip is None assert self.__reset_line is None - self.__chip = gpiod.Chip(aiogp.DEVICE_PATH) + self.__chip = gpiod.Chip(env.GPIO_DEVICE_PATH) self.__reset_line = self.__chip.get_line(self.__reset_pin) self.__reset_line.request("kvmd::hid-serial::reset", gpiod.LINE_REQ_DIR_OUT, default_vals=[0]) diff --git a/kvmd/plugins/msd/otg/__init__.py b/kvmd/plugins/msd/otg/__init__.py index 2c795970..ef925065 100644 --- a/kvmd/plugins/msd/otg/__init__.py +++ b/kvmd/plugins/msd/otg/__init__.py @@ -44,7 +44,6 @@ from ....yamlconf import Option from ....validators.os import valid_abs_dir from ....validators.os import valid_command -from .... import tools from .... import aiotools from .... import aiofs @@ -139,7 +138,6 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes remount_cmd: List[str], unlock_cmd: List[str], - sysfs_prefix: str, gadget: str, # XXX: Not from options, see /kvmd/apps/kvmd/__init__.py for details ) -> None: @@ -150,7 +148,7 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes self.__remount_cmd = remount_cmd self.__unlock_cmd = unlock_cmd - self.__drive = Drive(sysfs_prefix, gadget, instance=0, lun=0) + self.__drive = Drive(gadget, instance=0, lun=0) self.__new_file: Optional[aiofiles.base.AiofilesContextManager] = None self.__new_file_written = 0 @@ -170,7 +168,6 @@ class Plugin(BaseMsd): # pylint: disable=too-many-instance-attributes "storage": Option("/var/lib/kvmd/msd", type=valid_abs_dir, unpack_as="storage_path"), "remount_cmd": Option([*sudo, "/usr/bin/kvmd-helper-otgmsd-remount", "{mode}"], type=valid_command), "unlock_cmd": Option([*sudo, "/usr/bin/kvmd-helper-otgmsd-unlock", "unlock"], type=valid_command), - "sysfs_prefix": Option("", type=tools.str_strip), } async def get_state(self) -> Dict: diff --git a/kvmd/plugins/msd/otg/drive.py b/kvmd/plugins/msd/otg/drive.py index ff91afcf..a0a0d82b 100644 --- a/kvmd/plugins/msd/otg/drive.py +++ b/kvmd/plugins/msd/otg/drive.py @@ -23,6 +23,8 @@ import os import errno +from .... import env + from .. import MsdOperationError @@ -34,9 +36,9 @@ class MsdDriveLockedError(MsdOperationError): # ===== class Drive: - def __init__(self, prefix: str, gadget: str, instance: int, lun: int) -> None: + def __init__(self, gadget: str, instance: int, lun: int) -> None: self.__path = os.path.join( - f"{prefix}/sys/kernel/config/usb_gadget", + f"{env.SYSFS_PREFIX}/sys/kernel/config/usb_gadget", gadget, f"functions/mass_storage.usb{instance}/lun.{lun}", ) diff --git a/kvmd/plugins/msd/relay.py b/kvmd/plugins/msd/relay.py index d1d91841..fe1c7784 100644 --- a/kvmd/plugins/msd/relay.py +++ b/kvmd/plugins/msd/relay.py @@ -39,6 +39,7 @@ import gpiod from ...logging import get_logger +from ... import env from ... import aiotools from ... import aiofs from ... import aiogp @@ -172,7 +173,7 @@ class _Gpio: assert self.__target_line is None assert self.__reset_line is None - self.__chip = gpiod.Chip(aiogp.DEVICE_PATH) + self.__chip = gpiod.Chip(env.GPIO_DEVICE_PATH) self.__target_line = self.__chip.get_line(self.__target_pin) self.__target_line.request("kvmd::msd-relay::target", gpiod.LINE_REQ_DIR_OUT, default_vals=[0]) diff --git a/kvmd/plugins/ugpio/gpio.py b/kvmd/plugins/ugpio/gpio.py index 7c3f317c..4d50d4fc 100644 --- a/kvmd/plugins/ugpio/gpio.py +++ b/kvmd/plugins/ugpio/gpio.py @@ -25,6 +25,7 @@ from typing import Optional import gpiod +from ... import env from ... import aiotools from ... import aiogp @@ -58,13 +59,13 @@ class Plugin(BaseUserGpioDriver): def prepare(self) -> None: assert self.__reader is None self.__reader = aiogp.AioReader( - path=aiogp.DEVICE_PATH, + path=env.GPIO_DEVICE_PATH, consumer="kvmd::ugpio-gpio::inputs", pins=self.__input_pins, notifier=self._notifier, ) - self.__chip = gpiod.Chip(aiogp.DEVICE_PATH) + self.__chip = gpiod.Chip(env.GPIO_DEVICE_PATH) for (pin, initial) in self.__output_pins.items(): line = self.__chip.get_line(pin) line.request("kvmd::ugpio-gpio::outputs", gpiod.LINE_REQ_DIR_OUT, default_vals=[int(initial or False)]) diff --git a/kvmd/tools.py b/kvmd/tools.py index 679a7e8d..6d10e227 100644 --- a/kvmd/tools.py +++ b/kvmd/tools.py @@ -28,12 +28,6 @@ from typing import List from typing import Dict from typing import Hashable from typing import TypeVar -from typing import Any - - -# ===== -def str_strip(arg: Any) -> str: - return str(arg).strip() # ===== diff --git a/testenv/v2-hdmi-rpi4.override.yaml b/testenv/v2-hdmi-rpi4.override.yaml index 2d2bf678..348f3c50 100644 --- a/testenv/v2-hdmi-rpi4.override.yaml +++ b/testenv/v2-hdmi-rpi4.override.yaml @@ -2,11 +2,6 @@ kvmd: server: unix_mode: 0666 - info: - hw: - procfs_prefix: /fake_procfs - sysfs_prefix: /fake_sysfs - hid: keyboard: device: /dev/null @@ -17,7 +12,6 @@ kvmd: msd: remount_cmd: /bin/true unlock_cmd: /bin/true - sysfs_prefix: /fake_sysfs streamer: desired_fps: 30 diff --git a/testenv/v2-hdmiusb-rpi4.override.yaml b/testenv/v2-hdmiusb-rpi4.override.yaml index c16d8867..60442fae 100644 --- a/testenv/v2-hdmiusb-rpi4.override.yaml +++ b/testenv/v2-hdmiusb-rpi4.override.yaml @@ -2,11 +2,6 @@ kvmd: server: unix_mode: 0666 - info: - hw: - procfs_prefix: /fake_procfs - sysfs_prefix: /fake_sysfs - hid: keyboard: device: /dev/null @@ -17,7 +12,6 @@ kvmd: msd: remount_cmd: /bin/true unlock_cmd: /bin/true - sysfs_prefix: /fake_sysfs streamer: cmd: |