serverwatcher 6.dev17__py3-none-any.whl → 6.dev18__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.
- serverwatcher/livecli.py +70 -59
- serverwatcher/watchercli.py +9 -48
- {serverwatcher-6.dev17.dist-info → serverwatcher-6.dev18.dist-info}/METADATA +1 -1
- {serverwatcher-6.dev17.dist-info → serverwatcher-6.dev18.dist-info}/RECORD +7 -7
- {serverwatcher-6.dev17.dist-info → serverwatcher-6.dev18.dist-info}/WHEEL +0 -0
- {serverwatcher-6.dev17.dist-info → serverwatcher-6.dev18.dist-info}/licenses/LICENSE +0 -0
- {serverwatcher-6.dev17.dist-info → serverwatcher-6.dev18.dist-info}/top_level.txt +0 -0
serverwatcher/livecli.py
CHANGED
|
@@ -5,10 +5,6 @@ import termios
|
|
|
5
5
|
import tty
|
|
6
6
|
import asyncio
|
|
7
7
|
|
|
8
|
-
# ---------------------------------------------------------------------------
|
|
9
|
-
# DSL core
|
|
10
|
-
# ---------------------------------------------------------------------------
|
|
11
|
-
|
|
12
8
|
COMMANDS: dict[str, 'CommandSpec'] = {}
|
|
13
9
|
|
|
14
10
|
|
|
@@ -31,16 +27,14 @@ class ChildSpec:
|
|
|
31
27
|
self,
|
|
32
28
|
name,
|
|
33
29
|
func,
|
|
34
|
-
requires_children
|
|
35
|
-
requires_arguments
|
|
36
|
-
requires_params
|
|
37
|
-
requires_flags
|
|
38
|
-
has_arguments
|
|
30
|
+
requires_children=False,
|
|
31
|
+
requires_arguments=False,
|
|
32
|
+
requires_params=False,
|
|
33
|
+
requires_flags=False,
|
|
34
|
+
has_arguments=False,
|
|
39
35
|
):
|
|
40
36
|
if has_arguments and requires_children:
|
|
41
|
-
raise ValueError(
|
|
42
|
-
f'Child \'{name}\' cannot both have arguments and require children'
|
|
43
|
-
)
|
|
37
|
+
raise ValueError(f'Child {name} cannot have arguments and children')
|
|
44
38
|
|
|
45
39
|
self.name = name
|
|
46
40
|
self.func = func
|
|
@@ -52,7 +46,7 @@ class ChildSpec:
|
|
|
52
46
|
|
|
53
47
|
self.params: dict[str, ParamSpec] = {}
|
|
54
48
|
self.flags: dict[str, FlagSpec] = {}
|
|
55
|
-
self.children: dict[str,
|
|
49
|
+
self.children: dict[str, ChildSpec] = {}
|
|
56
50
|
|
|
57
51
|
self.description = getattr(func, '__description__', None)
|
|
58
52
|
|
|
@@ -91,9 +85,7 @@ class CommandSpec:
|
|
|
91
85
|
has_arguments=False,
|
|
92
86
|
):
|
|
93
87
|
if has_arguments and requires_children:
|
|
94
|
-
raise ValueError(
|
|
95
|
-
f"Command '{name}' cannot both have arguments and require children"
|
|
96
|
-
)
|
|
88
|
+
raise ValueError(f'Command {name} cannot have arguments and children')
|
|
97
89
|
|
|
98
90
|
self.name = name
|
|
99
91
|
self.func = func
|
|
@@ -107,18 +99,18 @@ class CommandSpec:
|
|
|
107
99
|
self.params: dict[str, ParamSpec] = {}
|
|
108
100
|
self.flags: dict[str, FlagSpec] = {}
|
|
109
101
|
|
|
110
|
-
self.description = getattr(func,
|
|
102
|
+
self.description = getattr(func, '__description__', None)
|
|
111
103
|
|
|
112
104
|
def param(self, name, type=str, default=None):
|
|
113
105
|
def deco(func):
|
|
114
|
-
pyname = name.replace(
|
|
106
|
+
pyname = name.replace('-', '_')
|
|
115
107
|
self.params[pyname] = ParamSpec(name, type, default, func)
|
|
116
108
|
return func
|
|
117
109
|
return deco
|
|
118
110
|
|
|
119
111
|
def flag(self, name):
|
|
120
112
|
def deco(func):
|
|
121
|
-
pyname = name.replace(
|
|
113
|
+
pyname = name.replace('-', '_')
|
|
122
114
|
self.flags[pyname] = FlagSpec(name, func)
|
|
123
115
|
return func
|
|
124
116
|
return deco
|
|
@@ -132,7 +124,6 @@ class CommandSpec:
|
|
|
132
124
|
return deco
|
|
133
125
|
|
|
134
126
|
|
|
135
|
-
|
|
136
127
|
class CommandDSL:
|
|
137
128
|
def __call__(self, name, **meta):
|
|
138
129
|
def deco(func):
|
|
@@ -145,38 +136,59 @@ class CommandDSL:
|
|
|
145
136
|
command = CommandDSL()
|
|
146
137
|
|
|
147
138
|
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
def generate_help(cmd: CommandSpec) -> str:
|
|
153
|
-
lines: list[str] = []
|
|
154
|
-
lines.append(f'{cmd.name}: {cmd.description or 'No description'}')
|
|
139
|
+
def generate_command_help(cmd: CommandSpec) -> str:
|
|
140
|
+
lines = []
|
|
141
|
+
lines.append(f'{cmd.name}: {cmd.description or "No description"}')
|
|
142
|
+
lines.append(f'Usage: {cmd.name} [child] [arg] [--flags] [params]')
|
|
155
143
|
|
|
156
144
|
if cmd.children:
|
|
157
145
|
lines.append('')
|
|
158
146
|
lines.append('Children:')
|
|
159
147
|
for cname, child in cmd.children.items():
|
|
160
|
-
lines.append(f' {cname}: {child.description or
|
|
148
|
+
lines.append(f' {cname}: {child.description or "No description"}')
|
|
161
149
|
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
)
|
|
150
|
+
if cmd.flags:
|
|
151
|
+
lines.append('')
|
|
152
|
+
lines.append('Flags:')
|
|
153
|
+
for fname in cmd.flags:
|
|
154
|
+
lines.append(f' --{fname}')
|
|
168
155
|
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
156
|
+
if cmd.params:
|
|
157
|
+
lines.append('')
|
|
158
|
+
lines.append('Params:')
|
|
159
|
+
for pname, pspec in cmd.params.items():
|
|
160
|
+
lines.append(f' {pname} (type={pspec.type_.__name__}, default={pspec.default})')
|
|
161
|
+
|
|
162
|
+
return '\n'.join(lines)
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
def generate_child_help(child: ChildSpec) -> str:
|
|
166
|
+
lines = []
|
|
167
|
+
lines.append(f'{child.name}: {child.description or "No description"}')
|
|
168
|
+
lines.append(f'Usage: {child.name} [arg] [--flags] [params]')
|
|
169
|
+
|
|
170
|
+
if child.flags:
|
|
171
|
+
lines.append('')
|
|
172
|
+
lines.append('Flags:')
|
|
173
|
+
for fname in child.flags:
|
|
174
|
+
lines.append(f' --{fname}')
|
|
175
|
+
|
|
176
|
+
if child.params:
|
|
177
|
+
lines.append('')
|
|
178
|
+
lines.append('Params:')
|
|
179
|
+
for pname, pspec in child.params.items():
|
|
180
|
+
lines.append(f' {pname} (type={pspec.type_.__name__}, default={pspec.default})')
|
|
173
181
|
|
|
174
182
|
return '\n'.join(lines)
|
|
175
183
|
|
|
176
184
|
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
185
|
+
def generate_help(obj):
|
|
186
|
+
if isinstance(obj, CommandSpec):
|
|
187
|
+
return generate_command_help(obj)
|
|
188
|
+
if isinstance(obj, ChildSpec):
|
|
189
|
+
return generate_child_help(obj)
|
|
190
|
+
return 'No help available'
|
|
191
|
+
|
|
180
192
|
|
|
181
193
|
@dataclass
|
|
182
194
|
class ParsedArgs:
|
|
@@ -193,9 +205,9 @@ def parse_line(raw: str) -> ParsedArgs:
|
|
|
193
205
|
|
|
194
206
|
parts = raw.split()
|
|
195
207
|
sub = parts[0]
|
|
196
|
-
positional
|
|
197
|
-
flags
|
|
198
|
-
params
|
|
208
|
+
positional = []
|
|
209
|
+
flags = {}
|
|
210
|
+
params = {}
|
|
199
211
|
|
|
200
212
|
for token in parts[1:]:
|
|
201
213
|
if token.startswith('--'):
|
|
@@ -216,27 +228,30 @@ def dispatch(cli, line: str):
|
|
|
216
228
|
|
|
217
229
|
cmd = COMMANDS.get(parsed.subcommand)
|
|
218
230
|
if cmd is None:
|
|
219
|
-
return cli.safePrint(f'Unknown command
|
|
231
|
+
return cli.safePrint(f'Unknown command {parsed.subcommand}')
|
|
220
232
|
|
|
221
|
-
if
|
|
222
|
-
return cli.safePrint(
|
|
233
|
+
if 'help' in parsed.flags:
|
|
234
|
+
return cli.safePrint(generate_help(cmd))
|
|
223
235
|
|
|
224
236
|
cmd.func()
|
|
225
237
|
|
|
226
238
|
if not parsed.positional:
|
|
227
239
|
if cmd.requires_arguments:
|
|
228
|
-
return cli.safePrint(f'Command
|
|
240
|
+
return cli.safePrint(f'Command {cmd.name} requires an argument')
|
|
229
241
|
return cli.safePrint('Missing subcommand')
|
|
230
242
|
|
|
231
243
|
child_name = parsed.positional[0]
|
|
232
244
|
child = cmd.children.get(child_name)
|
|
233
245
|
if child is None:
|
|
234
|
-
return cli.safePrint(f'Unknown subcommand
|
|
246
|
+
return cli.safePrint(f'Unknown subcommand {child_name}')
|
|
247
|
+
|
|
248
|
+
if 'help' in parsed.flags:
|
|
249
|
+
return cli.safePrint(generate_help(child))
|
|
235
250
|
|
|
236
251
|
arg = parsed.positional[1] if len(parsed.positional) > 1 else None
|
|
237
252
|
|
|
238
253
|
if child.requires_arguments and arg is None:
|
|
239
|
-
return cli.safePrint(f'Subcommand
|
|
254
|
+
return cli.safePrint(f'Subcommand {child.name} requires an argument')
|
|
240
255
|
|
|
241
256
|
g = child.func.__globals__
|
|
242
257
|
|
|
@@ -276,25 +291,21 @@ def dispatch(cli, line: str):
|
|
|
276
291
|
return func(cli)
|
|
277
292
|
|
|
278
293
|
|
|
279
|
-
# ---------------------------------------------------------------------------
|
|
280
|
-
# Base LiveCLI
|
|
281
|
-
# ---------------------------------------------------------------------------
|
|
282
|
-
|
|
283
294
|
class LiveCLI(cmd.Cmd):
|
|
284
295
|
prompt = ''
|
|
285
296
|
|
|
286
|
-
def safePrint(self, msg
|
|
297
|
+
def safePrint(self, msg='', end='\n'):
|
|
287
298
|
print(str(msg), end=end)
|
|
288
299
|
|
|
289
|
-
def bprint(self, msg
|
|
300
|
+
def bprint(self, msg):
|
|
290
301
|
self.safePrint(msg)
|
|
291
302
|
|
|
292
|
-
def read_line_raw(self)
|
|
303
|
+
def read_line_raw(self):
|
|
293
304
|
fd = sys.stdin.fileno()
|
|
294
305
|
old = termios.tcgetattr(fd)
|
|
295
306
|
try:
|
|
296
307
|
tty.setraw(fd)
|
|
297
|
-
chars
|
|
308
|
+
chars = []
|
|
298
309
|
while True:
|
|
299
310
|
ch = sys.stdin.read(1)
|
|
300
311
|
if ch in ('\r', '\n'):
|
|
@@ -314,5 +325,5 @@ class LiveCLI(cmd.Cmd):
|
|
|
314
325
|
if stop:
|
|
315
326
|
break
|
|
316
327
|
|
|
317
|
-
def onecmd(self, line
|
|
328
|
+
def onecmd(self, line):
|
|
318
329
|
return dispatch(self, line)
|
serverwatcher/watchercli.py
CHANGED
|
@@ -13,22 +13,16 @@ class WatcherCLI(LiveCLI):
|
|
|
13
13
|
self.buffer = utils.Buffer(enabled=True)
|
|
14
14
|
self.outputMode = 'both'
|
|
15
15
|
|
|
16
|
-
def printHeader(self)
|
|
16
|
+
def printHeader(self):
|
|
17
17
|
self.safePrint(res('<yellow>-----------------------------------'))
|
|
18
18
|
self.safePrint(res('<yellow>-------- <aqua>ServerWatcher CLI <yellow>--------'))
|
|
19
19
|
self.safePrint(res('<yellow>-----------------------------------'))
|
|
20
|
-
self.safePrint('
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
# ---------------------------------------------------------------------------
|
|
24
|
-
# stats command
|
|
25
|
-
# ---------------------------------------------------------------------------
|
|
20
|
+
self.safePrint('')
|
|
26
21
|
|
|
27
22
|
@command('stats', requires_children=True)
|
|
28
23
|
def stats():
|
|
29
24
|
__description__ = 'Retrieve and print server statistics'
|
|
30
25
|
|
|
31
|
-
|
|
32
26
|
@stats.child('get', requires_arguments=False)
|
|
33
27
|
def stats_get(self, arg=None):
|
|
34
28
|
__description__ = 'Retrieve and print all or specific server statistics'
|
|
@@ -36,13 +30,8 @@ def stats_get(self, arg=None):
|
|
|
36
30
|
self.watcher.server.refresh()
|
|
37
31
|
|
|
38
32
|
if arg is not None:
|
|
39
|
-
gb =
|
|
40
|
-
|
|
41
|
-
fmt = True
|
|
42
|
-
elif no_formatted():
|
|
43
|
-
fmt = False
|
|
44
|
-
else:
|
|
45
|
-
fmt = True
|
|
33
|
+
gb = raw()
|
|
34
|
+
fmt = not raw()
|
|
46
35
|
|
|
47
36
|
unit = ''
|
|
48
37
|
match arg:
|
|
@@ -75,45 +64,24 @@ def stats_get(self, arg=None):
|
|
|
75
64
|
|
|
76
65
|
self.bprint(f'{name}: {value}{unit}')
|
|
77
66
|
else:
|
|
78
|
-
return
|
|
79
|
-
|
|
67
|
+
return
|
|
80
68
|
|
|
81
69
|
@stats.get.param('rounding', type=int, default=2)
|
|
82
|
-
def rounding(value
|
|
83
|
-
__description__ = 'placeholder'
|
|
70
|
+
def rounding(value):
|
|
84
71
|
return value
|
|
85
72
|
|
|
86
|
-
|
|
87
73
|
@stats.get.param('mode', type=str, default='current')
|
|
88
|
-
def mode(value
|
|
74
|
+
def mode(value):
|
|
89
75
|
return value
|
|
90
76
|
|
|
91
|
-
|
|
92
77
|
@stats.get.flag('raw')
|
|
93
78
|
def raw():
|
|
94
|
-
|
|
95
|
-
return True # DSL overrides with presence/absence
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
@stats.get.flag('formatted')
|
|
99
|
-
def formatted():
|
|
100
|
-
return True # DSL overrides with presence/absence
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
@stats.get.flag('no-formatted')
|
|
104
|
-
def no_formatted():
|
|
105
|
-
return False # DSL overrides with presence/absence
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
# ---------------------------------------------------------------------------
|
|
109
|
-
# view command
|
|
110
|
-
# ---------------------------------------------------------------------------
|
|
79
|
+
return True
|
|
111
80
|
|
|
112
81
|
@command('view', requires_children=True)
|
|
113
82
|
def view():
|
|
114
83
|
__description__ = 'Switch terminal view'
|
|
115
84
|
|
|
116
|
-
|
|
117
85
|
@view.child('cli')
|
|
118
86
|
def view_cli(self):
|
|
119
87
|
__description__ = 'Switch to CLI view'
|
|
@@ -126,7 +94,6 @@ def view_cli(self):
|
|
|
126
94
|
for msg in self.buffer.captured:
|
|
127
95
|
self.safePrint(msg)
|
|
128
96
|
|
|
129
|
-
|
|
130
97
|
@view.child('watcher')
|
|
131
98
|
def view_watcher(self):
|
|
132
99
|
__description__ = 'Switch to Watcher view'
|
|
@@ -138,16 +105,10 @@ def view_watcher(self):
|
|
|
138
105
|
for msg in self.watcher.router.buffer.captured:
|
|
139
106
|
self.safePrint(msg)
|
|
140
107
|
|
|
141
|
-
|
|
142
|
-
# ---------------------------------------------------------------------------
|
|
143
|
-
# clear command
|
|
144
|
-
# ---------------------------------------------------------------------------
|
|
145
|
-
|
|
146
108
|
@command('clear')
|
|
147
109
|
def clear():
|
|
148
110
|
__description__ = 'Clear the CLI terminal'
|
|
149
111
|
|
|
150
|
-
|
|
151
112
|
@clear.flag('no-buffer')
|
|
152
113
|
def no_buffer():
|
|
153
|
-
return False
|
|
114
|
+
return False
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
serverwatcher/__init__.py,sha256=Q_afN0XU29n48d6Gf0-LT2lLo3RiTWlHRT6rC_fYbjw,486
|
|
2
2
|
serverwatcher/__main__.py,sha256=5geaZQKgLSP1pxnpQPgFy9zAwyyPyTInlbcFxb9OiEw,3016
|
|
3
3
|
serverwatcher/cli.py,sha256=b77rWfjQuqHiRGaVQj-O5EygJGdufMasRBUUqKcasAM,9887
|
|
4
|
-
serverwatcher/livecli.py,sha256=
|
|
4
|
+
serverwatcher/livecli.py,sha256=3KKBb7bGocjXw0c0Eb0ePM8vzwT19rn4BLcvVLhk_Yg,8826
|
|
5
5
|
serverwatcher/validator.py,sha256=aD6GHOz1S5VFC93Mj89WO9vZG1bTjhg7QZbdlvQf4wo,1778
|
|
6
6
|
serverwatcher/watcher.py,sha256=ZiocJpeyhKTGOwYYak36MXNEFpLnpdl9v6BnMPGrBmM,13593
|
|
7
|
-
serverwatcher/watchercli.py,sha256=
|
|
7
|
+
serverwatcher/watchercli.py,sha256=1YeejzOFtgdrFOwNcT61A3QrrCUPza5E79gSWn47gEk,3324
|
|
8
8
|
serverwatcher/configclasses/__init__.py,sha256=YS0KhxtAJGdMcaiFstqTRNxIPLnR7s9v3Tkt5h2uKE4,182
|
|
9
9
|
serverwatcher/configclasses/config.py,sha256=1Upor55QFE4UIOqL9ZYa4U5kbda48GG9HWdRXg8mb_Y,2418
|
|
10
10
|
serverwatcher/configclasses/messages.py,sha256=iOkCvwagngW4aeWD5I6hi6cqqDkzEsFJsLHSuqK-P1s,3467
|
|
@@ -14,8 +14,8 @@ serverwatcher/defaultconfigs/messages.yaml,sha256=jSVEl-RYqPHhe5U5KLl8zfJtUBymvy
|
|
|
14
14
|
serverwatcher/defaultconfigs/watcher.yaml,sha256=GlAEKCuzFUSF6wWOqQLFL1CeuPltb1ltfYxFe_FUClw,723
|
|
15
15
|
serverwatcher/tests/test.py,sha256=EPJXmIJ4lLfuT-xFuAqrh52O_yYTQdQl17Djzr72v18,3711
|
|
16
16
|
serverwatcher/tests/test2.py,sha256=pDFB3LTZZXdrkofCF9tDGlkUzNXq3AzK225Ww6H2EAw,1702
|
|
17
|
-
serverwatcher-6.
|
|
18
|
-
serverwatcher-6.
|
|
19
|
-
serverwatcher-6.
|
|
20
|
-
serverwatcher-6.
|
|
21
|
-
serverwatcher-6.
|
|
17
|
+
serverwatcher-6.dev18.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
18
|
+
serverwatcher-6.dev18.dist-info/METADATA,sha256=DQZH-WYt-5OBl3FHl9uzxo-aMe41lcNmNetdI2cOtXY,2647
|
|
19
|
+
serverwatcher-6.dev18.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
20
|
+
serverwatcher-6.dev18.dist-info/top_level.txt,sha256=8DJAf8WmmglgtZHkp8aoTriRJ2YPcS4F3DfOIkytASo,14
|
|
21
|
+
serverwatcher-6.dev18.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|