summaryrefslogtreecommitdiff
path: root/kvmd/extras
diff options
context:
space:
mode:
authorDevaev Maxim <[email protected]>2018-09-26 02:57:24 +0300
committerDevaev Maxim <[email protected]>2018-09-26 02:57:24 +0300
commit81a5311349564a1016c4af2bf18ae872b650e85b (patch)
treed01fd027948494e22ae2c14334b98c1515e5e8a4 /kvmd/extras
parentf3946f102fc167efdc53c73412b2c0d6ac6c72c5 (diff)
moved kvmd to the root
Diffstat (limited to 'kvmd/extras')
-rw-r--r--kvmd/extras/__init__.py0
-rw-r--r--kvmd/extras/cleanup/__init__.py37
-rw-r--r--kvmd/extras/cleanup/__main__.py2
-rw-r--r--kvmd/extras/wscli/__init__.py50
-rw-r--r--kvmd/extras/wscli/__main__.py2
5 files changed, 91 insertions, 0 deletions
diff --git a/kvmd/extras/__init__.py b/kvmd/extras/__init__.py
new file mode 100644
index 00000000..e69de29b
--- /dev/null
+++ b/kvmd/extras/__init__.py
diff --git a/kvmd/extras/cleanup/__init__.py b/kvmd/extras/cleanup/__init__.py
new file mode 100644
index 00000000..5ac09ecb
--- /dev/null
+++ b/kvmd/extras/cleanup/__init__.py
@@ -0,0 +1,37 @@
+import os
+import subprocess
+import time
+
+from ...application import init
+from ...logging import get_logger
+
+from ... import gpio
+
+
+# =====
+def main() -> None:
+ config = init()
+ logger = get_logger(0)
+
+ logger.info("Cleaning up ...")
+ with gpio.bcm():
+ for (name, pin) in [
+ ("atx_power_switch", config["atx"]["pinout"]["power_switch"]),
+ ("atx_reset_switch", config["atx"]["pinout"]["reset_switch"]),
+ ("streamer_cap", config["streamer"]["pinout"]["cap"]),
+ ("streamer_conv", config["streamer"]["pinout"]["conv"]),
+ ]:
+ if pin > 0:
+ logger.info("Writing value=0 to pin=%d (%s)", pin, name)
+ gpio.set_output(pin, initial=False)
+
+ streamer = os.path.basename(config["streamer"]["cmd"][0])
+ logger.info("Trying to find and kill %r ...", streamer)
+ try:
+ subprocess.check_output(["killall", streamer], stderr=subprocess.STDOUT)
+ time.sleep(3)
+ subprocess.check_output(["killall", "-9", streamer], stderr=subprocess.STDOUT)
+ except subprocess.CalledProcessError:
+ pass
+
+ logger.info("Bye-bye")
diff --git a/kvmd/extras/cleanup/__main__.py b/kvmd/extras/cleanup/__main__.py
new file mode 100644
index 00000000..031df43e
--- /dev/null
+++ b/kvmd/extras/cleanup/__main__.py
@@ -0,0 +1,2 @@
+from . import main
+main()
diff --git a/kvmd/extras/wscli/__init__.py b/kvmd/extras/wscli/__init__.py
new file mode 100644
index 00000000..aa2d2e63
--- /dev/null
+++ b/kvmd/extras/wscli/__init__.py
@@ -0,0 +1,50 @@
+#!/usr/bin/env python3
+
+
+import sys
+import signal
+import asyncio
+import argparse
+import time
+
+import aiohttp
+
+
+# =====
+async def _run_client(loop: asyncio.AbstractEventLoop, url: str) -> None:
+ def stdin_callback() -> None:
+ line = sys.stdin.buffer.readline().decode()
+ if line:
+ asyncio.ensure_future(ws.send_str(line), loop=loop)
+ else:
+ loop.stop()
+
+ loop.add_reader(sys.stdin.fileno(), stdin_callback)
+
+ async def dispatch() -> None:
+ while True:
+ msg = await ws.receive()
+ if msg.type == aiohttp.WSMsgType.TEXT:
+ print("[%.5f] Received: %s" % (time.time(), msg.data.strip()))
+ else:
+ if msg.type == aiohttp.WSMsgType.CLOSE:
+ await ws.close()
+ elif msg.type == aiohttp.WSMsgType.ERROR:
+ print("[%.5f] Error during receive: %s" % (time.time(), ws.exception()))
+ elif msg.type == aiohttp.WSMsgType.CLOSED:
+ pass
+ break
+
+ async with aiohttp.ClientSession().ws_connect(url) as ws:
+ await dispatch()
+
+
+def main() -> None:
+ parser = argparse.ArgumentParser()
+ parser.add_argument("-u", "--url", default="http://localhost:8081/ws")
+ options = parser.parse_args()
+
+ loop = asyncio.get_event_loop()
+ loop.add_signal_handler(signal.SIGINT, loop.stop)
+ loop.create_task(_run_client(loop, options.url))
+ loop.run_forever()
diff --git a/kvmd/extras/wscli/__main__.py b/kvmd/extras/wscli/__main__.py
new file mode 100644
index 00000000..031df43e
--- /dev/null
+++ b/kvmd/extras/wscli/__main__.py
@@ -0,0 +1,2 @@
+from . import main
+main()