serverwatcher 6.dev6__py3-none-any.whl → 6.dev8__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/cli.py +86 -97
- serverwatcher/tests/test.py +56 -57
- {serverwatcher-6.dev6.dist-info → serverwatcher-6.dev8.dist-info}/METADATA +1 -1
- {serverwatcher-6.dev6.dist-info → serverwatcher-6.dev8.dist-info}/RECORD +7 -7
- {serverwatcher-6.dev6.dist-info → serverwatcher-6.dev8.dist-info}/WHEEL +0 -0
- {serverwatcher-6.dev6.dist-info → serverwatcher-6.dev8.dist-info}/licenses/LICENSE +0 -0
- {serverwatcher-6.dev6.dist-info → serverwatcher-6.dev8.dist-info}/top_level.txt +0 -0
serverwatcher/cli.py
CHANGED
|
@@ -43,7 +43,10 @@ def parse_line(raw: str) -> ParsedArgs:
|
|
|
43
43
|
return ParsedArgs(sub, positional, flags, params)
|
|
44
44
|
|
|
45
45
|
|
|
46
|
-
# command
|
|
46
|
+
# command registry
|
|
47
|
+
COMMANDS: dict[str, 'CommandSpec'] = {}
|
|
48
|
+
|
|
49
|
+
|
|
47
50
|
class ParamSpec:
|
|
48
51
|
def __init__(self, name: str, type_: callable, default: object):
|
|
49
52
|
self.name = name
|
|
@@ -63,6 +66,18 @@ class ChildSpec:
|
|
|
63
66
|
self.params: dict[str, ParamSpec] = {}
|
|
64
67
|
self.flags: dict[str, FlagSpec] = {}
|
|
65
68
|
|
|
69
|
+
def param(self, name: str, type: callable = str, default: object = None):
|
|
70
|
+
def deco(func: callable):
|
|
71
|
+
self.params[name] = ParamSpec(name, type, default)
|
|
72
|
+
return func
|
|
73
|
+
return deco
|
|
74
|
+
|
|
75
|
+
def flag(self, name: str):
|
|
76
|
+
def deco(func: callable):
|
|
77
|
+
self.flags[name] = FlagSpec(name)
|
|
78
|
+
return func
|
|
79
|
+
return deco
|
|
80
|
+
|
|
66
81
|
|
|
67
82
|
class CommandSpec:
|
|
68
83
|
def __init__(self, name: str, func: callable):
|
|
@@ -70,56 +85,27 @@ class CommandSpec:
|
|
|
70
85
|
self.func = func
|
|
71
86
|
self.children: dict[str, ChildSpec] = {}
|
|
72
87
|
|
|
73
|
-
|
|
74
|
-
# DSL object
|
|
75
|
-
class CommandDSL:
|
|
76
|
-
def __init__(self):
|
|
77
|
-
self.registry: dict[str, CommandSpec] = {}
|
|
78
|
-
self._current_command: CommandSpec | None = None
|
|
79
|
-
self._current_child: ChildSpec | None = None
|
|
80
|
-
|
|
81
|
-
def __call__(self, name: str):
|
|
82
|
-
def deco(func: callable):
|
|
83
|
-
cmd = CommandSpec(name, func)
|
|
84
|
-
self.registry[name] = cmd
|
|
85
|
-
self._current_command = cmd
|
|
86
|
-
self._current_child = None
|
|
87
|
-
return func
|
|
88
|
-
return deco
|
|
89
|
-
|
|
90
88
|
def child(self, name: str):
|
|
91
89
|
def deco(func: callable):
|
|
92
|
-
if self._current_command is None:
|
|
93
|
-
raise RuntimeError('child() used outside of a command')
|
|
94
90
|
child = ChildSpec(name, func)
|
|
95
|
-
self.
|
|
96
|
-
self._current_child = child
|
|
91
|
+
self.children[name] = child
|
|
97
92
|
return func
|
|
98
93
|
return deco
|
|
99
94
|
|
|
100
|
-
def param(self, name: str, type: callable = str, default: object = None):
|
|
101
|
-
def deco(func: callable):
|
|
102
|
-
if self._current_child is None:
|
|
103
|
-
raise RuntimeError('param() used outside of a child')
|
|
104
|
-
spec = ParamSpec(name, type, default)
|
|
105
|
-
self._current_child.params[name] = spec
|
|
106
|
-
return func
|
|
107
|
-
return deco
|
|
108
95
|
|
|
109
|
-
|
|
96
|
+
class CommandDSL:
|
|
97
|
+
def __call__(self, name: str):
|
|
110
98
|
def deco(func: callable):
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
spec
|
|
114
|
-
self._current_child.flags[name] = spec
|
|
115
|
-
return func
|
|
99
|
+
spec = CommandSpec(name, func)
|
|
100
|
+
COMMANDS[name] = spec
|
|
101
|
+
return spec
|
|
116
102
|
return deco
|
|
117
103
|
|
|
118
104
|
|
|
119
105
|
command = CommandDSL()
|
|
120
106
|
|
|
121
107
|
|
|
122
|
-
# base CLI
|
|
108
|
+
# base CLI helpers
|
|
123
109
|
class CLIBase:
|
|
124
110
|
def safePrint(self, msg: object = '', end: str = '\n') -> None:
|
|
125
111
|
print(str(msg), end=end)
|
|
@@ -134,29 +120,22 @@ def dispatch(cli: CLIBase, line: str):
|
|
|
134
120
|
if not parsed.subcommand:
|
|
135
121
|
return
|
|
136
122
|
|
|
137
|
-
cmd =
|
|
123
|
+
cmd = COMMANDS.get(parsed.subcommand)
|
|
138
124
|
if cmd is None:
|
|
139
|
-
cli.safePrint(f'Unknown command
|
|
140
|
-
return
|
|
125
|
+
return cli.safePrint(f'Unknown command {parsed.subcommand}')
|
|
141
126
|
|
|
142
|
-
# run command handler to allow any setup logic
|
|
143
127
|
cmd.func(cli, parsed)
|
|
144
128
|
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
if not child_name:
|
|
148
|
-
cli.safePrint('Missing subcommand')
|
|
149
|
-
return
|
|
129
|
+
if not parsed.positional:
|
|
130
|
+
return cli.safePrint('Missing subcommand')
|
|
150
131
|
|
|
132
|
+
child_name = parsed.positional[0]
|
|
151
133
|
child = cmd.children.get(child_name)
|
|
152
134
|
if child is None:
|
|
153
|
-
cli.safePrint(f'Unknown subcommand
|
|
154
|
-
return
|
|
135
|
+
return cli.safePrint(f'Unknown subcommand {child_name}')
|
|
155
136
|
|
|
156
|
-
# second positional is the main argument (stat, etc.)
|
|
157
137
|
stat = parsed.positional[1] if len(parsed.positional) > 1 else None
|
|
158
138
|
|
|
159
|
-
# build wrappers for params and flags
|
|
160
139
|
wrappers: dict[str, callable] = {}
|
|
161
140
|
|
|
162
141
|
for pname, pspec in child.params.items():
|
|
@@ -184,7 +163,6 @@ def dispatch(cli: CLIBase, line: str):
|
|
|
184
163
|
|
|
185
164
|
wrappers[fname] = make_flag
|
|
186
165
|
|
|
187
|
-
# call child with stat and wrappers injected
|
|
188
166
|
return child.func(cli, stat, **wrappers)
|
|
189
167
|
|
|
190
168
|
|
|
@@ -263,33 +241,16 @@ class WatcherCLI(cmd.Cmd, CLIBase):
|
|
|
263
241
|
# stats command
|
|
264
242
|
@command('stats')
|
|
265
243
|
def stats(self: WatcherCLI, parsed: ParsedArgs):
|
|
266
|
-
# no setup needed for stats right now
|
|
267
244
|
pass
|
|
268
245
|
|
|
269
246
|
|
|
270
|
-
@
|
|
271
|
-
def stats_get(self: WatcherCLI, stat: str,
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
@command.param('mode', type=str, default='current')
|
|
279
|
-
def _mode(value):
|
|
280
|
-
return value
|
|
281
|
-
|
|
282
|
-
@command.flag('raw')
|
|
283
|
-
def _raw():
|
|
284
|
-
return False
|
|
285
|
-
|
|
286
|
-
@command.flag('formatted')
|
|
287
|
-
def _formatted():
|
|
288
|
-
return True
|
|
289
|
-
|
|
290
|
-
@command.flag('no-formatted')
|
|
291
|
-
def _no_formatted():
|
|
292
|
-
return False
|
|
247
|
+
@stats.child('get')
|
|
248
|
+
def stats_get(self: WatcherCLI, stat: str, **kwargs):
|
|
249
|
+
rounding = kwargs['rounding']
|
|
250
|
+
mode = kwargs['mode']
|
|
251
|
+
raw = kwargs['raw']
|
|
252
|
+
formatted = kwargs['formatted']
|
|
253
|
+
no_formatted = kwargs['no_formatted']
|
|
293
254
|
|
|
294
255
|
self.watcher.server.refresh()
|
|
295
256
|
|
|
@@ -333,15 +294,39 @@ def stats_get(self: WatcherCLI, stat: str,
|
|
|
333
294
|
self.bprint(f'{name}: {value}{unit}')
|
|
334
295
|
|
|
335
296
|
|
|
297
|
+
@stats_get.param('rounding', type=int, default=2)
|
|
298
|
+
def rounding(value: int):
|
|
299
|
+
return value
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
@stats_get.param('mode', type=str, default='current')
|
|
303
|
+
def mode(value: str):
|
|
304
|
+
return value
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
@stats_get.flag('raw')
|
|
308
|
+
def raw():
|
|
309
|
+
return False
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
@stats_get.flag('formatted')
|
|
313
|
+
def formatted():
|
|
314
|
+
return True
|
|
315
|
+
|
|
316
|
+
|
|
317
|
+
@stats_get.flag('no-formatted')
|
|
318
|
+
def no_formatted():
|
|
319
|
+
return False
|
|
320
|
+
|
|
321
|
+
|
|
336
322
|
# view command
|
|
337
323
|
@command('view')
|
|
338
324
|
def view(self: WatcherCLI, parsed: ParsedArgs):
|
|
339
|
-
# no setup needed for view
|
|
340
325
|
pass
|
|
341
326
|
|
|
342
327
|
|
|
343
|
-
@
|
|
344
|
-
def view_cli(self: WatcherCLI,
|
|
328
|
+
@view.child('cli')
|
|
329
|
+
def view_cli(self: WatcherCLI, _arg: str, **kwargs):
|
|
345
330
|
self.watcher.router.disableOriginOutput()
|
|
346
331
|
self.outputMode = 'cli'
|
|
347
332
|
self.buffer.enabled = True
|
|
@@ -351,8 +336,8 @@ def view_cli(self: WatcherCLI, _stat: str):
|
|
|
351
336
|
self.safePrint(msg)
|
|
352
337
|
|
|
353
338
|
|
|
354
|
-
@
|
|
355
|
-
def view_watcher(self: WatcherCLI,
|
|
339
|
+
@view.child('watcher')
|
|
340
|
+
def view_watcher(self: WatcherCLI, _arg: str, **kwargs):
|
|
356
341
|
self.watcher.router.enableOriginOutput()
|
|
357
342
|
self.outputMode = 'both'
|
|
358
343
|
utils.clearTerminal()
|
|
@@ -364,15 +349,12 @@ def view_watcher(self: WatcherCLI, _stat: str):
|
|
|
364
349
|
# clear command
|
|
365
350
|
@command('clear')
|
|
366
351
|
def clear(self: WatcherCLI, parsed: ParsedArgs):
|
|
367
|
-
# no setup needed
|
|
368
352
|
pass
|
|
369
353
|
|
|
370
354
|
|
|
371
|
-
@
|
|
372
|
-
def clear_buffer(self: WatcherCLI,
|
|
373
|
-
|
|
374
|
-
def _buffer(value: str):
|
|
375
|
-
return value.lower() == 'true'
|
|
355
|
+
@clear.child('buffer')
|
|
356
|
+
def clear_buffer(self: WatcherCLI, _arg: str, **kwargs):
|
|
357
|
+
buffer = kwargs['buffer']
|
|
376
358
|
|
|
377
359
|
if buffer():
|
|
378
360
|
self.buffer.clear()
|
|
@@ -381,31 +363,38 @@ def clear_buffer(self: WatcherCLI, _stat: str, buffer):
|
|
|
381
363
|
self.printHeader()
|
|
382
364
|
|
|
383
365
|
|
|
366
|
+
@clear_buffer.param('buffer', type=str, default='true')
|
|
367
|
+
def buffer(value: str):
|
|
368
|
+
return value.lower() == 'true'
|
|
369
|
+
|
|
370
|
+
|
|
384
371
|
# watcher command
|
|
385
372
|
@command('watcher')
|
|
386
373
|
def watcher(self: WatcherCLI, parsed: ParsedArgs):
|
|
387
|
-
# no setup needed
|
|
388
374
|
pass
|
|
389
375
|
|
|
390
376
|
|
|
391
|
-
@
|
|
392
|
-
def watcher_restart(self: WatcherCLI,
|
|
377
|
+
@watcher.child('restart')
|
|
378
|
+
def watcher_restart(self: WatcherCLI, _arg: str, **kwargs):
|
|
393
379
|
self.watcher.restart_and_wait()
|
|
394
380
|
|
|
395
381
|
|
|
396
|
-
@
|
|
397
|
-
def watcher_schedule(self: WatcherCLI,
|
|
398
|
-
|
|
399
|
-
def _minutes(value: int):
|
|
400
|
-
return value
|
|
382
|
+
@watcher.child('schedule')
|
|
383
|
+
def watcher_schedule(self: WatcherCLI, _arg: str, **kwargs):
|
|
384
|
+
minutes = kwargs['minutes']
|
|
401
385
|
|
|
402
386
|
val = minutes()
|
|
403
387
|
if val is None:
|
|
404
|
-
return self.safePrint('Usage: watcher schedule
|
|
388
|
+
return self.safePrint('Usage: watcher schedule minutes')
|
|
405
389
|
self.watcher.schedule_restart(val)
|
|
406
390
|
|
|
407
391
|
|
|
408
|
-
@
|
|
409
|
-
def watcher_shutdown(self: WatcherCLI,
|
|
392
|
+
@watcher.child('shutdown')
|
|
393
|
+
def watcher_shutdown(self: WatcherCLI, _arg: str, **kwargs):
|
|
410
394
|
self.watcher.shutdown()
|
|
411
395
|
return True
|
|
396
|
+
|
|
397
|
+
|
|
398
|
+
@watcher_schedule.param('minutes', type=int, default=None)
|
|
399
|
+
def minutes(value: int):
|
|
400
|
+
return value
|
serverwatcher/tests/test.py
CHANGED
|
@@ -1,58 +1,57 @@
|
|
|
1
1
|
@command('stats')
|
|
2
|
-
def stats():
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
self.bprint(f'{name}: {value}{unit}')
|
|
2
|
+
def stats(): pass
|
|
3
|
+
|
|
4
|
+
@stats.child('get')
|
|
5
|
+
def get(stat: str):
|
|
6
|
+
self.watcher.server.refresh()
|
|
7
|
+
|
|
8
|
+
unit = ''
|
|
9
|
+
match stat:
|
|
10
|
+
case 'ram':
|
|
11
|
+
value = self.watcher.server.getRAM(rounding=rounding(), gb=raw())
|
|
12
|
+
name = 'RAM'
|
|
13
|
+
unit = ' GB' if gb else ' MB'
|
|
14
|
+
case 'cpu':
|
|
15
|
+
value = self.watcher.server.getCPU(rounding=rounding())
|
|
16
|
+
name = 'CPU'
|
|
17
|
+
unit = '%'
|
|
18
|
+
case 'uptime':
|
|
19
|
+
value = self.watcher.server.getUptime(formatted=formatted())
|
|
20
|
+
name = 'Uptime'
|
|
21
|
+
unit = '' if fmt else 'ms'
|
|
22
|
+
case 'tps':
|
|
23
|
+
value = self.watcher.server.getTPS(rounding=rounding(), mode=mode())
|
|
24
|
+
name = 'TPS'
|
|
25
|
+
case 'players':
|
|
26
|
+
value = self.watcher.server.getPlayers()
|
|
27
|
+
name = 'Players'
|
|
28
|
+
case 'version':
|
|
29
|
+
value = self.watcher.server.version
|
|
30
|
+
name = 'Minecraft version'
|
|
31
|
+
case 'platform':
|
|
32
|
+
value = self.watcher.server.platform
|
|
33
|
+
name = 'Server platform'
|
|
34
|
+
case _:
|
|
35
|
+
return self.safePrint('Unknown stat')
|
|
36
|
+
|
|
37
|
+
self.bprint(f'{name}: {value}{unit}')
|
|
38
|
+
|
|
39
|
+
@stats.get.param('rounding', type=int, default=2)
|
|
40
|
+
def rounding(value):
|
|
41
|
+
return value
|
|
42
|
+
|
|
43
|
+
@stats.get.param('mode', type=str, default='current')
|
|
44
|
+
def mode(value):
|
|
45
|
+
return value
|
|
46
|
+
|
|
47
|
+
@stats.get.flag('raw')
|
|
48
|
+
def raw():
|
|
49
|
+
return False
|
|
50
|
+
|
|
51
|
+
@stats.get.flag('formatted')
|
|
52
|
+
def formatted():
|
|
53
|
+
return True
|
|
54
|
+
|
|
55
|
+
@stats.get.flag('no-formatted')
|
|
56
|
+
def no_formatted():
|
|
57
|
+
return False
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
serverwatcher/__init__.py,sha256=Q_afN0XU29n48d6Gf0-LT2lLo3RiTWlHRT6rC_fYbjw,486
|
|
2
2
|
serverwatcher/__main__.py,sha256=XjGcQ_-8p4ttuVYlYEvYKUEvcAsvZUQaEA0mX0ajRbU,3097
|
|
3
|
-
serverwatcher/cli.py,sha256=
|
|
3
|
+
serverwatcher/cli.py,sha256=9OuJYmwHJziY6praO3xHmABAEk6iWALobW7-KgM-kwA,10141
|
|
4
4
|
serverwatcher/validator.py,sha256=aD6GHOz1S5VFC93Mj89WO9vZG1bTjhg7QZbdlvQf4wo,1778
|
|
5
5
|
serverwatcher/watcher.py,sha256=ZiocJpeyhKTGOwYYak36MXNEFpLnpdl9v6BnMPGrBmM,13593
|
|
6
6
|
serverwatcher/configclasses/__init__.py,sha256=YS0KhxtAJGdMcaiFstqTRNxIPLnR7s9v3Tkt5h2uKE4,182
|
|
@@ -10,10 +10,10 @@ serverwatcher/configclasses/watcher.py,sha256=OIAYQZF9hD9e5FbcaYV5N9CAdCZoLgXSqA
|
|
|
10
10
|
serverwatcher/defaultconfigs/config.yaml,sha256=yrJ59Jx0F4TJzE1EdBF5IKPCDqs09XcbKHFfkYGJ1ys,721
|
|
11
11
|
serverwatcher/defaultconfigs/messages.yaml,sha256=jSVEl-RYqPHhe5U5KLl8zfJtUBymvyE74hmzH0RFC_Y,3177
|
|
12
12
|
serverwatcher/defaultconfigs/watcher.yaml,sha256=GlAEKCuzFUSF6wWOqQLFL1CeuPltb1ltfYxFe_FUClw,723
|
|
13
|
-
serverwatcher/tests/test.py,sha256=
|
|
13
|
+
serverwatcher/tests/test.py,sha256=DQtFzxT1ZFBhbq6i0vga_1p1OdfMI8lVSiXmvOWdE-s,1532
|
|
14
14
|
serverwatcher/tests/test2.py,sha256=pDFB3LTZZXdrkofCF9tDGlkUzNXq3AzK225Ww6H2EAw,1702
|
|
15
|
-
serverwatcher-6.
|
|
16
|
-
serverwatcher-6.
|
|
17
|
-
serverwatcher-6.
|
|
18
|
-
serverwatcher-6.
|
|
19
|
-
serverwatcher-6.
|
|
15
|
+
serverwatcher-6.dev8.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
16
|
+
serverwatcher-6.dev8.dist-info/METADATA,sha256=ckZFQW-fd9IE3Sru3B4IlPjMh_4Rqn_yms-Sq7PE9iw,2646
|
|
17
|
+
serverwatcher-6.dev8.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
18
|
+
serverwatcher-6.dev8.dist-info/top_level.txt,sha256=8DJAf8WmmglgtZHkp8aoTriRJ2YPcS4F3DfOIkytASo,14
|
|
19
|
+
serverwatcher-6.dev8.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|