diff options
author | Devaev Maxim <[email protected]> | 2020-09-10 07:30:25 +0300 |
---|---|---|
committer | Devaev Maxim <[email protected]> | 2020-09-10 07:30:25 +0300 |
commit | 967afb2d9a0f4a94026ec612801b6291db5c6a72 (patch) | |
tree | 70823828e4a3f215e055df5b8cda36c0adbed691 /kvmd/apps | |
parent | a6385cd20e4c4119d9679ed6a58fd9e302d10efe (diff) |
refactoring
Diffstat (limited to 'kvmd/apps')
-rw-r--r-- | kvmd/apps/kvmd/api/export.py | 5 | ||||
-rw-r--r-- | kvmd/apps/kvmd/streamer.py | 4 | ||||
-rw-r--r-- | kvmd/apps/kvmd/ugpio.py | 10 |
3 files changed, 10 insertions, 9 deletions
diff --git a/kvmd/apps/kvmd/api/export.py b/kvmd/apps/kvmd/api/export.py index 2e02c929..b659b5fe 100644 --- a/kvmd/apps/kvmd/api/export.py +++ b/kvmd/apps/kvmd/api/export.py @@ -21,7 +21,6 @@ import asyncio -import operator from typing import Any from typing import List @@ -29,6 +28,8 @@ from typing import List from aiohttp.web import Request from aiohttp.web import Response +from .... import tools + from ....plugins.atx import BaseAtx from ..info import InfoManager @@ -78,6 +79,6 @@ class ExportApi: "", ]) elif isinstance(value, dict): - for (sub_key, sub_value) in sorted(value.items(), key=operator.itemgetter(0)): + for (sub_key, sub_value) in tools.sorted_kvs(value): sub_path = (f"{path}_{sub_key}" if sub_key != "parsed_flags" else path) self.__append_prometheus_rows(rows, sub_value, sub_path) diff --git a/kvmd/apps/kvmd/streamer.py b/kvmd/apps/kvmd/streamer.py index f9fffc16..e2c0442c 100644 --- a/kvmd/apps/kvmd/streamer.py +++ b/kvmd/apps/kvmd/streamer.py @@ -24,7 +24,6 @@ import signal import asyncio import asyncio.subprocess import dataclasses -import operator from typing import Tuple from typing import List @@ -37,6 +36,7 @@ import aiohttp from ...logging import get_logger +from ... import tools from ... import aiotools from ... import aioproc from ... import htclient @@ -315,7 +315,7 @@ class Streamer: # pylint: disable=too-many-instance-attributes mtime=float(response.headers["X-Timestamp"]), headers=tuple( (key, value) - for (key, value) in sorted(response.headers.items(), key=operator.itemgetter(0)) + for (key, value) in tools.sorted_kvs(response.headers) if key.lower().startswith("x-ustreamer-") or key.lower() in [ "x-timestamp", "access-control-allow-origin", diff --git a/kvmd/apps/kvmd/ugpio.py b/kvmd/apps/kvmd/ugpio.py index 3f455833..3f62d286 100644 --- a/kvmd/apps/kvmd/ugpio.py +++ b/kvmd/apps/kvmd/ugpio.py @@ -21,7 +21,6 @@ import asyncio -import operator from typing import List from typing import Dict @@ -38,6 +37,7 @@ from ...plugins.ugpio import GpioDriverOfflineError from ...plugins.ugpio import BaseUserGpioDriver from ...plugins.ugpio import get_ugpio_driver_class +from ... import tools from ... import aiotools from ...yamlconf import Section @@ -242,13 +242,13 @@ class UserGpio: notifier=self.__notifier, **drv_config._unpack(ignore=["instance_name", "notifier", "type"]), ) - for (driver, drv_config) in sorted(config.drivers.items(), key=operator.itemgetter(0)) + for (driver, drv_config) in tools.sorted_kvs(config.drivers) } self.__inputs: Dict[str, _GpioInput] = {} self.__outputs: Dict[str, _GpioOutput] = {} - for (channel, ch_config) in sorted(config.scheme.items(), key=operator.itemgetter(0)): + for (channel, ch_config) in tools.sorted_kvs(config.scheme): driver = self.__drivers[ch_config.driver] if ch_config.mode == "input": self.__inputs[channel] = _GpioInput(channel, ch_config, driver) @@ -281,14 +281,14 @@ class UserGpio: def sysprep(self) -> None: get_logger().info("Preparing User-GPIO drivers ...") - for (_, driver) in sorted(self.__drivers.items(), key=operator.itemgetter(0)): + for (_, driver) in tools.sorted_kvs(self.__drivers): driver.prepare() async def systask(self) -> None: get_logger(0).info("Running User-GPIO drivers ...") await asyncio.gather(*[ driver.run() - for (_, driver) in sorted(self.__drivers.items(), key=operator.itemgetter(0)) + for (_, driver) in tools.sorted_kvs(self.__drivers) ]) async def cleanup(self) -> None: |