serverwatcher 6.dev25__py3-none-any.whl → 6.dev26__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 +43 -31
- serverwatcher/watchercli.py +57 -51
- {serverwatcher-6.dev25.dist-info → serverwatcher-6.dev26.dist-info}/METADATA +1 -1
- {serverwatcher-6.dev25.dist-info → serverwatcher-6.dev26.dist-info}/RECORD +7 -7
- {serverwatcher-6.dev25.dist-info → serverwatcher-6.dev26.dist-info}/WHEEL +0 -0
- {serverwatcher-6.dev25.dist-info → serverwatcher-6.dev26.dist-info}/licenses/LICENSE +0 -0
- {serverwatcher-6.dev25.dist-info → serverwatcher-6.dev26.dist-info}/top_level.txt +0 -0
serverwatcher/livecli.py
CHANGED
|
@@ -49,7 +49,7 @@ class ChildSpec:
|
|
|
49
49
|
self.children: dict[str, ChildSpec] = {}
|
|
50
50
|
|
|
51
51
|
self.description = getattr(func, '__description__', None)
|
|
52
|
-
|
|
52
|
+
|
|
53
53
|
def param(self, name, type=str, default=None):
|
|
54
54
|
def deco(func):
|
|
55
55
|
pyname = name.replace('-', '_')
|
|
@@ -65,7 +65,6 @@ class ChildSpec:
|
|
|
65
65
|
return deco
|
|
66
66
|
|
|
67
67
|
|
|
68
|
-
|
|
69
68
|
class CommandSpec:
|
|
70
69
|
def __init__(
|
|
71
70
|
self,
|
|
@@ -199,17 +198,27 @@ def parse_docstring_args(doc: str | None) -> dict[str, list[tuple[str, bool]]]:
|
|
|
199
198
|
return result
|
|
200
199
|
|
|
201
200
|
|
|
201
|
+
def get_doc_description(func) -> str | None:
|
|
202
|
+
doc = func.__doc__
|
|
203
|
+
if not doc:
|
|
204
|
+
return None
|
|
205
|
+
first = doc.strip().splitlines()[0].strip()
|
|
206
|
+
return first or None
|
|
207
|
+
|
|
208
|
+
|
|
202
209
|
def generate_help(obj):
|
|
203
210
|
if isinstance(obj, CommandSpec):
|
|
211
|
+
desc = get_doc_description(obj.func) or obj.description or 'No description'
|
|
204
212
|
lines = []
|
|
205
|
-
lines.append(f'{obj.name}: {
|
|
213
|
+
lines.append(f'{obj.name}: {desc}')
|
|
206
214
|
lines.append(f'Usage: {obj.name} [child] [arg] [--flags] [params]')
|
|
207
215
|
|
|
208
216
|
if obj.children:
|
|
209
217
|
lines.append('')
|
|
210
218
|
lines.append(' Children:')
|
|
211
219
|
for cname, child in obj.children.items():
|
|
212
|
-
|
|
220
|
+
cdesc = get_doc_description(child.func) or child.description or 'No description'
|
|
221
|
+
lines.append(f' {cname}: {cdesc}')
|
|
213
222
|
|
|
214
223
|
if obj.flags:
|
|
215
224
|
lines.append('')
|
|
@@ -226,8 +235,9 @@ def generate_help(obj):
|
|
|
226
235
|
return '\n'.join(lines)
|
|
227
236
|
|
|
228
237
|
if isinstance(obj, ChildSpec):
|
|
238
|
+
desc = get_doc_description(obj.func) or obj.description or 'No description'
|
|
229
239
|
lines = []
|
|
230
|
-
lines.append(f'{obj.name}: {
|
|
240
|
+
lines.append(f'{obj.name}: {desc}')
|
|
231
241
|
lines.append(f'Usage: {obj.name} [arg] [--flags] [params]')
|
|
232
242
|
|
|
233
243
|
args_meta = parse_docstring_args(obj.func.__doc__)
|
|
@@ -272,30 +282,7 @@ def dispatch(cli, line: str):
|
|
|
272
282
|
if 'help' in parsed.flags and not parsed.positional:
|
|
273
283
|
return cli.safePrint(generate_help(cmd_spec))
|
|
274
284
|
|
|
275
|
-
cmd_spec.func
|
|
276
|
-
|
|
277
|
-
if not cmd_spec.children:
|
|
278
|
-
if 'help' in parsed.flags:
|
|
279
|
-
return cli.safePrint(generate_help(cmd_spec))
|
|
280
|
-
return
|
|
281
|
-
|
|
282
|
-
if not parsed.positional:
|
|
283
|
-
return cli.safePrint('Missing subcommand')
|
|
284
|
-
|
|
285
|
-
child_name = parsed.positional[0]
|
|
286
|
-
child = cmd_spec.children.get(child_name)
|
|
287
|
-
if child is None:
|
|
288
|
-
return cli.safePrint(f'Unknown subcommand {child_name}')
|
|
289
|
-
|
|
290
|
-
if 'help' in parsed.flags:
|
|
291
|
-
return cli.safePrint(generate_help(child))
|
|
292
|
-
|
|
293
|
-
arg = parsed.positional[1] if len(parsed.positional) > 1 else None
|
|
294
|
-
|
|
295
|
-
if child.requires_arguments and arg is None:
|
|
296
|
-
return cli.safePrint(f'Subcommand {child.name} requires an argument')
|
|
297
|
-
|
|
298
|
-
g = child.func.__globals__
|
|
285
|
+
g_cmd = cmd_spec.func.__globals__
|
|
299
286
|
|
|
300
287
|
for pname, pspec in cmd_spec.params.items():
|
|
301
288
|
if pname in parsed.params:
|
|
@@ -312,7 +299,7 @@ def dispatch(cli, line: str):
|
|
|
312
299
|
return func(value)
|
|
313
300
|
return wrapper
|
|
314
301
|
|
|
315
|
-
|
|
302
|
+
g_cmd[pname] = make_param_func()
|
|
316
303
|
|
|
317
304
|
for fname, fspec in cmd_spec.flags.items():
|
|
318
305
|
present = fname in parsed.flags
|
|
@@ -322,7 +309,32 @@ def dispatch(cli, line: str):
|
|
|
322
309
|
return present
|
|
323
310
|
return wrapper
|
|
324
311
|
|
|
325
|
-
|
|
312
|
+
g_cmd[fname] = make_flag_func()
|
|
313
|
+
|
|
314
|
+
cmd_spec.func(cli)
|
|
315
|
+
|
|
316
|
+
if not cmd_spec.children:
|
|
317
|
+
if 'help' in parsed.flags:
|
|
318
|
+
return cli.safePrint(generate_help(cmd_spec))
|
|
319
|
+
return
|
|
320
|
+
|
|
321
|
+
if not parsed.positional:
|
|
322
|
+
return cli.safePrint('Missing subcommand')
|
|
323
|
+
|
|
324
|
+
child_name = parsed.positional[0]
|
|
325
|
+
child = cmd_spec.children.get(child_name)
|
|
326
|
+
if child is None:
|
|
327
|
+
return cli.safePrint(f'Unknown subcommand {child_name}')
|
|
328
|
+
|
|
329
|
+
if 'help' in parsed.flags:
|
|
330
|
+
return cli.safePrint(generate_help(child))
|
|
331
|
+
|
|
332
|
+
arg = parsed.positional[1] if len(parsed.positional) > 1 else None
|
|
333
|
+
|
|
334
|
+
if child.requires_arguments and arg is None:
|
|
335
|
+
return cli.safePrint(f'Subcommand {child.name} requires an argument')
|
|
336
|
+
|
|
337
|
+
g = child.func.__globals__
|
|
326
338
|
|
|
327
339
|
for pname, pspec in child.params.items():
|
|
328
340
|
if pname in parsed.params:
|
serverwatcher/watchercli.py
CHANGED
|
@@ -36,12 +36,16 @@ class WatcherCLI(LiveCLI):
|
|
|
36
36
|
|
|
37
37
|
@command('stats', requires_children=True)
|
|
38
38
|
def stats(self):
|
|
39
|
-
|
|
39
|
+
'''
|
|
40
|
+
Retrieve and print server statistics
|
|
41
|
+
'''
|
|
40
42
|
|
|
41
43
|
|
|
42
44
|
@stats.child('get', requires_arguments=False)
|
|
43
45
|
def stats_get(self, arg=None):
|
|
44
46
|
'''
|
|
47
|
+
Retrieve and print all or specific server statistics
|
|
48
|
+
|
|
45
49
|
args:
|
|
46
50
|
ram [rounding] [--raw]
|
|
47
51
|
cpu [rounding]
|
|
@@ -51,46 +55,45 @@ def stats_get(self, arg=None):
|
|
|
51
55
|
version
|
|
52
56
|
platform
|
|
53
57
|
'''
|
|
54
|
-
__description__ = 'Retrieve and print all or specific server statistics'
|
|
55
58
|
self.watcher.server.refresh()
|
|
56
59
|
|
|
57
|
-
if arg is
|
|
58
|
-
gb = raw()
|
|
59
|
-
fmt = not raw()
|
|
60
|
-
|
|
61
|
-
unit = ''
|
|
62
|
-
match arg:
|
|
63
|
-
case 'ram':
|
|
64
|
-
value = self.watcher.server.getRAM(rounding=rounding(), gb=gb)
|
|
65
|
-
name = 'RAM'
|
|
66
|
-
unit = ' GB' if gb else ' MB'
|
|
67
|
-
case 'cpu':
|
|
68
|
-
value = self.watcher.server.getCPU(rounding=rounding())
|
|
69
|
-
name = 'CPU'
|
|
70
|
-
unit = '%'
|
|
71
|
-
case 'uptime':
|
|
72
|
-
value = self.watcher.server.getUptime(formatted=fmt)
|
|
73
|
-
name = 'Uptime'
|
|
74
|
-
unit = '' if fmt else 'ms'
|
|
75
|
-
case 'tps':
|
|
76
|
-
value = self.watcher.server.getTPS(rounding=rounding(), mode=mode())
|
|
77
|
-
name = 'TPS'
|
|
78
|
-
case 'players':
|
|
79
|
-
value = self.watcher.server.getPlayers()
|
|
80
|
-
name = 'Players'
|
|
81
|
-
case 'version':
|
|
82
|
-
value = self.watcher.server.version
|
|
83
|
-
name = 'Minecraft version'
|
|
84
|
-
case 'platform':
|
|
85
|
-
value = self.watcher.server.platform
|
|
86
|
-
name = 'Server platform'
|
|
87
|
-
case _:
|
|
88
|
-
return self.safePrint('Unknown stat')
|
|
89
|
-
|
|
90
|
-
self.bprint(f'{name}: {value}{unit}')
|
|
91
|
-
else:
|
|
60
|
+
if arg is None:
|
|
92
61
|
return
|
|
93
62
|
|
|
63
|
+
gb = not raw()
|
|
64
|
+
fmt = not raw()
|
|
65
|
+
|
|
66
|
+
unit = ''
|
|
67
|
+
match arg:
|
|
68
|
+
case 'ram':
|
|
69
|
+
value = self.watcher.server.getRAM(rounding=rounding(), gb=gb)
|
|
70
|
+
name = 'RAM'
|
|
71
|
+
unit = ' GB' if gb else ' MB'
|
|
72
|
+
case 'cpu':
|
|
73
|
+
value = self.watcher.server.getCPU(rounding=rounding())
|
|
74
|
+
name = 'CPU'
|
|
75
|
+
unit = '%'
|
|
76
|
+
case 'uptime':
|
|
77
|
+
value = self.watcher.server.getUptime(formatted=fmt)
|
|
78
|
+
name = 'Uptime'
|
|
79
|
+
unit = '' if fmt else 'ms'
|
|
80
|
+
case 'tps':
|
|
81
|
+
value = self.watcher.server.getTPS(rounding=rounding(), mode=mode())
|
|
82
|
+
name = 'TPS'
|
|
83
|
+
case 'players':
|
|
84
|
+
value = self.watcher.server.getPlayers()
|
|
85
|
+
name = 'Players'
|
|
86
|
+
case 'version':
|
|
87
|
+
value = self.watcher.server.version
|
|
88
|
+
name = 'Minecraft version'
|
|
89
|
+
case 'platform':
|
|
90
|
+
value = self.watcher.server.platform
|
|
91
|
+
name = 'Server platform'
|
|
92
|
+
case _:
|
|
93
|
+
return self.safePrint('Unknown stat')
|
|
94
|
+
|
|
95
|
+
self.bprint(f'{name}: {value}{unit}')
|
|
96
|
+
|
|
94
97
|
|
|
95
98
|
@stats.get.param('rounding', type=int, default=2)
|
|
96
99
|
def rounding(value):
|
|
@@ -109,13 +112,16 @@ def raw():
|
|
|
109
112
|
|
|
110
113
|
@command('view', requires_children=True)
|
|
111
114
|
def view(self):
|
|
112
|
-
|
|
115
|
+
'''
|
|
116
|
+
Switch terminal view
|
|
117
|
+
'''
|
|
113
118
|
|
|
114
119
|
|
|
115
120
|
@view.child('cli')
|
|
116
121
|
def view_cli(self):
|
|
117
|
-
|
|
118
|
-
|
|
122
|
+
'''
|
|
123
|
+
Switch to CLI view
|
|
124
|
+
'''
|
|
119
125
|
self.watcher.router.disableOriginOutput()
|
|
120
126
|
self.outputMode = 'cli'
|
|
121
127
|
self.buffer.enabled = True
|
|
@@ -131,8 +137,9 @@ def view_cli(self):
|
|
|
131
137
|
|
|
132
138
|
@view.child('watcher')
|
|
133
139
|
def view_watcher(self):
|
|
134
|
-
|
|
135
|
-
|
|
140
|
+
'''
|
|
141
|
+
Switch to Watcher view
|
|
142
|
+
'''
|
|
136
143
|
self.watcher.router.enableOriginOutput()
|
|
137
144
|
self.outputMode = 'both'
|
|
138
145
|
|
|
@@ -145,18 +152,17 @@ def view_watcher(self):
|
|
|
145
152
|
|
|
146
153
|
@command('clear')
|
|
147
154
|
def clear(self):
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
if clear_buffer:
|
|
155
|
+
'''
|
|
156
|
+
Clear the CLI terminal
|
|
157
|
+
'''
|
|
158
|
+
no_buf = no_buffer()
|
|
159
|
+
if not no_buf:
|
|
154
160
|
self.buffer.clear()
|
|
155
161
|
|
|
156
162
|
utils.clearTerminal()
|
|
157
163
|
self.printHeader()
|
|
158
164
|
|
|
159
165
|
|
|
160
|
-
@clear.
|
|
161
|
-
def
|
|
162
|
-
return
|
|
166
|
+
@clear.flag('no-buffer')
|
|
167
|
+
def no_buffer():
|
|
168
|
+
return True
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
serverwatcher/__init__.py,sha256=Q_afN0XU29n48d6Gf0-LT2lLo3RiTWlHRT6rC_fYbjw,486
|
|
2
2
|
serverwatcher/__main__.py,sha256=5geaZQKgLSP1pxnpQPgFy9zAwyyPyTInlbcFxb9OiEw,3016
|
|
3
|
-
serverwatcher/livecli.py,sha256=
|
|
3
|
+
serverwatcher/livecli.py,sha256=jhu5BxFwr8LmZKRfCM_5TPvE1u9mCAIh21G6hwdNLGA,11218
|
|
4
4
|
serverwatcher/validator.py,sha256=aD6GHOz1S5VFC93Mj89WO9vZG1bTjhg7QZbdlvQf4wo,1778
|
|
5
5
|
serverwatcher/watcher.py,sha256=ZiocJpeyhKTGOwYYak36MXNEFpLnpdl9v6BnMPGrBmM,13593
|
|
6
|
-
serverwatcher/watchercli.py,sha256=
|
|
6
|
+
serverwatcher/watchercli.py,sha256=SL-rYsGfd-X0UB4iDURqG5pJ4D8f-sGc50xceLXAX8k,3884
|
|
7
7
|
serverwatcher/configclasses/__init__.py,sha256=YS0KhxtAJGdMcaiFstqTRNxIPLnR7s9v3Tkt5h2uKE4,182
|
|
8
8
|
serverwatcher/configclasses/config.py,sha256=1Upor55QFE4UIOqL9ZYa4U5kbda48GG9HWdRXg8mb_Y,2418
|
|
9
9
|
serverwatcher/configclasses/messages.py,sha256=iOkCvwagngW4aeWD5I6hi6cqqDkzEsFJsLHSuqK-P1s,3467
|
|
@@ -13,8 +13,8 @@ serverwatcher/defaultconfigs/messages.yaml,sha256=jSVEl-RYqPHhe5U5KLl8zfJtUBymvy
|
|
|
13
13
|
serverwatcher/defaultconfigs/watcher.yaml,sha256=GlAEKCuzFUSF6wWOqQLFL1CeuPltb1ltfYxFe_FUClw,723
|
|
14
14
|
serverwatcher/tests/test.py,sha256=-ZYvAQ1vtAUydiEBK27MgBGW0fHzAuc3Iu63O-Fz4Y0,1636
|
|
15
15
|
serverwatcher/tests/test2.py,sha256=DcvYiidXTe3SSOpiSPQ585YBN4PXrDMs0a3ZW_TbBsg,9564
|
|
16
|
-
serverwatcher-6.
|
|
17
|
-
serverwatcher-6.
|
|
18
|
-
serverwatcher-6.
|
|
19
|
-
serverwatcher-6.
|
|
20
|
-
serverwatcher-6.
|
|
16
|
+
serverwatcher-6.dev26.dist-info/licenses/LICENSE,sha256=OXLcl0T2SZ8Pmy2_dmlvKuetivmyPd5m1q-Gyd-zaYY,35149
|
|
17
|
+
serverwatcher-6.dev26.dist-info/METADATA,sha256=7jetq4oSNtW8vm3eqfXiZpZyZ_N__yCLSKiLSdaHbj0,2647
|
|
18
|
+
serverwatcher-6.dev26.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
19
|
+
serverwatcher-6.dev26.dist-info/top_level.txt,sha256=8DJAf8WmmglgtZHkp8aoTriRJ2YPcS4F3DfOIkytASo,14
|
|
20
|
+
serverwatcher-6.dev26.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|