serverwatcher 5.28.1__tar.gz → 5.30__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.
Files changed (22) hide show
  1. {serverwatcher-5.28.1/src/serverwatcher.egg-info → serverwatcher-5.30}/PKG-INFO +1 -1
  2. {serverwatcher-5.28.1 → serverwatcher-5.30}/pyproject.toml +1 -1
  3. serverwatcher-5.30/src/serverwatcher/__main__.py +47 -0
  4. {serverwatcher-5.28.1 → serverwatcher-5.30}/src/serverwatcher/configclasses/messages.py +4 -36
  5. {serverwatcher-5.28.1 → serverwatcher-5.30}/src/serverwatcher/defaultconfigs/messages.yaml +4 -0
  6. {serverwatcher-5.28.1 → serverwatcher-5.30}/src/serverwatcher/validator.py +6 -2
  7. {serverwatcher-5.28.1 → serverwatcher-5.30}/src/serverwatcher/watcher.py +28 -25
  8. {serverwatcher-5.28.1 → serverwatcher-5.30/src/serverwatcher.egg-info}/PKG-INFO +1 -1
  9. serverwatcher-5.28.1/src/serverwatcher/__main__.py +0 -34
  10. {serverwatcher-5.28.1 → serverwatcher-5.30}/LICENSE +0 -0
  11. {serverwatcher-5.28.1 → serverwatcher-5.30}/README.md +0 -0
  12. {serverwatcher-5.28.1 → serverwatcher-5.30}/setup.cfg +0 -0
  13. {serverwatcher-5.28.1 → serverwatcher-5.30}/src/serverwatcher/__init__.py +0 -0
  14. {serverwatcher-5.28.1 → serverwatcher-5.30}/src/serverwatcher/configclasses/__init__.py +0 -0
  15. {serverwatcher-5.28.1 → serverwatcher-5.30}/src/serverwatcher/configclasses/config.py +0 -0
  16. {serverwatcher-5.28.1 → serverwatcher-5.30}/src/serverwatcher/configclasses/watcher.py +0 -0
  17. {serverwatcher-5.28.1 → serverwatcher-5.30}/src/serverwatcher/defaultconfigs/config.yaml +0 -0
  18. {serverwatcher-5.28.1 → serverwatcher-5.30}/src/serverwatcher/defaultconfigs/watcher.yaml +0 -0
  19. {serverwatcher-5.28.1 → serverwatcher-5.30}/src/serverwatcher.egg-info/SOURCES.txt +0 -0
  20. {serverwatcher-5.28.1 → serverwatcher-5.30}/src/serverwatcher.egg-info/dependency_links.txt +0 -0
  21. {serverwatcher-5.28.1 → serverwatcher-5.30}/src/serverwatcher.egg-info/requires.txt +0 -0
  22. {serverwatcher-5.28.1 → serverwatcher-5.30}/src/serverwatcher.egg-info/top_level.txt +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: serverwatcher
3
- Version: 5.28.1
3
+ Version: 5.30
4
4
  Summary: A HungerLib-powered Minecraft server automation engine.
5
5
  Author: iFamished
6
6
  License: GPL-3.0
@@ -7,7 +7,7 @@ build-backend = "setuptools.build_meta"
7
7
 
8
8
  [project]
9
9
  name = "serverwatcher"
10
- version = "5.28.1"
10
+ version = "5.30"
11
11
  description = "A HungerLib-powered Minecraft server automation engine."
12
12
  readme = "README.md"
13
13
  requires-python = ">=3.14"
@@ -0,0 +1,47 @@
1
+ from .watcher import ServerWatcher
2
+ from .validator import validate_all
3
+ from hungerlib import (
4
+ ValidationError,
5
+ FatalError,
6
+ TypeMismatchError,
7
+ FallbackError,
8
+ RecommendedError,
9
+ )
10
+ import time
11
+
12
+ def main():
13
+ try:
14
+ validate_all()
15
+
16
+ except FatalError as e:
17
+ print("❌ FATAL CONFIG ERROR:")
18
+ print(e)
19
+ return
20
+
21
+ except TypeMismatchError as e:
22
+ print("❌ TYPE MISMATCH ERROR:")
23
+ print(e)
24
+ return
25
+
26
+ except FallbackError as e:
27
+ print("⚠️ FALLBACKS IN USE:")
28
+ print(e)
29
+ print("Continuing in 5 seconds...")
30
+ time.sleep(5)
31
+
32
+ except RecommendedError as e:
33
+ print("⚠️ RECOMMENDED KEYS MISSING:")
34
+ print(e)
35
+ print("Continuing in 5 seconds...")
36
+ time.sleep(5)
37
+
38
+ except ValidationError as e:
39
+ print("❌ CONFIG ERROR:")
40
+ print(e)
41
+ return
42
+
43
+ watcher = ServerWatcher()
44
+ watcher.run()
45
+
46
+ if __name__ == "__main__":
47
+ main()
@@ -10,24 +10,8 @@ class MessagesConfig:
10
10
 
11
11
  broadcast_restart_at: str = 'broadcast_restart_at'
12
12
 
13
- minute_120: str = 'broadcast_minutes.120'
14
- minute_60: str = 'broadcast_minutes.60'
15
- minute_45: str = 'broadcast_minutes.45'
16
- minute_30: str = 'broadcast_minutes.30'
17
- minute_15: str = 'broadcast_minutes.15'
18
- minute_5: str = 'broadcast_minutes.5'
19
- minute_1: str = 'broadcast_minutes.1'
20
-
21
- second_10: str = 'broadcast_seconds.10'
22
- second_9: str = 'broadcast_seconds.9'
23
- second_8: str = 'broadcast_seconds.8'
24
- second_7: str = 'broadcast_seconds.7'
25
- second_6: str = 'broadcast_seconds.6'
26
- second_5: str = 'broadcast_seconds.5'
27
- second_4: str = 'broadcast_seconds.4'
28
- second_3: str = 'broadcast_seconds.3'
29
- second_2: str = 'broadcast_seconds.2'
30
- second_1: str = 'broadcast_seconds.1'
13
+ minute_template: str = 'broadcast_templates.minutes'
14
+ second_template: str = 'broadcast_templates.seconds'
31
15
 
32
16
  startup: str = 'logging.startup'
33
17
  status_check: str = 'logging.status_check'
@@ -66,24 +50,8 @@ class fallbacks:
66
50
 
67
51
  broadcast_restart_at = '{prefix} The server will restart at {time} CDT.'
68
52
 
69
- minute_120 = '{prefix} The server will restart in 2 hours.'
70
- minute_60 = '{prefix} The server will restart in 1 hour.'
71
- minute_45 = '{prefix} The server will restart in 45 minutes.'
72
- minute_30 = '{prefix} The server will restart in 30 minutes.'
73
- minute_15 = '{prefix} The server will restart in 15 minutes.'
74
- minute_5 = '{prefix} The server will restart in 5 minutes.'
75
- minute_1 = '{prefix} The server will restart in 1 minute.'
76
-
77
- second_10 = '{prefix} <red>The server is restarting in 10 seconds!'
78
- second_9 = '{prefix} <red>The server is restarting in 9 seconds!'
79
- second_8 = '{prefix} <red>The server is restarting in 8 seconds!'
80
- second_7 = '{prefix} <red>The server is restarting in 7 seconds!'
81
- second_6 = '{prefix} <red>The server is restarting in 6 seconds!'
82
- second_5 = '{prefix} <red>The server is restarting in 5 seconds!'
83
- second_4 = '{prefix} <red>The server is restarting in 4 seconds!'
84
- second_3 = '{prefix} <red>The server is restarting in 3 seconds!'
85
- second_2 = '{prefix} <red>The server is restarting in 2 seconds!'
86
- second_1 = '{prefix} <red>The server is restarting in 1 second!'
53
+ minute_template = '{prefix} Restart in {n} minute{s}!'
54
+ second_template = '{prefix} <red>Restarting in {n} second{s}!'
87
55
 
88
56
  startup = 'ServerWatcher is running!'
89
57
  status_check = 'Checking server status...'
@@ -43,6 +43,10 @@ bullet: '-'
43
43
 
44
44
  broadcast_restart_at: '{prefix} The server will restart at {time} CDT.'
45
45
 
46
+ broadcast_templates:
47
+ minutes: '{prefix} Restart in {n} minute{s}!'
48
+ seconds: '{prefix} <red>Restarting in {n} second{s}!'
49
+
46
50
  broadcast_minutes: {}
47
51
  broadcast_seconds: {}
48
52
 
@@ -10,8 +10,12 @@ from serverwatcher.configclasses.watcher import WatcherConfig
10
10
 
11
11
  utils.clearTerminal()
12
12
 
13
- # You can customize messages here if you want
14
- v = Validator()
13
+ v = Validator(
14
+ throw_on_required=True,
15
+ throw_on_type_mismatch=True,
16
+ throw_on_fallback=True,
17
+ throw_on_recommended=True,
18
+ )
15
19
 
16
20
 
17
21
  def validate_global_config(c):
@@ -131,26 +131,35 @@ class ServerWatcher:
131
131
 
132
132
  self.router.broadcast(self.messages.broadcast_restart_at, time=time_str)
133
133
 
134
- # minute callbacks
134
+ def plural(n):
135
+ return '' if n == 1 else 's'
136
+
137
+ # minute message generator
138
+ def minute_msg(n):
139
+ raw = self.messages.minute_template
140
+ return self.res(raw, n=n, s=plural(n))
141
+
142
+ # second message generator
143
+ def second_msg(n):
144
+ raw = self.messages.second_template
145
+ return self.res(raw, n=n, s=plural(n))
146
+
147
+ # minute callbacks using template
135
148
  minute_callbacks = {
136
- int(k.split("_")[1]): (
137
- lambda raw=self.messages.as_map()[k]:
138
- (self.router.broadcast(self.res(raw)),
139
- self.router.origin(raw))
140
- )
141
- for k in self.messages.as_map()
142
- if k.startswith("minute_")
149
+ n: (lambda n=n: (
150
+ self.router.broadcast(minute_msg(n)),
151
+ self.router.origin(minute_msg(n))
152
+ ))
153
+ for n in self.watcherconfig.snap_minutes
143
154
  }
144
155
 
145
- # second callbacks
156
+ # second callbacks using template
146
157
  second_callbacks = {
147
- int(k.split("_")[1]): (
148
- lambda raw=self.messages.as_map()[k]:
149
- (self.router.broadcast(self.res(raw)),
150
- self.router.origin(raw))
151
- )
152
- for k in self.messages.as_map()
153
- if k.startswith("second_")
158
+ n: (lambda n=n: (
159
+ self.router.broadcast(second_msg(n)),
160
+ self.router.origin(second_msg(n))
161
+ ))
162
+ for n in range(1, 11)
154
163
  }
155
164
 
156
165
  utils.runCountdownEvents(
@@ -180,21 +189,15 @@ class ServerWatcher:
180
189
  no_restart_reasons = []
181
190
 
182
191
  if snap.ram >= self.watcherconfig.threshold_ram:
183
- restart_reasons.append(
184
- self.res(self.messages.reason_ram, ram=snap.ram, threshold=self.watcherconfig.threshold_ram)
185
- )
192
+ restart_reasons.append(self.res(self.messages.reason_ram, ram=snap.ram, threshold=self.watcherconfig.threshold_ram))
186
193
  pro += int(round(snap.ram, 0) - (self.watcherconfig.threshold_ram - 1))
187
194
 
188
195
  if snap.cpu >= self.watcherconfig.threshold_cpu:
189
- restart_reasons.append(
190
- self.res(self.messages.reason_cpu, cpu=snap.cpu, threshold=self.watcherconfig.threshold_cpu)
191
- )
196
+ restart_reasons.append(self.res(self.messages.reason_cpu, cpu=snap.cpu, threshold=self.watcherconfig.threshold_cpu))
192
197
  pro += self.watcherconfig.weight_cpu
193
198
 
194
199
  if snap.uptime // 3600 >= self.watcherconfig.threshold_uptime:
195
- restart_reasons.append(
196
- self.res(self.messages.reason_uptime, uptime=snap.uptime_formatted, threshold=self.watcherconfig.threshold_uptime)
197
- )
200
+ restart_reasons.append(self.res(self.messages.reason_uptime, uptime=snap.uptime_formatted, threshold=self.watcherconfig.threshold_uptime))
198
201
  pro += self.watcherconfig.weight_uptime
199
202
 
200
203
  if (snap.tps if snap.tps is not None else 20) <= self.watcherconfig.threshold_tps:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: serverwatcher
3
- Version: 5.28.1
3
+ Version: 5.30
4
4
  Summary: A HungerLib-powered Minecraft server automation engine.
5
5
  Author: iFamished
6
6
  License: GPL-3.0
@@ -1,34 +0,0 @@
1
- from .watcher import ServerWatcher
2
- from .validator import validate_all
3
- from hungerlib.utils.exceptions import (
4
- ValidationError,
5
- FatalValidationError,
6
- ValidationFallbacks,
7
- )
8
- import time
9
-
10
- def main():
11
- try:
12
- validate_all()
13
-
14
- except FatalValidationError as e:
15
- print("❌ FATAL CONFIG ERROR:")
16
- print(e)
17
- return # fully cancel
18
-
19
- except ValidationFallbacks as e:
20
- print("⚠️ CONFIG DEFAULTS IN USE:")
21
- print(e)
22
- print("Continuing in 5 seconds...")
23
- time.sleep(5)
24
-
25
- except ValidationError as e:
26
- print("❌ CONFIG ERROR:")
27
- print(e)
28
- return # non-fatal but still cancel
29
-
30
- watcher = ServerWatcher()
31
- watcher.run()
32
-
33
- if __name__ == "__main__":
34
- main()
File without changes
File without changes
File without changes