summaryrefslogtreecommitdiff
path: root/kvmd
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2020-10-09 11:58:19 +0300
committerDevaev Maxim <[email protected]>2020-10-09 11:58:19 +0300
commitcf5bc84872d4e865bdf96198b40fda47f7f285a2 (patch)
treee37c97146bcdd779b84227a3bc9fa5dc557785a7 /kvmd
parent5bfde6ceae5af9c47c7a86a6ee1d9fb180b39b54 (diff)
refactoring
Diffstat (limited to 'kvmd')
-rw-r--r--kvmd/aioproc.py10
-rw-r--r--kvmd/plugins/msd/otg/helpers.py9
2 files changed, 11 insertions, 8 deletions
diff --git a/kvmd/aioproc.py b/kvmd/aioproc.py
index 4c503bca..65502d35 100644
--- a/kvmd/aioproc.py
+++ b/kvmd/aioproc.py
@@ -23,6 +23,7 @@
import asyncio
import asyncio.subprocess
import signal
+import logging
from typing import Tuple
from typing import List
@@ -46,6 +47,15 @@ async def read_process(cmd: List[str], err_to_null: bool=False) -> Tuple[asyncio
return (proc, stdout.decode(errors="ignore").strip())
+async def log_process(cmd: List[str], logger: logging.Logger) -> asyncio.subprocess.Process: # pylint: disable=no-member
+ (proc, stdout) = await read_process(cmd)
+ if stdout:
+ log = (logger.info if proc.returncode == 0 else logger.error)
+ for line in stdout.split("\n"):
+ log("Console: %s", line)
+ return proc
+
+
def ignore_sigint() -> None:
signal.signal(signal.SIGINT, signal.SIG_IGN)
diff --git a/kvmd/plugins/msd/otg/helpers.py b/kvmd/plugins/msd/otg/helpers.py
index df004c6d..a3c60e02 100644
--- a/kvmd/plugins/msd/otg/helpers.py
+++ b/kvmd/plugins/msd/otg/helpers.py
@@ -59,13 +59,6 @@ async def unlock_drive(base_cmd: List[str]) -> None:
async def _run_helper(cmd: List[str]) -> None:
logger = get_logger(0)
logger.info("Executing helper %s ...", cmd)
-
- (proc, stdout) = await aioproc.read_process(cmd)
-
- if stdout:
- log = (logger.info if proc.returncode == 0 else logger.error)
- for line in stdout.split("\n"):
- log("Console: %s", line)
-
+ proc = await aioproc.log_process(cmd, logger)
if proc.returncode != 0:
raise MsdError(f"Error while helper execution: pid={proc.pid}; retcode={proc.returncode}")