mirror of
https://github.com/mofeng-git/One-KVM.git
synced 2026-02-01 10:31:54 +08:00
kvmd extra package
This commit is contained in:
@@ -1,7 +1,5 @@
|
||||
import asyncio
|
||||
import argparse
|
||||
import logging
|
||||
import logging.config
|
||||
import time
|
||||
|
||||
from typing import List
|
||||
@@ -14,7 +12,7 @@ from RPi import GPIO
|
||||
|
||||
import aiohttp
|
||||
|
||||
import yaml
|
||||
from .application import init
|
||||
|
||||
from .atx import Atx
|
||||
from .streamer import Streamer
|
||||
@@ -191,13 +189,4 @@ class _Application:
|
||||
|
||||
|
||||
def main() -> None:
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-c", "--config", default="kvmd.yaml", metavar="<path>")
|
||||
options = parser.parse_args()
|
||||
|
||||
with open(options.config) as config_file:
|
||||
config = yaml.load(config_file)
|
||||
logging.captureWarnings(True)
|
||||
logging.config.dictConfig(config["logging"])
|
||||
|
||||
_Application(config["kvmd"]).run()
|
||||
_Application(init()).run()
|
||||
|
||||
22
kvmd/kvmd/application.py
Normal file
22
kvmd/kvmd/application.py
Normal file
@@ -0,0 +1,22 @@
|
||||
import argparse
|
||||
import logging
|
||||
import logging.config
|
||||
|
||||
from typing import Dict
|
||||
|
||||
import yaml
|
||||
|
||||
|
||||
# =====
|
||||
def init() -> Dict:
|
||||
parser = argparse.ArgumentParser()
|
||||
parser.add_argument("-c", "--config", default="kvmd.yaml", metavar="<path>")
|
||||
options = parser.parse_args()
|
||||
|
||||
with open(options.config) as config_file:
|
||||
config = yaml.load(config_file)
|
||||
|
||||
logging.captureWarnings(True)
|
||||
logging.config.dictConfig(config["logging"])
|
||||
|
||||
return config["kvmd"]
|
||||
0
kvmd/kvmd/extra/__init__.py
Normal file
0
kvmd/kvmd/extra/__init__.py
Normal file
53
kvmd/kvmd/extra/wscli.py
Normal file
53
kvmd/kvmd/extra/wscli.py
Normal file
@@ -0,0 +1,53 @@
|
||||
#!/usr/bin/env python3
|
||||
|
||||
|
||||
import sys
|
||||
import signal
|
||||
import asyncio
|
||||
import argparse
|
||||
|
||||
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("Received:", msg.data.strip())
|
||||
else:
|
||||
if msg.type == aiohttp.WSMsgType.CLOSE:
|
||||
await ws.close()
|
||||
elif msg.type == aiohttp.WSMsgType.ERROR:
|
||||
print("Error during receive:", 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()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user