serverwatcher 6.dev7__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 +87 -97
- serverwatcher/tests/test.py +56 -57
- {serverwatcher-6.dev7.dist-info → serverwatcher-6.dev8.dist-info}/METADATA +1 -1
- {serverwatcher-6.dev7.dist-info → serverwatcher-6.dev8.dist-info}/RECORD +7 -7
- {serverwatcher-6.dev7.dist-info → serverwatcher-6.dev8.dist-info}/WHEEL +0 -0
- {serverwatcher-6.dev7.dist-info → serverwatcher-6.dev8.dist-info}/licenses/LICENSE +0 -0
- {serverwatcher-6.dev7.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,43 +241,26 @@ 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
|
-
@
|
|
247
|
+
@stats.child('get')
|
|
271
248
|
def stats_get(self: WatcherCLI, stat: str, **kwargs):
|
|
272
|
-
|
|
273
249
|
rounding = kwargs['rounding']
|
|
274
250
|
mode = kwargs['mode']
|
|
275
251
|
raw = kwargs['raw']
|
|
276
252
|
formatted = kwargs['formatted']
|
|
277
253
|
no_formatted = kwargs['no_formatted']
|
|
278
254
|
|
|
279
|
-
@command.param('rounding', type=int, default=2)
|
|
280
|
-
def _rounding(value):
|
|
281
|
-
return value
|
|
282
|
-
|
|
283
|
-
@command.param('mode', type=str, default='current')
|
|
284
|
-
def _mode(value):
|
|
285
|
-
return value
|
|
286
|
-
|
|
287
|
-
@command.flag('raw')
|
|
288
|
-
def _raw():
|
|
289
|
-
return False
|
|
290
|
-
|
|
291
|
-
@command.flag('formatted')
|
|
292
|
-
def _formatted():
|
|
293
|
-
return True
|
|
294
|
-
|
|
295
|
-
@command.flag('no-formatted')
|
|
296
|
-
def _no_formatted():
|
|
297
|
-
return False
|
|
298
|
-
|
|
299
255
|
self.watcher.server.refresh()
|
|
300
256
|
|
|
301
257
|
gb = not raw()
|
|
302
|
-
|
|
258
|
+
if formatted():
|
|
259
|
+
fmt = True
|
|
260
|
+
elif no_formatted():
|
|
261
|
+
fmt = False
|
|
262
|
+
else:
|
|
263
|
+
fmt = True
|
|
303
264
|
|
|
304
265
|
unit = ''
|
|
305
266
|
match stat:
|
|
@@ -332,15 +293,40 @@ def stats_get(self: WatcherCLI, stat: str, **kwargs):
|
|
|
332
293
|
|
|
333
294
|
self.bprint(f'{name}: {value}{unit}')
|
|
334
295
|
|
|
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
|
+
|
|
335
322
|
# view command
|
|
336
323
|
@command('view')
|
|
337
324
|
def view(self: WatcherCLI, parsed: ParsedArgs):
|
|
338
|
-
# no setup needed for view
|
|
339
325
|
pass
|
|
340
326
|
|
|
341
327
|
|
|
342
|
-
@
|
|
343
|
-
def view_cli(self: WatcherCLI,
|
|
328
|
+
@view.child('cli')
|
|
329
|
+
def view_cli(self: WatcherCLI, _arg: str, **kwargs):
|
|
344
330
|
self.watcher.router.disableOriginOutput()
|
|
345
331
|
self.outputMode = 'cli'
|
|
346
332
|
self.buffer.enabled = True
|
|
@@ -350,8 +336,8 @@ def view_cli(self: WatcherCLI, _stat: str):
|
|
|
350
336
|
self.safePrint(msg)
|
|
351
337
|
|
|
352
338
|
|
|
353
|
-
@
|
|
354
|
-
def view_watcher(self: WatcherCLI,
|
|
339
|
+
@view.child('watcher')
|
|
340
|
+
def view_watcher(self: WatcherCLI, _arg: str, **kwargs):
|
|
355
341
|
self.watcher.router.enableOriginOutput()
|
|
356
342
|
self.outputMode = 'both'
|
|
357
343
|
utils.clearTerminal()
|
|
@@ -363,15 +349,12 @@ def view_watcher(self: WatcherCLI, _stat: str):
|
|
|
363
349
|
# clear command
|
|
364
350
|
@command('clear')
|
|
365
351
|
def clear(self: WatcherCLI, parsed: ParsedArgs):
|
|
366
|
-
# no setup needed
|
|
367
352
|
pass
|
|
368
353
|
|
|
369
354
|
|
|
370
|
-
@
|
|
371
|
-
def clear_buffer(self: WatcherCLI,
|
|
372
|
-
|
|
373
|
-
def _buffer(value: str):
|
|
374
|
-
return value.lower() == 'true'
|
|
355
|
+
@clear.child('buffer')
|
|
356
|
+
def clear_buffer(self: WatcherCLI, _arg: str, **kwargs):
|
|
357
|
+
buffer = kwargs['buffer']
|
|
375
358
|
|
|
376
359
|
if buffer():
|
|
377
360
|
self.buffer.clear()
|
|
@@ -380,31 +363,38 @@ def clear_buffer(self: WatcherCLI, _stat: str, buffer):
|
|
|
380
363
|
self.printHeader()
|
|
381
364
|
|
|
382
365
|
|
|
366
|
+
@clear_buffer.param('buffer', type=str, default='true')
|
|
367
|
+
def buffer(value: str):
|
|
368
|
+
return value.lower() == 'true'
|
|
369
|
+
|
|
370
|
+
|
|
383
371
|
# watcher command
|
|
384
372
|
@command('watcher')
|
|
385
373
|
def watcher(self: WatcherCLI, parsed: ParsedArgs):
|
|
386
|
-
# no setup needed
|
|
387
374
|
pass
|
|
388
375
|
|
|
389
376
|
|
|
390
|
-
@
|
|
391
|
-
def watcher_restart(self: WatcherCLI,
|
|
377
|
+
@watcher.child('restart')
|
|
378
|
+
def watcher_restart(self: WatcherCLI, _arg: str, **kwargs):
|
|
392
379
|
self.watcher.restart_and_wait()
|
|
393
380
|
|
|
394
381
|
|
|
395
|
-
@
|
|
396
|
-
def watcher_schedule(self: WatcherCLI,
|
|
397
|
-
|
|
398
|
-
def _minutes(value: int):
|
|
399
|
-
return value
|
|
382
|
+
@watcher.child('schedule')
|
|
383
|
+
def watcher_schedule(self: WatcherCLI, _arg: str, **kwargs):
|
|
384
|
+
minutes = kwargs['minutes']
|
|
400
385
|
|
|
401
386
|
val = minutes()
|
|
402
387
|
if val is None:
|
|
403
|
-
return self.safePrint('Usage: watcher schedule
|
|
388
|
+
return self.safePrint('Usage: watcher schedule minutes')
|
|
404
389
|
self.watcher.schedule_restart(val)
|
|
405
390
|
|
|
406
391
|
|
|
407
|
-
@
|
|
408
|
-
def watcher_shutdown(self: WatcherCLI,
|
|
392
|
+
@watcher.child('shutdown')
|
|
393
|
+
def watcher_shutdown(self: WatcherCLI, _arg: str, **kwargs):
|
|
409
394
|
self.watcher.shutdown()
|
|
410
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
|