serverwatcher 6.dev14__tar.gz → 6.dev16__tar.gz
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-6.dev14/src/serverwatcher.egg-info → serverwatcher-6.dev16}/PKG-INFO +1 -1
- {serverwatcher-6.dev14 → serverwatcher-6.dev16}/pyproject.toml +1 -1
- {serverwatcher-6.dev14 → serverwatcher-6.dev16}/src/serverwatcher/__main__.py +5 -5
- {serverwatcher-6.dev14 → serverwatcher-6.dev16}/src/serverwatcher/livecli.py +108 -77
- serverwatcher-6.dev16/src/serverwatcher/watchercli.py +153 -0
- {serverwatcher-6.dev14 → serverwatcher-6.dev16/src/serverwatcher.egg-info}/PKG-INFO +1 -1
- serverwatcher-6.dev14/src/serverwatcher/watchercli.py +0 -198
- {serverwatcher-6.dev14 → serverwatcher-6.dev16}/LICENSE +0 -0
- {serverwatcher-6.dev14 → serverwatcher-6.dev16}/README.md +0 -0
- {serverwatcher-6.dev14 → serverwatcher-6.dev16}/setup.cfg +0 -0
- {serverwatcher-6.dev14 → serverwatcher-6.dev16}/src/serverwatcher/__init__.py +0 -0
- {serverwatcher-6.dev14 → serverwatcher-6.dev16}/src/serverwatcher/cli.py +0 -0
- {serverwatcher-6.dev14 → serverwatcher-6.dev16}/src/serverwatcher/configclasses/__init__.py +0 -0
- {serverwatcher-6.dev14 → serverwatcher-6.dev16}/src/serverwatcher/configclasses/config.py +0 -0
- {serverwatcher-6.dev14 → serverwatcher-6.dev16}/src/serverwatcher/configclasses/messages.py +0 -0
- {serverwatcher-6.dev14 → serverwatcher-6.dev16}/src/serverwatcher/configclasses/watcher.py +0 -0
- {serverwatcher-6.dev14 → serverwatcher-6.dev16}/src/serverwatcher/defaultconfigs/config.yaml +0 -0
- {serverwatcher-6.dev14 → serverwatcher-6.dev16}/src/serverwatcher/defaultconfigs/messages.yaml +0 -0
- {serverwatcher-6.dev14 → serverwatcher-6.dev16}/src/serverwatcher/defaultconfigs/watcher.yaml +0 -0
- {serverwatcher-6.dev14 → serverwatcher-6.dev16}/src/serverwatcher/tests/test.py +0 -0
- {serverwatcher-6.dev14 → serverwatcher-6.dev16}/src/serverwatcher/tests/test2.py +0 -0
- {serverwatcher-6.dev14 → serverwatcher-6.dev16}/src/serverwatcher/validator.py +0 -0
- {serverwatcher-6.dev14 → serverwatcher-6.dev16}/src/serverwatcher/watcher.py +0 -0
- {serverwatcher-6.dev14 → serverwatcher-6.dev16}/src/serverwatcher.egg-info/SOURCES.txt +0 -0
- {serverwatcher-6.dev14 → serverwatcher-6.dev16}/src/serverwatcher.egg-info/dependency_links.txt +0 -0
- {serverwatcher-6.dev14 → serverwatcher-6.dev16}/src/serverwatcher.egg-info/requires.txt +0 -0
- {serverwatcher-6.dev14 → serverwatcher-6.dev16}/src/serverwatcher.egg-info/top_level.txt +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
from mapres import rprint, setGlobalMaps, ascii_colors
|
|
2
1
|
import time
|
|
3
2
|
import asyncio
|
|
4
3
|
import threading
|
|
5
|
-
|
|
4
|
+
|
|
5
|
+
from mapres import rprint, setGlobalMaps, ascii_colors
|
|
6
6
|
|
|
7
7
|
from hungerlib.validator import (
|
|
8
8
|
ValidationError,
|
|
@@ -14,12 +14,12 @@ from hungerlib.validator import (
|
|
|
14
14
|
|
|
15
15
|
from .watcher import ServerWatcher
|
|
16
16
|
from .validator import validate_all
|
|
17
|
+
from .watchercli import WatcherCLI
|
|
17
18
|
|
|
18
19
|
|
|
19
|
-
# mapres setup
|
|
20
20
|
setGlobalMaps(ascii_colors)
|
|
21
21
|
|
|
22
|
-
|
|
22
|
+
|
|
23
23
|
def pretty_report(report: str) -> str:
|
|
24
24
|
lines = report.splitlines()
|
|
25
25
|
out = []
|
|
@@ -43,7 +43,7 @@ def pretty_report(report: str) -> str:
|
|
|
43
43
|
out.append(line)
|
|
44
44
|
return '\n'.join(out)
|
|
45
45
|
|
|
46
|
-
|
|
46
|
+
|
|
47
47
|
def main():
|
|
48
48
|
try:
|
|
49
49
|
validate_all()
|
|
@@ -1,9 +1,15 @@
|
|
|
1
|
-
# livecli.py
|
|
2
|
-
|
|
3
1
|
from dataclasses import dataclass
|
|
2
|
+
import cmd
|
|
3
|
+
import sys
|
|
4
|
+
import termios
|
|
5
|
+
import tty
|
|
6
|
+
import asyncio
|
|
7
|
+
|
|
8
|
+
# ---------------------------------------------------------------------------
|
|
9
|
+
# DSL core
|
|
10
|
+
# ---------------------------------------------------------------------------
|
|
4
11
|
|
|
5
|
-
|
|
6
|
-
COMMANDS: dict[str, "CommandSpec"] = {}
|
|
12
|
+
COMMANDS: dict[str, 'CommandSpec'] = {}
|
|
7
13
|
|
|
8
14
|
|
|
9
15
|
@dataclass
|
|
@@ -11,11 +17,13 @@ class ParamSpec:
|
|
|
11
17
|
name: str
|
|
12
18
|
type_: type
|
|
13
19
|
default: object
|
|
20
|
+
func: callable
|
|
14
21
|
|
|
15
22
|
|
|
16
23
|
@dataclass
|
|
17
24
|
class FlagSpec:
|
|
18
25
|
name: str
|
|
26
|
+
func: callable
|
|
19
27
|
|
|
20
28
|
|
|
21
29
|
class ChildSpec:
|
|
@@ -23,15 +31,15 @@ class ChildSpec:
|
|
|
23
31
|
self,
|
|
24
32
|
name,
|
|
25
33
|
func,
|
|
26
|
-
requires_children=False,
|
|
27
|
-
requires_arguments=False,
|
|
28
|
-
requires_params=False,
|
|
29
|
-
requires_flags=False,
|
|
30
|
-
has_arguments=False,
|
|
34
|
+
requires_children: bool = False,
|
|
35
|
+
requires_arguments: bool = False,
|
|
36
|
+
requires_params: bool = False,
|
|
37
|
+
requires_flags: bool = False,
|
|
38
|
+
has_arguments: bool = False,
|
|
31
39
|
):
|
|
32
40
|
if has_arguments and requires_children:
|
|
33
41
|
raise ValueError(
|
|
34
|
-
f
|
|
42
|
+
f'Child \'{name}\' cannot both have arguments and require children'
|
|
35
43
|
)
|
|
36
44
|
|
|
37
45
|
self.name = name
|
|
@@ -42,23 +50,23 @@ class ChildSpec:
|
|
|
42
50
|
self.requires_flags = requires_flags
|
|
43
51
|
self.has_arguments = has_arguments
|
|
44
52
|
|
|
45
|
-
self.params = {}
|
|
46
|
-
self.flags = {}
|
|
47
|
-
self.children = {}
|
|
53
|
+
self.params: dict[str, ParamSpec] = {}
|
|
54
|
+
self.flags: dict[str, FlagSpec] = {}
|
|
55
|
+
self.children: dict[str, 'ChildSpec'] = {}
|
|
48
56
|
|
|
49
|
-
self.description = getattr(func,
|
|
57
|
+
self.description = getattr(func, '__description__', None)
|
|
50
58
|
|
|
51
59
|
def param(self, name, type=str, default=None):
|
|
52
60
|
def deco(func):
|
|
53
|
-
pyname = name.replace(
|
|
54
|
-
self.params[pyname] = ParamSpec(name, type, default)
|
|
61
|
+
pyname = name.replace('-', '_')
|
|
62
|
+
self.params[pyname] = ParamSpec(name, type, default, func)
|
|
55
63
|
return func
|
|
56
64
|
return deco
|
|
57
65
|
|
|
58
66
|
def flag(self, name):
|
|
59
67
|
def deco(func):
|
|
60
|
-
pyname = name.replace(
|
|
61
|
-
self.flags[pyname] = FlagSpec(name)
|
|
68
|
+
pyname = name.replace('-', '_')
|
|
69
|
+
self.flags[pyname] = FlagSpec(name, func)
|
|
62
70
|
return func
|
|
63
71
|
return deco
|
|
64
72
|
|
|
@@ -95,9 +103,26 @@ class CommandSpec:
|
|
|
95
103
|
self.requires_flags = requires_flags
|
|
96
104
|
self.has_arguments = has_arguments
|
|
97
105
|
|
|
98
|
-
self.children = {}
|
|
106
|
+
self.children: dict[str, ChildSpec] = {}
|
|
107
|
+
self.params: dict[str, ParamSpec] = {}
|
|
108
|
+
self.flags: dict[str, FlagSpec] = {}
|
|
109
|
+
|
|
99
110
|
self.description = getattr(func, "__description__", None)
|
|
100
111
|
|
|
112
|
+
def param(self, name, type=str, default=None):
|
|
113
|
+
def deco(func):
|
|
114
|
+
pyname = name.replace("-", "_")
|
|
115
|
+
self.params[pyname] = ParamSpec(name, type, default, func)
|
|
116
|
+
return func
|
|
117
|
+
return deco
|
|
118
|
+
|
|
119
|
+
def flag(self, name):
|
|
120
|
+
def deco(func):
|
|
121
|
+
pyname = name.replace("-", "_")
|
|
122
|
+
self.flags[pyname] = FlagSpec(name, func)
|
|
123
|
+
return func
|
|
124
|
+
return deco
|
|
125
|
+
|
|
101
126
|
def child(self, name, **meta):
|
|
102
127
|
def deco(func):
|
|
103
128
|
child = ChildSpec(name, func, **meta)
|
|
@@ -107,6 +132,7 @@ class CommandSpec:
|
|
|
107
132
|
return deco
|
|
108
133
|
|
|
109
134
|
|
|
135
|
+
|
|
110
136
|
class CommandDSL:
|
|
111
137
|
def __call__(self, name, **meta):
|
|
112
138
|
def deco(func):
|
|
@@ -119,39 +145,38 @@ class CommandDSL:
|
|
|
119
145
|
command = CommandDSL()
|
|
120
146
|
|
|
121
147
|
|
|
122
|
-
#
|
|
123
|
-
#
|
|
124
|
-
#
|
|
148
|
+
# ---------------------------------------------------------------------------
|
|
149
|
+
# Help generation
|
|
150
|
+
# ---------------------------------------------------------------------------
|
|
125
151
|
|
|
126
152
|
def generate_help(cmd: CommandSpec) -> str:
|
|
127
|
-
lines = []
|
|
128
|
-
|
|
129
|
-
lines.append(f"{cmd.name}: {cmd.description or 'No description'}")
|
|
153
|
+
lines: list[str] = []
|
|
154
|
+
lines.append(f'{cmd.name}: {cmd.description or 'No description'}')
|
|
130
155
|
|
|
131
156
|
if cmd.children:
|
|
132
|
-
lines.append(
|
|
133
|
-
lines.append(
|
|
157
|
+
lines.append('')
|
|
158
|
+
lines.append('Children:')
|
|
134
159
|
for cname, child in cmd.children.items():
|
|
135
|
-
lines.append(f
|
|
160
|
+
lines.append(f' {cname}: {child.description or 'No description'}')
|
|
136
161
|
|
|
137
162
|
if child.params:
|
|
138
|
-
lines.append(
|
|
163
|
+
lines.append(' Params:')
|
|
139
164
|
for pname, pspec in child.params.items():
|
|
140
165
|
lines.append(
|
|
141
|
-
f
|
|
166
|
+
f' {pname} (CLI: {pspec.name}, type={pspec.type_.__name__}, default={pspec.default})'
|
|
142
167
|
)
|
|
143
168
|
|
|
144
169
|
if child.flags:
|
|
145
|
-
lines.append(
|
|
170
|
+
lines.append(' Flags:')
|
|
146
171
|
for fname, fspec in child.flags.items():
|
|
147
|
-
lines.append(f
|
|
172
|
+
lines.append(f' --{fspec.name}')
|
|
148
173
|
|
|
149
|
-
return
|
|
174
|
+
return '\n'.join(lines)
|
|
150
175
|
|
|
151
176
|
|
|
152
|
-
#
|
|
153
|
-
#
|
|
154
|
-
#
|
|
177
|
+
# ---------------------------------------------------------------------------
|
|
178
|
+
# Parsing + dispatch
|
|
179
|
+
# ---------------------------------------------------------------------------
|
|
155
180
|
|
|
156
181
|
@dataclass
|
|
157
182
|
class ParsedArgs:
|
|
@@ -168,15 +193,15 @@ def parse_line(raw: str) -> ParsedArgs:
|
|
|
168
193
|
|
|
169
194
|
parts = raw.split()
|
|
170
195
|
sub = parts[0]
|
|
171
|
-
positional = []
|
|
172
|
-
flags = {}
|
|
173
|
-
params = {}
|
|
196
|
+
positional: list[str] = []
|
|
197
|
+
flags: dict[str, bool] = {}
|
|
198
|
+
params: dict[str, str] = {}
|
|
174
199
|
|
|
175
200
|
for token in parts[1:]:
|
|
176
|
-
if token.startswith(
|
|
201
|
+
if token.startswith('--'):
|
|
177
202
|
flags[token[2:]] = True
|
|
178
|
-
elif
|
|
179
|
-
key, value = token.split(
|
|
203
|
+
elif ':' in token:
|
|
204
|
+
key, value = token.split(':', 1)
|
|
180
205
|
params[key.lower()] = value
|
|
181
206
|
else:
|
|
182
207
|
positional.append(token)
|
|
@@ -191,82 +216,88 @@ def dispatch(cli, line: str):
|
|
|
191
216
|
|
|
192
217
|
cmd = COMMANDS.get(parsed.subcommand)
|
|
193
218
|
if cmd is None:
|
|
194
|
-
return cli.safePrint(f
|
|
219
|
+
return cli.safePrint(f'Unknown command \'{parsed.subcommand}\'')
|
|
195
220
|
|
|
196
221
|
if cmd.requires_children and not cmd.children:
|
|
197
|
-
return cli.safePrint(f
|
|
222
|
+
return cli.safePrint(f'Command \'{cmd.name}\' requires children')
|
|
198
223
|
|
|
199
224
|
cmd.func()
|
|
200
225
|
|
|
201
226
|
if not parsed.positional:
|
|
202
227
|
if cmd.requires_arguments:
|
|
203
|
-
return cli.safePrint(f
|
|
204
|
-
return cli.safePrint(
|
|
228
|
+
return cli.safePrint(f'Command \'{cmd.name}\' requires an argument')
|
|
229
|
+
return cli.safePrint('Missing subcommand')
|
|
205
230
|
|
|
206
231
|
child_name = parsed.positional[0]
|
|
207
232
|
child = cmd.children.get(child_name)
|
|
208
233
|
if child is None:
|
|
209
|
-
return cli.safePrint(f
|
|
234
|
+
return cli.safePrint(f'Unknown subcommand \'{child_name}\'')
|
|
210
235
|
|
|
211
236
|
arg = parsed.positional[1] if len(parsed.positional) > 1 else None
|
|
212
237
|
|
|
213
238
|
if child.requires_arguments and arg is None:
|
|
214
|
-
return cli.safePrint(f
|
|
239
|
+
return cli.safePrint(f'Subcommand \'{child.name}\' requires an argument')
|
|
215
240
|
|
|
216
|
-
|
|
241
|
+
# Inject param/flag functions into child.func globals
|
|
242
|
+
g = child.func.__globals__
|
|
217
243
|
|
|
244
|
+
# Params: use provided value or default, then call original func(value)
|
|
218
245
|
for pname, pspec in child.params.items():
|
|
219
246
|
if pname in parsed.params:
|
|
220
|
-
|
|
247
|
+
raw_value = parsed.params[pname]
|
|
248
|
+
try:
|
|
249
|
+
converted = pspec.type_(raw_value)
|
|
250
|
+
except Exception:
|
|
251
|
+
converted = pspec.default
|
|
252
|
+
else:
|
|
253
|
+
converted = pspec.default
|
|
221
254
|
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
return pspec.default
|
|
255
|
+
def make_param_func(func=pspec.func, value=converted):
|
|
256
|
+
def wrapper():
|
|
257
|
+
return func(value)
|
|
258
|
+
return wrapper
|
|
227
259
|
|
|
228
|
-
|
|
229
|
-
else:
|
|
230
|
-
wrappers[pname] = lambda pspec=pspec: pspec.default
|
|
260
|
+
g[pname] = make_param_func()
|
|
231
261
|
|
|
232
|
-
|
|
262
|
+
# Flags: presence → True, absence → False
|
|
263
|
+
for fname, fspec in child.flags.items():
|
|
233
264
|
present = fname in parsed.flags
|
|
234
|
-
wrappers[fname] = lambda present=present: present
|
|
235
265
|
|
|
236
|
-
|
|
266
|
+
def make_flag_func(func=fspec.func, present=present):
|
|
267
|
+
def wrapper():
|
|
268
|
+
return present
|
|
269
|
+
return wrapper
|
|
237
270
|
|
|
271
|
+
g[fname] = make_flag_func()
|
|
238
272
|
|
|
239
|
-
|
|
240
|
-
# BASE LiveCLI (reusable)
|
|
241
|
-
# -------------------------
|
|
273
|
+
return child.func(cli, arg)
|
|
242
274
|
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
import asyncio
|
|
275
|
+
|
|
276
|
+
# ---------------------------------------------------------------------------
|
|
277
|
+
# Base LiveCLI
|
|
278
|
+
# ---------------------------------------------------------------------------
|
|
248
279
|
|
|
249
280
|
class LiveCLI(cmd.Cmd):
|
|
250
|
-
prompt =
|
|
281
|
+
prompt = ''
|
|
251
282
|
|
|
252
|
-
def safePrint(self, msg=
|
|
283
|
+
def safePrint(self, msg: object = '', end: str = '\n') -> None:
|
|
253
284
|
print(str(msg), end=end)
|
|
254
285
|
|
|
255
|
-
def bprint(self, msg):
|
|
286
|
+
def bprint(self, msg: object) -> None:
|
|
256
287
|
self.safePrint(msg)
|
|
257
288
|
|
|
258
|
-
def read_line_raw(self):
|
|
289
|
+
def read_line_raw(self) -> str:
|
|
259
290
|
fd = sys.stdin.fileno()
|
|
260
291
|
old = termios.tcgetattr(fd)
|
|
261
292
|
try:
|
|
262
293
|
tty.setraw(fd)
|
|
263
|
-
chars = []
|
|
294
|
+
chars: list[str] = []
|
|
264
295
|
while True:
|
|
265
296
|
ch = sys.stdin.read(1)
|
|
266
|
-
if ch in (
|
|
297
|
+
if ch in ('\r', '\n'):
|
|
267
298
|
break
|
|
268
299
|
chars.append(ch)
|
|
269
|
-
return
|
|
300
|
+
return ''.join(chars)
|
|
270
301
|
finally:
|
|
271
302
|
termios.tcsetattr(fd, termios.TCSADRAIN, old)
|
|
272
303
|
|
|
@@ -280,5 +311,5 @@ class LiveCLI(cmd.Cmd):
|
|
|
280
311
|
if stop:
|
|
281
312
|
break
|
|
282
313
|
|
|
283
|
-
def onecmd(self, line):
|
|
314
|
+
def onecmd(self, line: str):
|
|
284
315
|
return dispatch(self, line)
|
|
@@ -0,0 +1,153 @@
|
|
|
1
|
+
from hungerlib import utils
|
|
2
|
+
from mapres import res, ascii_colors, setGlobalMaps
|
|
3
|
+
from .watcher import ServerWatcher
|
|
4
|
+
from .livecli import LiveCLI, command
|
|
5
|
+
|
|
6
|
+
setGlobalMaps(ascii_colors)
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
class WatcherCLI(LiveCLI):
|
|
10
|
+
def __init__(self, watcher: ServerWatcher):
|
|
11
|
+
super().__init__()
|
|
12
|
+
self.watcher = watcher
|
|
13
|
+
self.buffer = utils.Buffer(enabled=True)
|
|
14
|
+
self.outputMode = 'both'
|
|
15
|
+
|
|
16
|
+
def printHeader(self) -> None:
|
|
17
|
+
self.safePrint(res('<yellow>-----------------------------------'))
|
|
18
|
+
self.safePrint(res('<yellow>-------- <aqua>ServerWatcher CLI <yellow>--------'))
|
|
19
|
+
self.safePrint(res('<yellow>-----------------------------------'))
|
|
20
|
+
self.safePrint('\n')
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
# ---------------------------------------------------------------------------
|
|
24
|
+
# stats command
|
|
25
|
+
# ---------------------------------------------------------------------------
|
|
26
|
+
|
|
27
|
+
@command('stats', requires_children=True)
|
|
28
|
+
def stats():
|
|
29
|
+
__description__ = 'Retrieve and print server statistics'
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@stats.child('get', requires_arguments=False)
|
|
33
|
+
def stats_get(self, arg=None):
|
|
34
|
+
__description__ = 'Retrieve and print all or specific server statistics'
|
|
35
|
+
|
|
36
|
+
self.watcher.server.refresh()
|
|
37
|
+
|
|
38
|
+
if arg is not None:
|
|
39
|
+
gb = not raw()
|
|
40
|
+
if formatted():
|
|
41
|
+
fmt = True
|
|
42
|
+
elif no_formatted():
|
|
43
|
+
fmt = False
|
|
44
|
+
else:
|
|
45
|
+
fmt = True
|
|
46
|
+
|
|
47
|
+
unit = ''
|
|
48
|
+
match arg:
|
|
49
|
+
case 'ram':
|
|
50
|
+
value = self.watcher.server.getRAM(rounding=rounding(), gb=gb)
|
|
51
|
+
name = 'RAM'
|
|
52
|
+
unit = ' GB' if gb else ' MB'
|
|
53
|
+
case 'cpu':
|
|
54
|
+
value = self.watcher.server.getCPU(rounding=rounding())
|
|
55
|
+
name = 'CPU'
|
|
56
|
+
unit = '%'
|
|
57
|
+
case 'uptime':
|
|
58
|
+
value = self.watcher.server.getUptime(formatted=fmt)
|
|
59
|
+
name = 'Uptime'
|
|
60
|
+
unit = '' if fmt else 'ms'
|
|
61
|
+
case 'tps':
|
|
62
|
+
value = self.watcher.server.getTPS(rounding=rounding(), mode=mode())
|
|
63
|
+
name = 'TPS'
|
|
64
|
+
case 'players':
|
|
65
|
+
value = self.watcher.server.getPlayers()
|
|
66
|
+
name = 'Players'
|
|
67
|
+
case 'version':
|
|
68
|
+
value = self.watcher.server.version
|
|
69
|
+
name = 'Minecraft version'
|
|
70
|
+
case 'platform':
|
|
71
|
+
value = self.watcher.server.platform
|
|
72
|
+
name = 'Server platform'
|
|
73
|
+
case _:
|
|
74
|
+
return self.safePrint('Unknown stat')
|
|
75
|
+
|
|
76
|
+
self.bprint(f'{name}: {value}{unit}')
|
|
77
|
+
else:
|
|
78
|
+
return # later: print all stats for `stats get`
|
|
79
|
+
|
|
80
|
+
|
|
81
|
+
@stats.get.param('rounding', type=int, default=2)
|
|
82
|
+
def rounding(value: int):
|
|
83
|
+
__description__ = 'placeholder'
|
|
84
|
+
return value
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
@stats.get.param('mode', type=str, default='current')
|
|
88
|
+
def mode(value: str):
|
|
89
|
+
return value
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
@stats.get.flag('raw')
|
|
93
|
+
def raw():
|
|
94
|
+
__description__ = 'placeholder'
|
|
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
|
+
# ---------------------------------------------------------------------------
|
|
111
|
+
|
|
112
|
+
@command('view', requires_children=True)
|
|
113
|
+
def view():
|
|
114
|
+
__description__ = 'Switch terminal view'
|
|
115
|
+
|
|
116
|
+
|
|
117
|
+
@view.child('cli')
|
|
118
|
+
def view_cli(self):
|
|
119
|
+
__description__ = 'Switch to CLI view'
|
|
120
|
+
|
|
121
|
+
self.watcher.router.disableOriginOutput()
|
|
122
|
+
self.outputMode = 'cli'
|
|
123
|
+
self.buffer.enabled = True
|
|
124
|
+
utils.clearTerminal()
|
|
125
|
+
self.printHeader()
|
|
126
|
+
for msg in self.buffer.captured:
|
|
127
|
+
self.safePrint(msg)
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
@view.child('watcher')
|
|
131
|
+
def view_watcher(self):
|
|
132
|
+
__description__ = 'Switch to Watcher view'
|
|
133
|
+
|
|
134
|
+
self.watcher.router.enableOriginOutput()
|
|
135
|
+
self.outputMode = 'both'
|
|
136
|
+
utils.clearTerminal()
|
|
137
|
+
self.printHeader()
|
|
138
|
+
for msg in self.watcher.router.buffer.captured:
|
|
139
|
+
self.safePrint(msg)
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
# ---------------------------------------------------------------------------
|
|
143
|
+
# clear command
|
|
144
|
+
# ---------------------------------------------------------------------------
|
|
145
|
+
|
|
146
|
+
@command('clear')
|
|
147
|
+
def clear():
|
|
148
|
+
__description__ = 'Clear the CLI terminal'
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
@clear.flag('no-buffer')
|
|
152
|
+
def no_buffer():
|
|
153
|
+
return False # DSL overrides with presence/absence
|
|
@@ -1,198 +0,0 @@
|
|
|
1
|
-
# watchercli.py
|
|
2
|
-
|
|
3
|
-
from .livecli import (
|
|
4
|
-
LiveCLI,
|
|
5
|
-
command,
|
|
6
|
-
COMMANDS,
|
|
7
|
-
generate_help,
|
|
8
|
-
)
|
|
9
|
-
from hungerlib import utils
|
|
10
|
-
from mapres import res, maps, setGlobalMaps
|
|
11
|
-
from .watcher import ServerWatcher
|
|
12
|
-
|
|
13
|
-
setGlobalMaps(maps.ascii_colors)
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
# -------------------------
|
|
17
|
-
# WatcherCLI
|
|
18
|
-
# -------------------------
|
|
19
|
-
|
|
20
|
-
class WatcherCLI(LiveCLI):
|
|
21
|
-
def __init__(self, watcher: ServerWatcher):
|
|
22
|
-
super().__init__()
|
|
23
|
-
self.watcher = watcher
|
|
24
|
-
self.buffer = utils.Buffer(enabled=True)
|
|
25
|
-
self.outputMode = "both"
|
|
26
|
-
|
|
27
|
-
def printHeader(self):
|
|
28
|
-
self.safePrint(res("<yellow>-----------------------------------"))
|
|
29
|
-
self.safePrint(res("<yellow>-------- <aqua>ServerWatcher CLI <yellow>--------"))
|
|
30
|
-
self.safePrint(res("<yellow>-----------------------------------"))
|
|
31
|
-
self.safePrint("")
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
# -------------------------
|
|
35
|
-
# Commands
|
|
36
|
-
# -------------------------
|
|
37
|
-
|
|
38
|
-
@command("stats", requires_children=True)
|
|
39
|
-
def stats():
|
|
40
|
-
__description__ = "Retrieve and print server statistics"
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
@stats.child("get", requires_arguments=False)
|
|
44
|
-
def stats_get(self: WatcherCLI, arg=None, **kwargs):
|
|
45
|
-
__description__ = "Retrieve and print all or specific server statistics"
|
|
46
|
-
|
|
47
|
-
rounding = kwargs["rounding"]
|
|
48
|
-
mode = kwargs["mode"]
|
|
49
|
-
raw = kwargs["raw"]
|
|
50
|
-
formatted = kwargs["formatted"]
|
|
51
|
-
no_formatted = kwargs["no_formatted"]
|
|
52
|
-
|
|
53
|
-
self.watcher.server.refresh()
|
|
54
|
-
|
|
55
|
-
if arg is None:
|
|
56
|
-
return # later: print all stats
|
|
57
|
-
|
|
58
|
-
gb = not raw()
|
|
59
|
-
fmt = formatted() or not no_formatted()
|
|
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
|
-
|
|
92
|
-
|
|
93
|
-
@stats.get.param("rounding", type=int, default=2)
|
|
94
|
-
def rounding(value):
|
|
95
|
-
return value
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
@stats.get.param("mode", type=str, default="current")
|
|
99
|
-
def mode(value):
|
|
100
|
-
return value
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
@stats.get.flag("raw")
|
|
104
|
-
def raw():
|
|
105
|
-
return True
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
@stats.get.flag("formatted")
|
|
109
|
-
def formatted():
|
|
110
|
-
return True
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
@stats.get.flag("no-formatted")
|
|
114
|
-
def no_formatted():
|
|
115
|
-
return False
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
# -------------------------
|
|
119
|
-
# view command
|
|
120
|
-
# -------------------------
|
|
121
|
-
|
|
122
|
-
@command("view", requires_children=True)
|
|
123
|
-
def view():
|
|
124
|
-
__description__ = "Switch terminal view"
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
@view.child("cli")
|
|
128
|
-
def view_cli(self: WatcherCLI, arg=None, **kwargs):
|
|
129
|
-
__description__ = "Switch to CLI view"
|
|
130
|
-
|
|
131
|
-
self.watcher.router.disableOriginOutput()
|
|
132
|
-
self.outputMode = "cli"
|
|
133
|
-
utils.clearTerminal()
|
|
134
|
-
self.printHeader()
|
|
135
|
-
for msg in self.buffer.captured:
|
|
136
|
-
self.safePrint(msg)
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
@view.child("watcher")
|
|
140
|
-
def view_watcher(self: WatcherCLI, arg=None, **kwargs):
|
|
141
|
-
__description__ = "Switch to Watcher view"
|
|
142
|
-
|
|
143
|
-
self.watcher.router.enableOriginOutput()
|
|
144
|
-
self.outputMode = "both"
|
|
145
|
-
utils.clearTerminal()
|
|
146
|
-
self.printHeader()
|
|
147
|
-
for msg in self.watcher.router.buffer.captured:
|
|
148
|
-
self.safePrint(msg)
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
# -------------------------
|
|
152
|
-
# clear command
|
|
153
|
-
# -------------------------
|
|
154
|
-
|
|
155
|
-
@command("clear")
|
|
156
|
-
def clear():
|
|
157
|
-
__description__ = "Clear the CLI terminal"
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
@clear.child("buffer")
|
|
161
|
-
def clear_buffer(self: WatcherCLI, arg=None, **kwargs):
|
|
162
|
-
__description__ = "Clear or keep the CLI buffer"
|
|
163
|
-
|
|
164
|
-
no_buffer = kwargs["no_buffer"]
|
|
165
|
-
|
|
166
|
-
if not no_buffer():
|
|
167
|
-
self.buffer.clear()
|
|
168
|
-
|
|
169
|
-
utils.clearTerminal()
|
|
170
|
-
self.printHeader()
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
@clear_buffer.flag("no-buffer")
|
|
174
|
-
def no_buffer():
|
|
175
|
-
return True
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
# -------------------------
|
|
179
|
-
# help command
|
|
180
|
-
# -------------------------
|
|
181
|
-
|
|
182
|
-
@command("help", requires_arguments=True)
|
|
183
|
-
def help():
|
|
184
|
-
__description__ = "Show help for a command"
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
@help.child("command", requires_arguments=True)
|
|
188
|
-
def help_command(self: WatcherCLI, cmd_name=None, **kwargs):
|
|
189
|
-
__description__ = "Show help for a specific command"
|
|
190
|
-
|
|
191
|
-
if cmd_name is None:
|
|
192
|
-
return self.safePrint("Usage: help command <name>")
|
|
193
|
-
|
|
194
|
-
cmd = COMMANDS.get(cmd_name)
|
|
195
|
-
if not cmd:
|
|
196
|
-
return self.safePrint(f"Unknown command '{cmd_name}'")
|
|
197
|
-
|
|
198
|
-
self.safePrint(generate_help(cmd))
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{serverwatcher-6.dev14 → serverwatcher-6.dev16}/src/serverwatcher/defaultconfigs/config.yaml
RENAMED
|
File without changes
|
{serverwatcher-6.dev14 → serverwatcher-6.dev16}/src/serverwatcher/defaultconfigs/messages.yaml
RENAMED
|
File without changes
|
{serverwatcher-6.dev14 → serverwatcher-6.dev16}/src/serverwatcher/defaultconfigs/watcher.yaml
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{serverwatcher-6.dev14 → serverwatcher-6.dev16}/src/serverwatcher.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|