Rewrite as Windows Wi-Fi monitor service
This commit is contained in:
47
osu_wifi_login/cli.py
Normal file
47
osu_wifi_login/cli.py
Normal file
@@ -0,0 +1,47 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import argparse
|
||||
import logging
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
from .config import ConfigError, load_config
|
||||
from .service import WifiBackgroundService
|
||||
from .windows import WifiCommandError
|
||||
|
||||
|
||||
def main() -> int:
|
||||
parser = argparse.ArgumentParser(description="OSU Wi-Fi background monitor for Windows")
|
||||
parser.add_argument(
|
||||
"--config",
|
||||
default="config.yaml",
|
||||
help="Path to the YAML configuration file (default: config.yaml)",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--once",
|
||||
action="store_true",
|
||||
help="Run one monitor iteration and exit",
|
||||
)
|
||||
args = parser.parse_args()
|
||||
|
||||
try:
|
||||
config = load_config(Path(args.config))
|
||||
except ConfigError as exc:
|
||||
print(f"Configuration error: {exc}", file=sys.stderr)
|
||||
return 2
|
||||
|
||||
logging.basicConfig(
|
||||
level=getattr(logging, config.logging.level, logging.INFO),
|
||||
format="%(asctime)s [%(levelname)s] %(message)s",
|
||||
)
|
||||
logger = logging.getLogger("osu_wifi_login")
|
||||
|
||||
try:
|
||||
service = WifiBackgroundService(config, logger)
|
||||
return service.run_forever(run_once=args.once)
|
||||
except WifiCommandError as exc:
|
||||
logger.error("%s", exc)
|
||||
return 1
|
||||
except KeyboardInterrupt:
|
||||
logger.info("Stopping OSU Wi-Fi monitor")
|
||||
return 0
|
||||
Reference in New Issue
Block a user