router-cli 0.1.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- router_cli/__init__.py +3 -0
- router_cli/client.py +883 -0
- router_cli/config.py +66 -0
- router_cli/main.py +704 -0
- router_cli/py.typed +0 -0
- router_cli-0.1.0.dist-info/METADATA +228 -0
- router_cli-0.1.0.dist-info/RECORD +9 -0
- router_cli-0.1.0.dist-info/WHEEL +4 -0
- router_cli-0.1.0.dist-info/entry_points.txt +3 -0
router_cli/config.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"""Configuration loading for router CLI."""
|
|
2
|
+
|
|
3
|
+
import sys
|
|
4
|
+
from pathlib import Path
|
|
5
|
+
|
|
6
|
+
if sys.version_info >= (3, 11):
|
|
7
|
+
import tomllib
|
|
8
|
+
else:
|
|
9
|
+
import tomli as tomllib
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def get_config_paths() -> list[Path]:
|
|
13
|
+
"""Return list of config file paths in order of priority."""
|
|
14
|
+
return [
|
|
15
|
+
Path.cwd() / "config.toml",
|
|
16
|
+
Path.home() / ".config" / "router" / "config.toml",
|
|
17
|
+
Path("/etc/router/config.toml"),
|
|
18
|
+
]
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _load_config_file() -> dict | None:
|
|
22
|
+
"""Load the raw config file if it exists."""
|
|
23
|
+
for config_path in get_config_paths():
|
|
24
|
+
if config_path.exists():
|
|
25
|
+
with open(config_path, "rb") as f:
|
|
26
|
+
return tomllib.load(f)
|
|
27
|
+
return None
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def load_config() -> dict:
|
|
31
|
+
"""Load configuration from TOML file.
|
|
32
|
+
|
|
33
|
+
Searches for config in:
|
|
34
|
+
1. ./config.toml (current directory)
|
|
35
|
+
2. ~/.config/router/config.toml
|
|
36
|
+
3. /etc/router/config.toml
|
|
37
|
+
"""
|
|
38
|
+
config = _load_config_file()
|
|
39
|
+
if config is not None:
|
|
40
|
+
return config.get("router", {})
|
|
41
|
+
|
|
42
|
+
raise FileNotFoundError(
|
|
43
|
+
"No config.toml found. Create one at ~/.config/router/config.toml with:\n"
|
|
44
|
+
"[router]\n"
|
|
45
|
+
'ip = "192.168.1.1"\n'
|
|
46
|
+
'username = "admin"\n'
|
|
47
|
+
'password = "your_password"\n'
|
|
48
|
+
"\n"
|
|
49
|
+
"[known_devices]\n"
|
|
50
|
+
'"AA:BB:CC:DD:EE:FF" = "My Phone"\n'
|
|
51
|
+
'"11:22:33:44:55:66" = "Smart TV"'
|
|
52
|
+
)
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def load_known_devices() -> dict[str, str]:
|
|
56
|
+
"""Load known devices from config file.
|
|
57
|
+
|
|
58
|
+
Returns a dict mapping MAC addresses (uppercase) to aliases.
|
|
59
|
+
"""
|
|
60
|
+
config = _load_config_file()
|
|
61
|
+
if config is None:
|
|
62
|
+
return {}
|
|
63
|
+
|
|
64
|
+
known = config.get("known_devices", {})
|
|
65
|
+
# Normalize MAC addresses to uppercase for case-insensitive matching
|
|
66
|
+
return {mac.upper(): alias for mac, alias in known.items()}
|