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