mcserver-cli 4.7.2__py3-none-any.whl → 4.7.3__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.
- mcserver/__init__.py +1 -1
- mcserver/app.py +10 -2
- mcserver/caching.py +3 -12
- mcserver/cli.py +0 -1
- mcserver/commands/add_projects.py +108 -24
- mcserver/commands/initialize_server.py +1 -1
- mcserver/commands/op_grant.py +3 -1
- mcserver/commands/op_list.py +3 -1
- mcserver/commands/op_revoke.py +3 -1
- mcserver/commands/start_server.py +12 -14
- mcserver/commands/whitelist_add.py +3 -1
- mcserver/commands/whitelist_list.py +3 -1
- mcserver/commands/whitelist_remove.py +3 -1
- mcserver/modrinth/apis/__init__.py +9 -3
- mcserver/modrinth/apis/get_project_informations.py +7 -3
- mcserver/modrinth/apis/get_project_versions.py +8 -3
- mcserver/modrinth/apis/search_projects.py +7 -7
- mcserver/modrinth/paths.py +1 -1
- mcserver/modrinth/project_records.py +12 -7
- mcserver/modrinth/slug_index.py +45 -13
- mcserver/networking.py +18 -9
- mcserver/purpurmc/api.py +22 -0
- mcserver/quiltmc/apis/__init__.py +4 -0
- mcserver/quiltmc/apis/get_installer_versions.py +37 -0
- mcserver/quiltmc/apis/get_loader_versions.py +38 -0
- mcserver/quiltmc/typings/__init__.py +5 -0
- mcserver/quiltmc/typings/installer_version.py +11 -0
- mcserver/quiltmc/typings/loader_version.py +16 -0
- mcserver/quiltmc/typings/shared.py +10 -0
- mcserver/quiltmc/urls.py +24 -0
- mcserver/server_files/banned_ips.py +2 -99
- mcserver/server_files/banned_players.py +3 -143
- mcserver/server_files/paths.py +2 -0
- mcserver/shared.py +15 -4
- mcserver/state.py +6 -3
- mcserver/urls.py +2 -0
- {mcserver_cli-4.7.2.dist-info → mcserver_cli-4.7.3.dist-info}/METADATA +1 -1
- mcserver_cli-4.7.3.dist-info/RECORD +80 -0
- mcserver_cli-4.7.2.dist-info/RECORD +0 -71
- {mcserver_cli-4.7.2.dist-info → mcserver_cli-4.7.3.dist-info}/WHEEL +0 -0
- {mcserver_cli-4.7.2.dist-info → mcserver_cli-4.7.3.dist-info}/entry_points.txt +0 -0
- {mcserver_cli-4.7.2.dist-info → mcserver_cli-4.7.3.dist-info}/licenses/LICENSE +0 -0
mcserver/__init__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "4.7.
|
|
1
|
+
__version__ = "4.7.3"
|
mcserver/app.py
CHANGED
|
@@ -33,8 +33,16 @@ def main():
|
|
|
33
33
|
log_handler = ClearLineHandler(sys.stdout)
|
|
34
34
|
log_handler.setFormatter(logging.Formatter("[%(levelname)s]: %(message)s"))
|
|
35
35
|
if debug_mode:
|
|
36
|
-
logging.basicConfig(
|
|
36
|
+
logging.basicConfig(
|
|
37
|
+
level=logging.DEBUG,
|
|
38
|
+
format="[%(levelname)s] [%(module)s]: %(message)s",
|
|
39
|
+
handlers=[log_handler],
|
|
40
|
+
)
|
|
37
41
|
else:
|
|
38
|
-
logging.basicConfig(
|
|
42
|
+
logging.basicConfig(
|
|
43
|
+
level=logging.INFO,
|
|
44
|
+
format="[%(levelname)s]: %(message)s",
|
|
45
|
+
handlers=[log_handler],
|
|
46
|
+
)
|
|
39
47
|
|
|
40
48
|
sys.exit(cli.main())
|
mcserver/caching.py
CHANGED
|
@@ -1,16 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
from pathlib import Path
|
|
3
|
-
|
|
4
|
-
cache_dir = Path.home() / ".cache"
|
|
5
|
-
|
|
6
|
-
xdg_cache_dir = os.getenv("XDG_CACHE_DIR")
|
|
7
|
-
if xdg_cache_dir:
|
|
8
|
-
cache_dir = Path(xdg_cache_dir)
|
|
9
|
-
|
|
10
|
-
mcserver_cache_dir = cache_dir / "mcserver"
|
|
1
|
+
from .paths import cache_dir
|
|
11
2
|
|
|
12
3
|
|
|
13
4
|
def create_file(file_name: str, file_data: bytes):
|
|
14
|
-
|
|
15
|
-
cache_file =
|
|
5
|
+
cache_dir.mkdir(parents=True, exist_ok=True)
|
|
6
|
+
cache_file = cache_dir / file_name
|
|
16
7
|
cache_file.write_bytes(file_data)
|
mcserver/cli.py
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import json
|
|
2
1
|
import logging
|
|
3
2
|
from argparse import Namespace
|
|
3
|
+
from datetime import UTC, datetime
|
|
4
4
|
|
|
5
5
|
from .. import config, networking, paths, resolver, shared
|
|
6
6
|
from ..modrinth import apis as modrinth_api
|
|
7
|
-
from ..modrinth import slug_index
|
|
7
|
+
from ..modrinth import project_records, slug_index
|
|
8
8
|
from ..modrinth.typings import (
|
|
9
9
|
Dependency,
|
|
10
10
|
DependencyType,
|
|
@@ -22,11 +22,19 @@ dependency_types: dict[DependencyType, int] = {
|
|
|
22
22
|
"incompatible": 3,
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
|
|
26
|
-
class
|
|
25
|
+
|
|
26
|
+
class GetVersionError(Exception):
|
|
27
|
+
pass
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class GetDependenciesError(Exception):
|
|
31
|
+
pass
|
|
32
|
+
|
|
33
|
+
|
|
27
34
|
class ResolverTranslationError(Exception):
|
|
28
35
|
pass
|
|
29
36
|
|
|
37
|
+
|
|
30
38
|
def human_to_resolver(dependencies: list[Dependency]) -> dict[str, int]:
|
|
31
39
|
resolver_dependencies: dict[str, int] = {}
|
|
32
40
|
for dependency in dependencies:
|
|
@@ -52,10 +60,14 @@ def run(args: Namespace) -> int:
|
|
|
52
60
|
projects: list[str] = args.projects
|
|
53
61
|
|
|
54
62
|
if not (paths.configs_dir / "server.json").exists():
|
|
55
|
-
logger.error(
|
|
63
|
+
logger.error(
|
|
64
|
+
"Configuration file for server does not exist, is server initialized?"
|
|
65
|
+
)
|
|
56
66
|
return 1
|
|
57
67
|
|
|
58
|
-
server_config = config.read_config(
|
|
68
|
+
server_config = config.read_config(
|
|
69
|
+
"server", shared.default_configs["server"]["format_version"]
|
|
70
|
+
)
|
|
59
71
|
game_version: str = server_config["game_version"]
|
|
60
72
|
loader_name: str = server_config["loader"]["name"]
|
|
61
73
|
|
|
@@ -64,20 +76,29 @@ def run(args: Namespace) -> int:
|
|
|
64
76
|
logger.error(f"{loader_name.capitalize()} does not support mods")
|
|
65
77
|
return 1
|
|
66
78
|
|
|
67
|
-
project_label, project_directory = shared.get_loader_context(loader_name)
|
|
68
|
-
|
|
69
79
|
# mod vs project labeling
|
|
70
80
|
project_label, project_directory = shared.get_loader_context(loader_name)
|
|
71
81
|
if project_directory is None:
|
|
72
|
-
logger.error(
|
|
82
|
+
logger.error(
|
|
83
|
+
"Wait 'project_directory' it can't be None! it just to satisfy pyright"
|
|
84
|
+
)
|
|
73
85
|
return 1
|
|
74
86
|
|
|
75
87
|
project_ids: list[str] = []
|
|
76
88
|
project_versions: dict[str, ProjectVersion] = {}
|
|
77
89
|
for project in projects:
|
|
78
|
-
|
|
90
|
+
try:
|
|
91
|
+
versions = modrinth_api.get_project_versions(
|
|
92
|
+
project, loader_name, game_version, include_changelog=False
|
|
93
|
+
)
|
|
94
|
+
except modrinth_api.GetProjectVersionsError:
|
|
95
|
+
logger.error("Failed to get project versions!")
|
|
96
|
+
return 1
|
|
97
|
+
|
|
79
98
|
if len(versions) == 0:
|
|
80
|
-
raise GetVersionError(
|
|
99
|
+
raise GetVersionError(
|
|
100
|
+
f"{project} has no version for {loader_name.capitalize()} {game_version}"
|
|
101
|
+
)
|
|
81
102
|
|
|
82
103
|
project_version = versions[0]
|
|
83
104
|
project_id = project_version["project_id"]
|
|
@@ -114,12 +135,25 @@ def run(args: Namespace) -> int:
|
|
|
114
135
|
dependencies = get_project_dependencies(project_id)
|
|
115
136
|
|
|
116
137
|
if dependencies is None:
|
|
117
|
-
raise GetDependenciesError(
|
|
138
|
+
raise GetDependenciesError(
|
|
139
|
+
f"No dependency provider available for {project_id}"
|
|
140
|
+
)
|
|
118
141
|
|
|
119
142
|
return human_to_resolver(dependencies)
|
|
120
143
|
|
|
144
|
+
try:
|
|
145
|
+
resolved_projects: list[ProjectData] = resolver.resolver_to_human(
|
|
146
|
+
resolver.resolve_dependencies(
|
|
147
|
+
project_ids, get_dependencies, resolver.required_only
|
|
148
|
+
)
|
|
149
|
+
)
|
|
150
|
+
except modrinth_api.GetProjectVersionsError:
|
|
151
|
+
logger.error("Failed to get project versions!")
|
|
152
|
+
return 1
|
|
121
153
|
|
|
122
|
-
|
|
154
|
+
resolved_project_data: dict[str, ProjectData] = {}
|
|
155
|
+
for project in resolved_projects:
|
|
156
|
+
resolved_project_data[project["project_id"]] = project
|
|
123
157
|
|
|
124
158
|
all_project_ids: set[str] = set()
|
|
125
159
|
incompatible_dependencies: set[str] = set()
|
|
@@ -150,7 +184,9 @@ def run(args: Namespace) -> int:
|
|
|
150
184
|
continue
|
|
151
185
|
|
|
152
186
|
if "highest_type" not in project:
|
|
153
|
-
logger.debug(
|
|
187
|
+
logger.debug(
|
|
188
|
+
f"{project_id} has no 'highest_type', this should be already handled by 'is_manual' but somehow it passed it"
|
|
189
|
+
)
|
|
154
190
|
continue
|
|
155
191
|
|
|
156
192
|
match project["highest_type"]:
|
|
@@ -164,7 +200,11 @@ def run(args: Namespace) -> int:
|
|
|
164
200
|
# Conflict detection
|
|
165
201
|
conflicting_projects = required_dependencies & incompatible_dependencies
|
|
166
202
|
if conflicting_projects:
|
|
167
|
-
logger.error(
|
|
203
|
+
logger.error(
|
|
204
|
+
f"Found conflicting dependencies: {', '.join(conflicting_projects)}"
|
|
205
|
+
)
|
|
206
|
+
logger.error("Cannon continue.")
|
|
207
|
+
return 1
|
|
168
208
|
|
|
169
209
|
# fetch additional info
|
|
170
210
|
project_informations: dict[str, ProjectInformation] = {}
|
|
@@ -173,43 +213,57 @@ def run(args: Namespace) -> int:
|
|
|
173
213
|
|
|
174
214
|
# Display information
|
|
175
215
|
required_projects_count = len(required_projects)
|
|
176
|
-
logger.info(
|
|
216
|
+
logger.info(
|
|
217
|
+
f"{shared.pluralize(project_label, required_projects_count).capitalize()} that {shared.pluralize('is', required_projects_count)} going to be downloaded:"
|
|
218
|
+
)
|
|
177
219
|
required_project_display: list[str] = []
|
|
178
220
|
for project_id in list(required_projects):
|
|
179
|
-
required_project_display.append(
|
|
221
|
+
required_project_display.append(
|
|
222
|
+
f"{project_informations[project_id]['project_name']} ({project_id})"
|
|
223
|
+
)
|
|
180
224
|
|
|
181
225
|
required_project_display.sort()
|
|
182
226
|
print(f" {', '.join(required_project_display)}\n")
|
|
183
227
|
|
|
184
228
|
optional_projects_count = len(optional_projects)
|
|
185
229
|
if optional_projects:
|
|
186
|
-
logger.info(
|
|
230
|
+
logger.info(
|
|
231
|
+
f"{shared.pluralize(project_label, optional_projects_count).capitalize()} that {shared.pluralize('is', optional_projects_count)} optional:"
|
|
232
|
+
)
|
|
187
233
|
optional_project_display: list[str] = []
|
|
188
234
|
for project_id in list(optional_projects):
|
|
189
|
-
optional_project_display.append(
|
|
235
|
+
optional_project_display.append(
|
|
236
|
+
f"{project_informations[project_id]['project_name']} ({project_id})"
|
|
237
|
+
)
|
|
190
238
|
|
|
191
239
|
optional_project_display.sort()
|
|
192
240
|
print(f" {', '.join(optional_project_display)}\n")
|
|
193
241
|
|
|
194
|
-
|
|
195
242
|
incompatible_projects_count = len(incompatible_projects)
|
|
196
243
|
if incompatible_projects:
|
|
197
|
-
logger.info(
|
|
244
|
+
logger.info(
|
|
245
|
+
f"{shared.pluralize(project_label, incompatible_projects_count).capitalize()} that {shared.pluralize('is', incompatible_projects_count)} incompatible:"
|
|
246
|
+
)
|
|
198
247
|
incompatible_project_display: list[str] = []
|
|
199
248
|
for project_id in list(incompatible_projects):
|
|
200
|
-
incompatible_project_display.append(
|
|
249
|
+
incompatible_project_display.append(
|
|
250
|
+
f"{project_informations[project_id]['project_name']} ({project_id})"
|
|
251
|
+
)
|
|
201
252
|
|
|
202
253
|
incompatible_project_display.sort()
|
|
203
254
|
print(f" {', '.join(incompatible_project_display)}\n")
|
|
204
255
|
|
|
205
256
|
# Confirmation prompt
|
|
206
|
-
confirmation_answer = shared.confirmation_prompt(
|
|
257
|
+
confirmation_answer = shared.confirmation_prompt(
|
|
258
|
+
"Do you want to continue?", default_option=True
|
|
259
|
+
)
|
|
207
260
|
|
|
208
261
|
if not confirmation_answer:
|
|
209
262
|
print("Cancelled")
|
|
210
263
|
return 1
|
|
211
264
|
|
|
212
265
|
for project_id in required_projects:
|
|
266
|
+
project_data = resolved_project_data[project_id]
|
|
213
267
|
project_information = project_informations[project_id]
|
|
214
268
|
project_version = project_versions[project_id]
|
|
215
269
|
version_files = project_version["files"]
|
|
@@ -223,9 +277,39 @@ def run(args: Namespace) -> int:
|
|
|
223
277
|
if primary_file is None:
|
|
224
278
|
primary_file = version_files[0]
|
|
225
279
|
|
|
280
|
+
file_path = project_directory / primary_file["file_name"]
|
|
281
|
+
if file_path:
|
|
282
|
+
logger.info(f"File '{file_path}' already exist, skipping download")
|
|
283
|
+
continue
|
|
284
|
+
|
|
226
285
|
logger.info(f"Downloading {project_information['project_name']}...")
|
|
227
286
|
project_directory.mkdir(exist_ok=True, parents=True)
|
|
228
|
-
|
|
287
|
+
|
|
288
|
+
sha512_hash = primary_file["file_hashes"].get("sha512")
|
|
289
|
+
if sha512_hash is not None:
|
|
290
|
+
networking.download(
|
|
291
|
+
primary_file["download_url"], file_path, hashes={"sha512": sha512_hash}
|
|
292
|
+
)
|
|
293
|
+
else:
|
|
294
|
+
networking.download(primary_file["download_url"], file_path)
|
|
295
|
+
|
|
296
|
+
project_records.write_record(
|
|
297
|
+
project_id,
|
|
298
|
+
{
|
|
299
|
+
"project_name": project_information.get("project_name"),
|
|
300
|
+
"project_slug": project_information.get("project_slug"),
|
|
301
|
+
"version_id": project_version["version_id"],
|
|
302
|
+
"version_environment": project_version["environment"],
|
|
303
|
+
"file": primary_file,
|
|
304
|
+
"added_time": datetime.now(tz=UTC).isoformat(),
|
|
305
|
+
"discovered_time": datetime.now(tz=UTC).isoformat(),
|
|
306
|
+
"updated_time": None,
|
|
307
|
+
"is_manual": project_data["is_manual"],
|
|
308
|
+
"highest_type": project_data["highest_type"],
|
|
309
|
+
"dependencies": project_data["dependencies"],
|
|
310
|
+
"dependents": project_data["dependents"],
|
|
311
|
+
},
|
|
312
|
+
)
|
|
229
313
|
|
|
230
314
|
for project_information in project_informations.values():
|
|
231
315
|
project_slug = project_information.get("project_slug")
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import copy
|
|
2
2
|
import logging
|
|
3
3
|
from argparse import Namespace
|
|
4
|
-
from pathlib import Path
|
|
5
4
|
|
|
6
5
|
from .. import __version__, config, shared, state
|
|
7
6
|
from ..metadata import metadata_file, set_metadata
|
|
@@ -10,6 +9,7 @@ from ..modrinth.shared import SearchSortIndex
|
|
|
10
9
|
|
|
11
10
|
logger = logging.getLogger(__name__)
|
|
12
11
|
|
|
12
|
+
|
|
13
13
|
def run(args: Namespace) -> int:
|
|
14
14
|
# CLI arguments
|
|
15
15
|
game_version: str = args.game_version
|
mcserver/commands/op_grant.py
CHANGED
|
@@ -12,7 +12,9 @@ logger = logging.getLogger(__name__)
|
|
|
12
12
|
|
|
13
13
|
def run(args: Namespace) -> int:
|
|
14
14
|
if not ops_file_path.exists():
|
|
15
|
-
logger.info(
|
|
15
|
+
logger.info(
|
|
16
|
+
f"Operator file '{ops_file_path.relative_to(current_dir)}' does not exist, creating new one"
|
|
17
|
+
)
|
|
16
18
|
ops_file_path.write_text("[]")
|
|
17
19
|
|
|
18
20
|
player_ids: list[str] = args.players
|
mcserver/commands/op_list.py
CHANGED
|
@@ -11,7 +11,9 @@ logger = logging.getLogger(__name__)
|
|
|
11
11
|
|
|
12
12
|
def run(args: Namespace) -> int:
|
|
13
13
|
if not ops_file_path.exists():
|
|
14
|
-
logger.error(
|
|
14
|
+
logger.error(
|
|
15
|
+
f"Operator file '{ops_file_path.relative_to(current_dir)}' does not exist"
|
|
16
|
+
)
|
|
15
17
|
return 1
|
|
16
18
|
|
|
17
19
|
operator_players = ops.list_players()
|
mcserver/commands/op_revoke.py
CHANGED
|
@@ -12,7 +12,9 @@ logger = logging.getLogger(__name__)
|
|
|
12
12
|
|
|
13
13
|
def run(args: Namespace) -> int:
|
|
14
14
|
if not ops_file_path.exists():
|
|
15
|
-
logger.error(
|
|
15
|
+
logger.error(
|
|
16
|
+
f"Operator file '{ops_file_path.relative_to(current_dir)}' does not exist"
|
|
17
|
+
)
|
|
16
18
|
return 1
|
|
17
19
|
player_ids: list[str] = args.players
|
|
18
20
|
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
+
import json
|
|
1
2
|
import logging
|
|
2
3
|
from argparse import Namespace
|
|
3
4
|
|
|
4
|
-
|
|
5
|
+
from .. import state
|
|
6
|
+
from ..paths import current_dir
|
|
5
7
|
|
|
6
|
-
|
|
8
|
+
logger = logging.getLogger(__name__)
|
|
7
9
|
|
|
8
|
-
from .. import state
|
|
9
10
|
|
|
11
|
+
def run(args: Namespace) -> int:
|
|
10
12
|
# Check MCServer status
|
|
11
13
|
if not state.state_file.parent.exists():
|
|
12
14
|
logger.error("State file not exist, is MCServer initialized?")
|
|
@@ -27,7 +29,7 @@ def run(args: Namespace) -> int:
|
|
|
27
29
|
return 1
|
|
28
30
|
|
|
29
31
|
# Set state
|
|
30
|
-
state.set_state("
|
|
32
|
+
state.set_state("server_running")
|
|
31
33
|
|
|
32
34
|
import os
|
|
33
35
|
import shutil
|
|
@@ -40,17 +42,13 @@ def run(args: Namespace) -> int:
|
|
|
40
42
|
"launcher", shared.default_configs["launcher"]["format_version"]
|
|
41
43
|
)
|
|
42
44
|
|
|
43
|
-
jarfile = Path(launcher_config["jarfile"])
|
|
45
|
+
jarfile = current_dir / Path(launcher_config["jarfile"]).name
|
|
44
46
|
memory_config = launcher_config["ram"]
|
|
45
47
|
|
|
46
48
|
# Download jarfile
|
|
47
49
|
if not jarfile.exists():
|
|
48
|
-
import json
|
|
49
|
-
|
|
50
50
|
from .. import networking
|
|
51
51
|
|
|
52
|
-
state.set_state("downloading_server")
|
|
53
|
-
|
|
54
52
|
server_config = config.read_config(
|
|
55
53
|
"server", shared.default_configs["server"]["format_version"]
|
|
56
54
|
)
|
|
@@ -74,7 +72,7 @@ def run(args: Namespace) -> int:
|
|
|
74
72
|
)
|
|
75
73
|
networking.download(
|
|
76
74
|
fabricmc_meta.download_url(game_version, loader_version, "1.1.2"),
|
|
77
|
-
jarfile,
|
|
75
|
+
jarfile.name,
|
|
78
76
|
)
|
|
79
77
|
|
|
80
78
|
# case "quilt":
|
|
@@ -98,7 +96,7 @@ def run(args: Namespace) -> int:
|
|
|
98
96
|
)["download_props"]["server:default"]
|
|
99
97
|
networking.download(
|
|
100
98
|
download_prop["download_url"],
|
|
101
|
-
jarfile,
|
|
99
|
+
jarfile.name,
|
|
102
100
|
hashes={"sha256": download_prop["file_hashes"]["sha256"]},
|
|
103
101
|
)
|
|
104
102
|
case "purpur":
|
|
@@ -112,7 +110,7 @@ def run(args: Namespace) -> int:
|
|
|
112
110
|
)
|
|
113
111
|
networking.download(
|
|
114
112
|
purpurmc_api.download_url("purpur", game_version, loader_version),
|
|
115
|
-
jarfile,
|
|
113
|
+
jarfile.name,
|
|
116
114
|
hashes={"md5": project_build["artifact_md5"]},
|
|
117
115
|
)
|
|
118
116
|
|
|
@@ -152,7 +150,7 @@ def run(args: Namespace) -> int:
|
|
|
152
150
|
|
|
153
151
|
# Check stuff
|
|
154
152
|
if not shutil.which("java"):
|
|
155
|
-
logger.error("'java' not found")
|
|
153
|
+
logger.error("'java' not found, is Java installed?")
|
|
156
154
|
return 1
|
|
157
155
|
|
|
158
156
|
if memory_config["min"] > memory_config["max"]:
|
|
@@ -165,7 +163,7 @@ def run(args: Namespace) -> int:
|
|
|
165
163
|
f"-Xmx{memory_config['max']}M",
|
|
166
164
|
f"-Xms{memory_config['min']}M",
|
|
167
165
|
"-jar",
|
|
168
|
-
|
|
166
|
+
jarfile,
|
|
169
167
|
]
|
|
170
168
|
|
|
171
169
|
if launcher_config["is_nogui"]:
|
|
@@ -12,7 +12,9 @@ logger = logging.getLogger(__name__)
|
|
|
12
12
|
|
|
13
13
|
def run(args: Namespace) -> int:
|
|
14
14
|
if not whitelist_file_path.exists():
|
|
15
|
-
logger.info(
|
|
15
|
+
logger.info(
|
|
16
|
+
f"Whitelist file '{whitelist_file_path.relative_to(current_dir)}' does not exist, creating new one"
|
|
17
|
+
)
|
|
16
18
|
whitelist_file_path.write_text("[]")
|
|
17
19
|
|
|
18
20
|
player_ids: list[str] = args.players
|
|
@@ -11,7 +11,9 @@ logger = logging.getLogger(__name__)
|
|
|
11
11
|
|
|
12
12
|
def run(args: Namespace) -> int:
|
|
13
13
|
if not whitelist_file_path.exists():
|
|
14
|
-
logger.error(
|
|
14
|
+
logger.error(
|
|
15
|
+
f"Whitelist file '{whitelist_file_path.relative_to(current_dir)}' does not exist"
|
|
16
|
+
)
|
|
15
17
|
return 1
|
|
16
18
|
|
|
17
19
|
whitelisted_players = whitelist.list_players()
|
|
@@ -12,7 +12,9 @@ logger = logging.getLogger(__name__)
|
|
|
12
12
|
|
|
13
13
|
def run(args: Namespace) -> int:
|
|
14
14
|
if not whitelist_file_path.exists():
|
|
15
|
-
logger.error(
|
|
15
|
+
logger.error(
|
|
16
|
+
f"Whitelist file '{whitelist_file_path.relative_to(current_dir)}' does not exist"
|
|
17
|
+
)
|
|
16
18
|
return 1
|
|
17
19
|
|
|
18
20
|
player_ids: list[str] = args.players
|
|
@@ -1,8 +1,14 @@
|
|
|
1
|
-
from .get_project_informations import
|
|
2
|
-
|
|
3
|
-
|
|
1
|
+
from .get_project_informations import (
|
|
2
|
+
GetProjectInformationsError,
|
|
3
|
+
get_project_informations,
|
|
4
|
+
)
|
|
5
|
+
from .get_project_versions import GetProjectVersionsError, get_project_versions
|
|
6
|
+
from .search_projects import SearchProjectsError, search_projects
|
|
4
7
|
|
|
5
8
|
__all__ = [
|
|
9
|
+
"GetProjectInformationsError",
|
|
10
|
+
"GetProjectVersionsError",
|
|
11
|
+
"SearchProjectsError",
|
|
6
12
|
"get_project_informations",
|
|
7
13
|
"get_project_versions",
|
|
8
14
|
"search_projects",
|
|
@@ -42,12 +42,16 @@ def get_project_informations(project_ids: list[str] | str) -> list[ProjectInform
|
|
|
42
42
|
response = networking.request(
|
|
43
43
|
f"{constants.modrinth_api_url}/v2/projects", query_parameters
|
|
44
44
|
)
|
|
45
|
+
response_json = response["json"]
|
|
45
46
|
|
|
46
|
-
if
|
|
47
|
-
raise GetProjectInformationsError("
|
|
47
|
+
if response_json is None:
|
|
48
|
+
raise GetProjectInformationsError("Response is not a JSON")
|
|
49
|
+
|
|
50
|
+
if not isinstance(response_json, list):
|
|
51
|
+
raise GetProjectInformationsError("Response JSON is not an array")
|
|
48
52
|
|
|
49
53
|
project_informations: list[ProjectInformation] = []
|
|
50
|
-
for information in
|
|
54
|
+
for information in response_json:
|
|
51
55
|
# Checks
|
|
52
56
|
project_status: ProjectStatus = information["status"]
|
|
53
57
|
if project_status not in shared.PROJECT_STATUS:
|
|
@@ -58,13 +58,18 @@ def get_project_versions(
|
|
|
58
58
|
response = networking.request(
|
|
59
59
|
f"{constants.modrinth_api_url}/v2/project/{project_id}/version",
|
|
60
60
|
query=query_parameters,
|
|
61
|
+
expect_json=True,
|
|
61
62
|
)
|
|
63
|
+
response_json = response["json"]
|
|
62
64
|
|
|
63
|
-
if
|
|
64
|
-
raise GetProjectVersionsError("
|
|
65
|
+
if response_json is None:
|
|
66
|
+
raise GetProjectVersionsError("Response is not a JSON")
|
|
67
|
+
|
|
68
|
+
if not isinstance(response_json, list):
|
|
69
|
+
raise GetProjectVersionsError("Response JSON is not an array")
|
|
65
70
|
|
|
66
71
|
project_versions: list[ProjectVersion] = []
|
|
67
|
-
for version in
|
|
72
|
+
for version in response_json:
|
|
68
73
|
dependencies: list[Dependency] = []
|
|
69
74
|
for dependency in version.get("dependencies", []):
|
|
70
75
|
version_dependency: Dependency = {
|
|
@@ -64,16 +64,16 @@ def search_projects(
|
|
|
64
64
|
query_parameters["query"] = search_query
|
|
65
65
|
|
|
66
66
|
response = networking.request(
|
|
67
|
-
f"{modrinth_api_url}/v2/search", query=query_parameters
|
|
67
|
+
f"{modrinth_api_url}/v2/search", query=query_parameters, expect_json=True
|
|
68
68
|
)
|
|
69
|
+
response_json = response["json"]
|
|
69
70
|
|
|
70
71
|
# Mostly just to make pyright happy
|
|
71
|
-
if
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
raise SearchProjectsError("Response is not JSON")
|
|
72
|
+
if response_json is None:
|
|
73
|
+
raise SearchProjectsError("Response is not a JSON")
|
|
74
|
+
|
|
75
|
+
if not isinstance(response_json, dict):
|
|
76
|
+
raise SearchProjectsError("Response JSON is not an object")
|
|
77
77
|
|
|
78
78
|
search_hits: list[SearchHit] = []
|
|
79
79
|
for hit in response_json["hits"]:
|
mcserver/modrinth/paths.py
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import json
|
|
2
|
-
from typing import
|
|
2
|
+
from typing import TypedDict
|
|
3
3
|
|
|
4
4
|
from ..shared import update_file
|
|
5
5
|
from .paths import modrinth_dir
|
|
@@ -13,9 +13,14 @@ class ProjectRecordFormatVersionError(Exception):
|
|
|
13
13
|
pass
|
|
14
14
|
|
|
15
15
|
|
|
16
|
+
class Dependency(TypedDict):
|
|
17
|
+
project_id: str
|
|
18
|
+
dependency_type: DependencyType
|
|
19
|
+
|
|
20
|
+
|
|
16
21
|
class ProjectRecordPayload(TypedDict):
|
|
17
22
|
# Project
|
|
18
|
-
project_name: str
|
|
23
|
+
project_name: str | None
|
|
19
24
|
project_slug: str | None
|
|
20
25
|
|
|
21
26
|
# Version
|
|
@@ -24,15 +29,15 @@ class ProjectRecordPayload(TypedDict):
|
|
|
24
29
|
file: File | None
|
|
25
30
|
|
|
26
31
|
# Metadata
|
|
27
|
-
added_time: str | None
|
|
28
|
-
discovered_time: str
|
|
29
|
-
updated_time: str | None
|
|
32
|
+
added_time: str | None # probably ISO-8601
|
|
33
|
+
discovered_time: str # probably ISO-8601
|
|
34
|
+
updated_time: str | None # probably ISO-8601
|
|
30
35
|
|
|
31
36
|
# Relationships
|
|
32
37
|
is_manual: bool
|
|
33
38
|
highest_type: DependencyType | None
|
|
34
|
-
dependencies:
|
|
35
|
-
dependents:
|
|
39
|
+
dependencies: list[Dependency]
|
|
40
|
+
dependents: list[Dependency]
|
|
36
41
|
|
|
37
42
|
|
|
38
43
|
class ProjectRecordData(ProjectRecordPayload):
|