mcserver-cli 4.5.2__py3-none-any.whl → 4.6.2__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/cli.py +22 -22
- mcserver/commands/add_projects.py +56 -581
- mcserver/commands/start_server.py +14 -13
- mcserver/modrinth/slug_index.py +13 -5
- mcserver/networking.py +31 -13
- {mcserver_cli-4.5.2.dist-info → mcserver_cli-4.6.2.dist-info}/METADATA +1 -1
- {mcserver_cli-4.5.2.dist-info → mcserver_cli-4.6.2.dist-info}/RECORD +11 -11
- {mcserver_cli-4.5.2.dist-info → mcserver_cli-4.6.2.dist-info}/WHEEL +0 -0
- {mcserver_cli-4.5.2.dist-info → mcserver_cli-4.6.2.dist-info}/entry_points.txt +0 -0
- {mcserver_cli-4.5.2.dist-info → mcserver_cli-4.6.2.dist-info}/licenses/LICENSE +0 -0
mcserver/__init__.py
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
__version__ = "4.
|
|
1
|
+
__version__ = "4.6.2"
|
mcserver/cli.py
CHANGED
|
@@ -116,8 +116,8 @@ def main() -> int:
|
|
|
116
116
|
# Parser Setup
|
|
117
117
|
parser = argparse.ArgumentParser(
|
|
118
118
|
prog="mcserver",
|
|
119
|
-
description="A CLI tool for managing Minecraft: Java Edition servers
|
|
120
|
-
epilog="Created for Linux and Termux only
|
|
119
|
+
description="A CLI tool for managing Minecraft: Java Edition servers",
|
|
120
|
+
epilog="Created for Linux and Termux only",
|
|
121
121
|
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
|
|
122
122
|
prefix_chars="-",
|
|
123
123
|
add_help=True,
|
|
@@ -140,20 +140,20 @@ def main() -> int:
|
|
|
140
140
|
commands = parser.add_subparsers(title="Commands")
|
|
141
141
|
|
|
142
142
|
# 'add' command
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
143
|
+
add_command = commands.add_parser(
|
|
144
|
+
"add",
|
|
145
|
+
help="Add mods or plugins",
|
|
146
|
+
description="Add mods or plugins from Modrinth",
|
|
147
|
+
)
|
|
148
148
|
|
|
149
|
-
|
|
150
|
-
|
|
149
|
+
add_command.set_defaults(command_name="add")
|
|
150
|
+
add_command.add_argument("projects", nargs="+", type=str, help="Project names")
|
|
151
151
|
|
|
152
152
|
# 'init' command
|
|
153
153
|
init_command = commands.add_parser(
|
|
154
154
|
"init",
|
|
155
155
|
help="Initialize server configurations",
|
|
156
|
-
description="Initialize the server configurations
|
|
156
|
+
description="Initialize the server configurations",
|
|
157
157
|
)
|
|
158
158
|
|
|
159
159
|
init_command.set_defaults(command_name="init")
|
|
@@ -220,7 +220,7 @@ def main() -> int:
|
|
|
220
220
|
|
|
221
221
|
# 'op' command
|
|
222
222
|
op_command = commands.add_parser(
|
|
223
|
-
"op", help="Manage operator players", description="Manage the operator status
|
|
223
|
+
"op", help="Manage operator players", description="Manage the operator status"
|
|
224
224
|
)
|
|
225
225
|
|
|
226
226
|
op_command.set_defaults(parser=op_command)
|
|
@@ -229,8 +229,8 @@ def main() -> int:
|
|
|
229
229
|
# 'op grant'
|
|
230
230
|
op_grant_command = op_subcommands.add_parser(
|
|
231
231
|
"grant",
|
|
232
|
-
help="Grant players operator permission
|
|
233
|
-
description="Grant players operator permission
|
|
232
|
+
help="Grant players operator permission",
|
|
233
|
+
description="Grant players operator permission",
|
|
234
234
|
)
|
|
235
235
|
|
|
236
236
|
op_grant_command.set_defaults(command_name="op_grant")
|
|
@@ -262,7 +262,7 @@ def main() -> int:
|
|
|
262
262
|
|
|
263
263
|
# 'op list'
|
|
264
264
|
op_list_command = op_subcommands.add_parser(
|
|
265
|
-
"list", help="List operator players", description="List all operator players
|
|
265
|
+
"list", help="List operator players", description="List all operator players"
|
|
266
266
|
)
|
|
267
267
|
|
|
268
268
|
op_list_command.set_defaults(command_name="op_list")
|
|
@@ -271,7 +271,7 @@ def main() -> int:
|
|
|
271
271
|
op_revoke_command = op_subcommands.add_parser(
|
|
272
272
|
"revoke",
|
|
273
273
|
help="Revoke operator players permission",
|
|
274
|
-
description="Revoke operator players permission
|
|
274
|
+
description="Revoke operator players permission",
|
|
275
275
|
)
|
|
276
276
|
|
|
277
277
|
op_revoke_command.set_defaults(command_name="op_revoke")
|
|
@@ -283,7 +283,7 @@ def main() -> int:
|
|
|
283
283
|
search_command = commands.add_parser(
|
|
284
284
|
"search",
|
|
285
285
|
help="Search Modrinth projects",
|
|
286
|
-
description="Search projects from Modrinth
|
|
286
|
+
description="Search projects from Modrinth",
|
|
287
287
|
)
|
|
288
288
|
|
|
289
289
|
search_command.set_defaults(command_name="search")
|
|
@@ -343,7 +343,7 @@ def main() -> int:
|
|
|
343
343
|
show_command = commands.add_parser(
|
|
344
344
|
"show",
|
|
345
345
|
help="Show Modrinth project information",
|
|
346
|
-
description="Show information about Modrinth projects
|
|
346
|
+
description="Show information about Modrinth projects",
|
|
347
347
|
)
|
|
348
348
|
|
|
349
349
|
show_command.set_defaults(command_name="show")
|
|
@@ -353,7 +353,7 @@ def main() -> int:
|
|
|
353
353
|
|
|
354
354
|
# 'start' command
|
|
355
355
|
start_command = commands.add_parser(
|
|
356
|
-
"start", help="Start the server", description="Install and start the server
|
|
356
|
+
"start", help="Start the server", description="Install and start the server"
|
|
357
357
|
)
|
|
358
358
|
|
|
359
359
|
start_command.set_defaults(command_name="start")
|
|
@@ -371,7 +371,7 @@ def main() -> int:
|
|
|
371
371
|
whitelist_command = commands.add_parser(
|
|
372
372
|
"whitelist",
|
|
373
373
|
help="Manage whitelisted players",
|
|
374
|
-
description="Manage the player whitelist
|
|
374
|
+
description="Manage the player whitelist",
|
|
375
375
|
)
|
|
376
376
|
|
|
377
377
|
whitelist_command.set_defaults(parser=whitelist_command)
|
|
@@ -381,7 +381,7 @@ def main() -> int:
|
|
|
381
381
|
whitelist_add_command = whitelist_subcommands.add_parser(
|
|
382
382
|
"add",
|
|
383
383
|
help="Add players to the whitelist",
|
|
384
|
-
description="Add players to the whitelist
|
|
384
|
+
description="Add players to the whitelist",
|
|
385
385
|
)
|
|
386
386
|
|
|
387
387
|
whitelist_add_command.set_defaults(command_name="whitelist_add")
|
|
@@ -401,7 +401,7 @@ def main() -> int:
|
|
|
401
401
|
whitelist_list_command = whitelist_subcommands.add_parser(
|
|
402
402
|
"list",
|
|
403
403
|
help="List whitelisted players",
|
|
404
|
-
description="List all whitelisted players
|
|
404
|
+
description="List all whitelisted players",
|
|
405
405
|
)
|
|
406
406
|
|
|
407
407
|
whitelist_list_command.set_defaults(command_name="whitelist_list")
|
|
@@ -410,7 +410,7 @@ def main() -> int:
|
|
|
410
410
|
whitelist_remove_command = whitelist_subcommands.add_parser(
|
|
411
411
|
"remove",
|
|
412
412
|
help="Remove players from the whitelist",
|
|
413
|
-
description="Remove players from the whitelist
|
|
413
|
+
description="Remove players from the whitelist",
|
|
414
414
|
)
|
|
415
415
|
|
|
416
416
|
whitelist_remove_command.set_defaults(command_name="whitelist_remove")
|
|
@@ -1,44 +1,20 @@
|
|
|
1
|
-
import copy
|
|
2
|
-
import datetime
|
|
3
1
|
import json
|
|
4
2
|
import logging
|
|
5
3
|
from argparse import Namespace
|
|
6
|
-
from datetime import UTC, datetime, timedelta
|
|
7
|
-
from pathlib import Path
|
|
8
|
-
from typing import TypedDict
|
|
9
4
|
|
|
10
5
|
from .. import config, networking, paths, resolver, shared
|
|
11
6
|
from ..modrinth import apis as modrinth_api
|
|
12
|
-
from ..modrinth import
|
|
13
|
-
from ..modrinth.project_records import ProjectRecordPayload
|
|
7
|
+
from ..modrinth import slug_index
|
|
14
8
|
from ..modrinth.typings import (
|
|
15
9
|
Dependency,
|
|
16
10
|
DependencyType,
|
|
17
11
|
ProjectInformation,
|
|
18
12
|
ProjectVersion,
|
|
19
13
|
)
|
|
20
|
-
from ..resolver import
|
|
14
|
+
from ..resolver import ProjectData
|
|
21
15
|
|
|
22
16
|
logger = logging.getLogger(__name__)
|
|
23
17
|
|
|
24
|
-
|
|
25
|
-
class GetDependenciesError(Exception):
|
|
26
|
-
pass
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
class ResolverTranslationError(Exception):
|
|
30
|
-
pass
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
class ProjectData(TypedDict):
|
|
34
|
-
project_id: str
|
|
35
|
-
is_manual: bool
|
|
36
|
-
highest_type: DependencyType | None
|
|
37
|
-
"""Not present if the project is manual and has not dependents"""
|
|
38
|
-
dependencies: list[Dependency]
|
|
39
|
-
dependents: list[Dependency]
|
|
40
|
-
|
|
41
|
-
|
|
42
18
|
dependency_types: dict[DependencyType, int] = {
|
|
43
19
|
"embedded": 0,
|
|
44
20
|
"optional": 1,
|
|
@@ -46,6 +22,10 @@ dependency_types: dict[DependencyType, int] = {
|
|
|
46
22
|
"incompatible": 3,
|
|
47
23
|
}
|
|
48
24
|
|
|
25
|
+
class GetVersionError(Exception): pass
|
|
26
|
+
class GetDependenciesError(Exception): pass
|
|
27
|
+
class ResolverTranslationError(Exception):
|
|
28
|
+
pass
|
|
49
29
|
|
|
50
30
|
def human_to_resolver(dependencies: list[Dependency]) -> dict[str, int]:
|
|
51
31
|
resolver_dependencies: dict[str, int] = {}
|
|
@@ -68,58 +48,14 @@ def human_to_resolver(dependencies: list[Dependency]) -> dict[str, int]:
|
|
|
68
48
|
return resolver_dependencies
|
|
69
49
|
|
|
70
50
|
|
|
71
|
-
def resolver_to_human(dependency_graph: dict[str, Project]) -> list[ProjectData]:
|
|
72
|
-
projects: list[ProjectData] = []
|
|
73
|
-
for project_id, project in dependency_graph.items():
|
|
74
|
-
dependencies: list[Dependency] = []
|
|
75
|
-
for dependency_id, dependency_type in project["dependencies"].items():
|
|
76
|
-
dependency: Dependency = {
|
|
77
|
-
"project_id": dependency_id,
|
|
78
|
-
"dependency_type": resolver.dependency_types2[dependency_type],
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
dependencies.append(dependency)
|
|
82
|
-
|
|
83
|
-
dependents: list[Dependency] = []
|
|
84
|
-
for dependency_id, dependency_type in project["dependents"].items():
|
|
85
|
-
dependent: Dependency = {
|
|
86
|
-
"project_id": dependency_id,
|
|
87
|
-
"dependency_type": resolver.dependency_types2[dependency_type],
|
|
88
|
-
}
|
|
89
|
-
|
|
90
|
-
dependents.append(dependent)
|
|
91
|
-
|
|
92
|
-
project_data: ProjectData = {
|
|
93
|
-
"project_id": project_id,
|
|
94
|
-
"is_manual": project["is_manual"],
|
|
95
|
-
"highest_type": None,
|
|
96
|
-
"dependencies": dependencies,
|
|
97
|
-
"dependents": dependents,
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
if project["highest_type"] is not None:
|
|
101
|
-
project_data["highest_type"] = resolver.dependency_types2[project["highest_type"]]
|
|
102
|
-
|
|
103
|
-
projects.append(project_data)
|
|
104
|
-
|
|
105
|
-
return projects
|
|
106
|
-
|
|
107
|
-
|
|
108
51
|
def run(args: Namespace) -> int:
|
|
109
|
-
# argparse's args
|
|
110
52
|
projects: list[str] = args.projects
|
|
111
53
|
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
if not server_config_file_path.exists():
|
|
115
|
-
logger.error(
|
|
116
|
-
f"Configuration file '{server_config_file_path}' does not exist, is MCServer initialized yet?"
|
|
117
|
-
)
|
|
54
|
+
if not (paths.configs_dir / "server.json").exists():
|
|
55
|
+
logger.error("Configuration file for server does not exist, is server initialized?")
|
|
118
56
|
return 1
|
|
119
57
|
|
|
120
|
-
server_config = config.read_config(
|
|
121
|
-
"server", shared.default_configs["server"]["format_version"]
|
|
122
|
-
)
|
|
58
|
+
server_config = config.read_config("server", shared.default_configs["server"]["format_version"])
|
|
123
59
|
game_version: str = server_config["game_version"]
|
|
124
60
|
loader_name: str = server_config["loader"]["name"]
|
|
125
61
|
|
|
@@ -128,46 +64,27 @@ def run(args: Namespace) -> int:
|
|
|
128
64
|
logger.error(f"{loader_name.capitalize()} does not support mods")
|
|
129
65
|
return 1
|
|
130
66
|
|
|
67
|
+
project_label, project_directory = shared.get_loader_context(loader_name)
|
|
68
|
+
|
|
131
69
|
# mod vs project labeling
|
|
132
70
|
project_label, project_directory = shared.get_loader_context(loader_name)
|
|
133
71
|
if project_directory is None:
|
|
134
72
|
logger.error("Wait 'project_directory' it can't be None! it just to satisfy pyright")
|
|
135
73
|
return 1
|
|
136
74
|
|
|
137
|
-
# initial project normalizer (slug -> id) + cache
|
|
138
75
|
project_ids: list[str] = []
|
|
139
76
|
project_versions: dict[str, ProjectVersion] = {}
|
|
140
77
|
for project in projects:
|
|
141
|
-
|
|
142
|
-
if project_records.record_exists(project_id):
|
|
143
|
-
project_ids.append(project_id)
|
|
144
|
-
logger.debug(f"Skipping fecthing for {project_id}, record already exist")
|
|
145
|
-
continue
|
|
146
|
-
|
|
147
|
-
versions = modrinth_api.get_project_versions(
|
|
148
|
-
project, loader_name, game_version, include_changelog=False
|
|
149
|
-
)
|
|
150
|
-
|
|
78
|
+
versions = modrinth_api.get_project_versions(project, loader_name, game_version, include_changelog=False)
|
|
151
79
|
if len(versions) == 0:
|
|
152
|
-
raise
|
|
153
|
-
f"Project has no version for '{loader_name.capitalize()}' '{game_version}'"
|
|
154
|
-
)
|
|
155
|
-
|
|
156
|
-
version = versions[0]
|
|
157
|
-
project_id = version["project_id"]
|
|
158
|
-
if project != project_id:
|
|
159
|
-
logger.debug("project and project_id is diffrent, adding it to the slug index")
|
|
160
|
-
slug_index.update_slug_index(project, project_id)
|
|
80
|
+
raise GetVersionError(f"{project} has no version for {loader_name.capitalize()} {game_version}")
|
|
161
81
|
|
|
162
|
-
|
|
163
|
-
|
|
82
|
+
project_version = versions[0]
|
|
83
|
+
project_id = project_version["project_id"]
|
|
84
|
+
project_versions[project_id] = project_version
|
|
164
85
|
project_ids.append(project_id)
|
|
165
86
|
|
|
166
|
-
|
|
167
|
-
slug_index.save_slug_index()
|
|
168
|
-
|
|
169
|
-
# get dependencies from Modrinth version
|
|
170
|
-
def get_version_dependencies(project_id: str) -> list[Dependency]:
|
|
87
|
+
def get_project_dependencies(project_id: str) -> list[Dependency]:
|
|
171
88
|
versions = modrinth_api.get_project_versions(
|
|
172
89
|
project_id, loader_name, game_version, include_changelog=False
|
|
173
90
|
)
|
|
@@ -187,44 +104,34 @@ def run(args: Namespace) -> int:
|
|
|
187
104
|
|
|
188
105
|
return version_dependencies
|
|
189
106
|
|
|
190
|
-
|
|
191
|
-
loaded_project_records: dict[str, ProjectRecordPayload] = {}
|
|
192
|
-
def get_dependencies(project_id: str) -> dict[str, int]:
|
|
107
|
+
def get_dependencies(project_id) -> dict[str, int]:
|
|
193
108
|
dependencies: list[Dependency] | None = None
|
|
194
|
-
if project_records.record_exists(project_id):
|
|
195
|
-
project_record = project_records.read_record(project_id)
|
|
196
|
-
loaded_project_records[project_id] = project_record
|
|
197
|
-
return project_record["dependencies"]
|
|
198
|
-
|
|
199
109
|
if project_id in project_versions:
|
|
200
110
|
project_version = project_versions[project_id]
|
|
201
111
|
if "dependencies" in project_version:
|
|
202
112
|
dependencies = project_version["dependencies"]
|
|
203
113
|
else:
|
|
204
|
-
dependencies =
|
|
114
|
+
dependencies = get_project_dependencies(project_id)
|
|
205
115
|
|
|
206
116
|
if dependencies is None:
|
|
207
117
|
raise GetDependenciesError(f"No dependency provider available for {project_id}")
|
|
208
118
|
|
|
209
119
|
return human_to_resolver(dependencies)
|
|
210
120
|
|
|
211
|
-
# resolve dependencies
|
|
212
|
-
resolved_projects = resolver_to_human(resolver.resolve_dependencies(project_ids, get_dependencies, resolver.required_only))
|
|
213
|
-
resolved_data: dict = {}
|
|
214
|
-
for project in resolved_projects:
|
|
215
|
-
project = copy.deepcopy(project)
|
|
216
|
-
project_id = str(project.pop("project_id"))
|
|
217
|
-
resolved_data[project_id] = project
|
|
218
121
|
|
|
219
|
-
|
|
122
|
+
resolved_projects: list[ProjectData] = resolver.resolver_to_human(resolver.resolve_dependencies(project_ids, get_dependencies, resolver.required_only))
|
|
123
|
+
|
|
124
|
+
print(json.dumps(resolved_projects, indent=2))
|
|
125
|
+
|
|
220
126
|
all_project_ids: set[str] = set()
|
|
221
|
-
required_dependencies: set[str] = set()
|
|
222
127
|
incompatible_dependencies: set[str] = set()
|
|
128
|
+
required_dependencies: set[str] = set()
|
|
223
129
|
|
|
224
130
|
optional_projects: set[str] = set()
|
|
225
131
|
required_projects: set[str] = set()
|
|
226
132
|
incompatible_projects: set[str] = set()
|
|
227
133
|
|
|
134
|
+
# Putting projects and dependencies into its bucket
|
|
228
135
|
for project in resolved_projects:
|
|
229
136
|
project_id = project["project_id"]
|
|
230
137
|
all_project_ids.add(project_id)
|
|
@@ -256,37 +163,17 @@ def run(args: Namespace) -> int:
|
|
|
256
163
|
case "incompatible":
|
|
257
164
|
incompatible_projects.add(project_id)
|
|
258
165
|
|
|
259
|
-
#
|
|
260
|
-
print(f"""all_project_ids: {all_project_ids}
|
|
261
|
-
required_dependencies: {required_dependencies}
|
|
262
|
-
incompatible_dependencies: {incompatible_dependencies}
|
|
263
|
-
|
|
264
|
-
optional_projects: {optional_projects}
|
|
265
|
-
required_projects: {required_projects}
|
|
266
|
-
incompatible_projects: {incompatible_projects}""")
|
|
267
|
-
|
|
268
|
-
# conflict detection
|
|
166
|
+
# Conflict detection
|
|
269
167
|
conflicting_projects = required_dependencies & incompatible_dependencies
|
|
270
168
|
if conflicting_projects:
|
|
271
169
|
logger.error(f"Found conflicting dependencies: {', '.join(conflicting_projects)}")
|
|
272
170
|
|
|
273
171
|
# fetch additional info
|
|
274
172
|
project_informations: dict[str, ProjectInformation] = {}
|
|
275
|
-
#for project in json.loads(Path("a.json").read_text()):
|
|
276
173
|
for project in modrinth_api.get_project_informations(list(all_project_ids)):
|
|
277
|
-
|
|
278
|
-
project_informations[project_id] = project
|
|
279
|
-
|
|
280
|
-
for project_information in project_informations.values():
|
|
281
|
-
project_slug = project_information.get("project_slug")
|
|
282
|
-
if project_slug is None:
|
|
283
|
-
continue
|
|
284
|
-
|
|
285
|
-
slug_index.update_slug_index(project_slug, project_information["project_id"])
|
|
174
|
+
project_informations[project["project_id"]] = project
|
|
286
175
|
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
#info display
|
|
176
|
+
# Display information
|
|
290
177
|
required_projects_count = len(required_projects)
|
|
291
178
|
logger.info(f"{shared.pluralize(project_label, required_projects_count).capitalize()} that {shared.pluralize('is', required_projects_count)} going to be downloaded:")
|
|
292
179
|
required_project_display: list[str] = []
|
|
@@ -306,7 +193,7 @@ incompatible_projects: {incompatible_projects}""")
|
|
|
306
193
|
optional_project_display.sort()
|
|
307
194
|
print(", ".join(optional_project_display))
|
|
308
195
|
|
|
309
|
-
incompatible_projects_count = len(
|
|
196
|
+
incompatible_projects_count = len(incompatible_projects)
|
|
310
197
|
if incompatible_projects:
|
|
311
198
|
logger.info(f"{shared.pluralize(project_label, incompatible_projects_count).capitalize()} that {shared.pluralize('is', incompatible_projects_count)} incompatible:")
|
|
312
199
|
incompatible_project_display: list[str] = []
|
|
@@ -316,451 +203,39 @@ incompatible_projects: {incompatible_projects}""")
|
|
|
316
203
|
incompatible_project_display.sort()
|
|
317
204
|
print(", ".join(incompatible_project_display))
|
|
318
205
|
|
|
319
|
-
#
|
|
206
|
+
# Confirmation prompt
|
|
320
207
|
confirmation_answer = shared.confirmation_prompt("Do you want to continue?", default_option=True)
|
|
321
208
|
|
|
322
209
|
if not confirmation_answer:
|
|
323
210
|
print("Cancelled")
|
|
324
211
|
return 1
|
|
325
212
|
|
|
326
|
-
|
|
327
|
-
|
|
328
213
|
for project_id in required_projects:
|
|
329
|
-
project_data = resolved_data[project_id]
|
|
330
214
|
project_information = project_informations[project_id]
|
|
331
|
-
project_version = project_versions
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
"updated_time": None,
|
|
356
|
-
"is_manual": project_data["is_manual"],
|
|
357
|
-
"highest_type": project_data["highest_type"],
|
|
358
|
-
"dependencies": human_to_resolver(project_data["dependencies"]),
|
|
359
|
-
"dependents": human_to_resolver(project_data["dependents"])
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
# logger.info(f"Downloading {project_information['project_name']}...")
|
|
363
|
-
# project_directory.mkdir(exist_ok=True, parents=True)
|
|
364
|
-
# networking.download(primary_file['download_url'], project_directory / primary_file["file_name"])
|
|
365
|
-
# project_records.write_record(project_id, record_payload)
|
|
366
|
-
elif project_record is not None:
|
|
367
|
-
record_payload = copy.deepcopy(project_record)
|
|
368
|
-
record_payload["dependencies"].update(project_data["dependencies"])
|
|
369
|
-
record_payload["dependents"].update(project_data["dependents"])
|
|
370
|
-
record_payload.update({
|
|
371
|
-
"updated_time": datetime.now(tz=UTC).isoformat(),
|
|
372
|
-
"is_manual": project_record["is_manual"] or project_data["is_manual"],
|
|
373
|
-
})
|
|
374
|
-
|
|
375
|
-
primary_file = record_payload["file"]
|
|
376
|
-
|
|
377
|
-
logger.info(f"Downloading {project_information['project_name']}...")
|
|
378
|
-
if primary_file is None:
|
|
379
|
-
logger.error("Screw you")
|
|
380
|
-
continue
|
|
215
|
+
project_version = project_versions[project_id]
|
|
216
|
+
version_files = project_version["files"]
|
|
217
|
+
|
|
218
|
+
primary_file = None
|
|
219
|
+
for file in version_files:
|
|
220
|
+
if file["is_primary"]:
|
|
221
|
+
primary_file = file
|
|
222
|
+
break
|
|
223
|
+
|
|
224
|
+
if primary_file is None:
|
|
225
|
+
primary_file = version_files[0]
|
|
226
|
+
|
|
227
|
+
logger.info(f"Downloading {project_information['project_name']}...")
|
|
228
|
+
project_directory.mkdir(exist_ok=True, parents=True)
|
|
229
|
+
networking.download(primary_file['download_url'], project_directory / primary_file["file_name"])
|
|
230
|
+
|
|
231
|
+
for project_information in project_informations.values():
|
|
232
|
+
project_slug = project_information.get("project_slug")
|
|
233
|
+
if project_slug is None:
|
|
234
|
+
continue
|
|
235
|
+
|
|
236
|
+
slug_index.update_slug_index(project_slug, project_information["project_id"])
|
|
237
|
+
|
|
238
|
+
slug_index.save_slug_index()
|
|
381
239
|
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
|
|
391
|
-
|
|
392
|
-
|
|
393
|
-
|
|
394
|
-
# # download required mods
|
|
395
|
-
# for project_id in required_projects:
|
|
396
|
-
# project_version = project_versions.get(project_id)
|
|
397
|
-
# project_information = project_informations[project_id]
|
|
398
|
-
# project_data = resolved_data[project_id]
|
|
399
|
-
# project_record = loaded_project_records.get(project_id)
|
|
400
|
-
|
|
401
|
-
# if project_record is not None:
|
|
402
|
-
# record_payload = copy.deepcopy(project_record)
|
|
403
|
-
# record_payload["dependencies"].update(project_data["dependencies"])
|
|
404
|
-
# record_payload["dependents"].update(project_data["dependents"])
|
|
405
|
-
# record_payload.update({
|
|
406
|
-
# "updated_time": datetime.now(tz=UTC).isoformat(),
|
|
407
|
-
# "is_manual": project_record["is_manual"] or project_data["is_manual"],
|
|
408
|
-
# })
|
|
409
|
-
# elif project_version:
|
|
410
|
-
# project_records.write_record(project_id, record_payload)
|
|
411
|
-
|
|
412
|
-
# for project_id in all_project_ids:
|
|
413
|
-
# if
|
|
414
|
-
# project_records.write_record(project_id, record_payload)
|
|
415
|
-
|
|
416
|
-
# project_data = resolved_data[project_id]
|
|
417
|
-
# project_information = project_informations[project_id]
|
|
418
|
-
# project_record = loaded_project_records.get(project_id)
|
|
419
|
-
# project_version = project_versions.get(project_id)
|
|
420
|
-
|
|
421
|
-
# record_payload: ProjectRecordPayload = {
|
|
422
|
-
# "project_name": project_information["project_name"],
|
|
423
|
-
# "project_slug": project_information.get("project_slug"),
|
|
424
|
-
# "version_id": None,
|
|
425
|
-
# "version_environment": None,
|
|
426
|
-
# "file": None,
|
|
427
|
-
# "added_time": None,
|
|
428
|
-
# "discovered_time": datetime.now(tz=UTC).isoformat(),
|
|
429
|
-
# "updated_time": None,
|
|
430
|
-
# "is_manual": project_data["is_manual"],
|
|
431
|
-
# "highest_type": project_data["highest_type"],
|
|
432
|
-
# "dependencies": human_to_resolver(project_data["dependencies"]),
|
|
433
|
-
# "dependents": human_to_resolver(project_data["dependents"]),
|
|
434
|
-
# }
|
|
435
|
-
|
|
436
|
-
# if project_id in required_projects:
|
|
437
|
-
# record_payload["added_time"] = datetime.now(tz=UTC).isoformat()
|
|
438
|
-
|
|
439
|
-
# if project_version is not None:
|
|
440
|
-
# version_files = project_version["files"]
|
|
441
|
-
|
|
442
|
-
# primary_file = None
|
|
443
|
-
# for file in version_files:
|
|
444
|
-
# if file["is_primary"]:
|
|
445
|
-
# primary_file = file
|
|
446
|
-
# break
|
|
447
|
-
|
|
448
|
-
# if primary_file is None:
|
|
449
|
-
# primary_file = version_files[0]
|
|
450
|
-
|
|
451
|
-
# record_payload.update({
|
|
452
|
-
# "version_id": project_version["version_id"],
|
|
453
|
-
# "version_environment": project_version["environment"],
|
|
454
|
-
# "file": primary_file
|
|
455
|
-
# })
|
|
456
|
-
|
|
457
|
-
# if project_record is not None:
|
|
458
|
-
# record_payload["dependencies"].update(project_record["dependencies"])
|
|
459
|
-
# record_payload["dependents"].update(project_record["dependents"])
|
|
460
|
-
# record_payload.update({
|
|
461
|
-
# "added_time": project_record["added_time"],
|
|
462
|
-
# "updated_time": datetime.now(tz=UTC).isoformat()
|
|
463
|
-
# })
|
|
464
|
-
|
|
465
|
-
# project_records.write_record(project_id, record_payload)
|
|
466
|
-
|
|
467
|
-
# record_payload: ProjectRecordPayload = {
|
|
468
|
-
# "project_name": project_info["project_name"],
|
|
469
|
-
# "project_slug": project_info["project_slug"],
|
|
470
|
-
# "version_id": project_version["version_id"],
|
|
471
|
-
# "version_environment": project_version["environment"],
|
|
472
|
-
# "added_time": datetime.now(tz=UTC).isoformat(),
|
|
473
|
-
# "updated_time": None,
|
|
474
|
-
# "file": primary_file,
|
|
475
|
-
# "is_manual": project_data["is_manual"],
|
|
476
|
-
# "highest_type": project_data["highest_type"],
|
|
477
|
-
# "dependencies": project_data["dependencies"],
|
|
478
|
-
# "dependents": project_data["dependents"]
|
|
479
|
-
# }
|
|
480
|
-
|
|
481
|
-
# loaded_project_record = loaded_project_records.get(project_id, {})
|
|
482
|
-
# project_records.write_record(project_id, record_payload)
|
|
483
|
-
|
|
484
|
-
# for project_id in optional_projects:
|
|
485
|
-
# project_data = resolved_data[project_id]
|
|
486
|
-
# project_info = project_information[project_id]
|
|
487
|
-
# loaded_project_record = loaded_project_records.get(project_id)
|
|
488
|
-
# record_payload: ProjectRecordPayload = {
|
|
489
|
-
# "project_name": project_info["project_name"],
|
|
490
|
-
# "project_slug": project_info["project_slug"],
|
|
491
|
-
# "added_time": None,
|
|
492
|
-
# "updated_time": None,
|
|
493
|
-
# "is_manual": project_data["is_manual"],
|
|
494
|
-
# "highest_type": project_data["highest_type"],
|
|
495
|
-
# "dependencies": project_data["dependencies"],
|
|
496
|
-
# "dependents": project_data["dependents"]
|
|
497
|
-
# }
|
|
498
|
-
|
|
499
|
-
# if loaded_project_record is not None:
|
|
500
|
-
# if updated_time
|
|
501
|
-
|
|
502
|
-
# project_records.write_record(project_id, record_payload)
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
# for project in resolved_projects:
|
|
506
|
-
# project_id = project["project_id"]
|
|
507
|
-
# project_information = project_info[project_id]
|
|
508
|
-
# project_version = project_versions[project_id]
|
|
509
|
-
|
|
510
|
-
# record_payload: ProjectRecordPayload = {
|
|
511
|
-
# "project_name": project_information["project_name"],
|
|
512
|
-
# "project_slug": project_information["project_slug"],
|
|
513
|
-
# "version_id": project_version["version_id"],
|
|
514
|
-
# "version_environment": project_version["environment"],
|
|
515
|
-
# "added_time": datetime.now(tz=UTC).isoformat(),
|
|
516
|
-
# "file": primary_file,
|
|
517
|
-
# "is_manual": project["is_manual"],
|
|
518
|
-
# "highest_type": project["highest_type"],
|
|
519
|
-
# "dependencies": project["dependencies"],
|
|
520
|
-
# "dependents": project["dependents"],
|
|
521
|
-
# }
|
|
522
|
-
|
|
523
|
-
# project_records.write_record(project["project_id"], record_payload)
|
|
524
|
-
|
|
525
|
-
return 0
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
# import logging
|
|
529
|
-
# from argparse import Namespace
|
|
530
|
-
|
|
531
|
-
# from .. import config, paths, shared
|
|
532
|
-
# from ..modrinth import apis as modrinth_apis
|
|
533
|
-
# from ..modrinth import project_records
|
|
534
|
-
# from ..resolver import (
|
|
535
|
-
# Dependency,
|
|
536
|
-
# human_to_resolver,
|
|
537
|
-
# required_only,
|
|
538
|
-
# resolve_dependencies,
|
|
539
|
-
# )
|
|
540
|
-
|
|
541
|
-
# logger = logging.getLogger(__name__)
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
# def run(args: Namespace) -> int:
|
|
545
|
-
# projects: list[str] = args.projects
|
|
546
|
-
|
|
547
|
-
# if not (paths.configs_dir / "server.json").exists():
|
|
548
|
-
# logger.error(
|
|
549
|
-
# "Configuration file for server does not exist, is server initialized?"
|
|
550
|
-
# )
|
|
551
|
-
|
|
552
|
-
# server_config = config.read_config(
|
|
553
|
-
# "server", shared.default_configs["server"]["format_version"]
|
|
554
|
-
# )
|
|
555
|
-
# game_version = server_config["game_version"]
|
|
556
|
-
# loader_name = server_config["loader"]["name"]
|
|
557
|
-
|
|
558
|
-
# if loader_name == "vanilla":
|
|
559
|
-
# logger.error("Vanilla does not support mod or plugin.")
|
|
560
|
-
# return 1
|
|
561
|
-
|
|
562
|
-
# project_ids: list[str] = []
|
|
563
|
-
# for project in projects:
|
|
564
|
-
# modrinth_apis.get_project_versions(project, loader_name, game_version)
|
|
565
|
-
|
|
566
|
-
# def get_dependencies(project_id: str) -> dict[str, int]:
|
|
567
|
-
# dependencies: list[Dependency] = []
|
|
568
|
-
# if project_records.record_exists(project_id):
|
|
569
|
-
# project_record = project_records.read_record(project_id)
|
|
570
|
-
# for dependency_id, dependency_type in project_record[
|
|
571
|
-
# "dependencies"
|
|
572
|
-
# ].items():
|
|
573
|
-
# dependencies.append(
|
|
574
|
-
# {"project_id": dependency_id, "dependency_type": dependency_type}
|
|
575
|
-
# )
|
|
576
|
-
|
|
577
|
-
# else:
|
|
578
|
-
# project_version = modrinth_apis.get_project_versions(
|
|
579
|
-
# project_id, loader_name, game_version, include_changelog=False
|
|
580
|
-
# )[0]
|
|
581
|
-
|
|
582
|
-
# if "dependencies" in project_version:
|
|
583
|
-
# project_dependencies = project_version["dependencies"]
|
|
584
|
-
# for dependency in project_dependencies:
|
|
585
|
-
# if not "project_id" in dependency:
|
|
586
|
-
# continue
|
|
587
|
-
|
|
588
|
-
# if dependency["project_id"] is None:
|
|
589
|
-
# continue
|
|
590
|
-
|
|
591
|
-
# dependencies.append(
|
|
592
|
-
# {
|
|
593
|
-
# "project_id": dependency["project_id"],
|
|
594
|
-
# "dependency_type": dependency["dependency_type"],
|
|
595
|
-
# }
|
|
596
|
-
# )
|
|
597
|
-
|
|
598
|
-
# return human_to_resolver(dependencies)
|
|
599
|
-
|
|
600
|
-
# resolved_projects = resolve_dependencies(
|
|
601
|
-
# projects, get_dependencies, required_only
|
|
602
|
-
# )
|
|
603
|
-
# print(resolved_projects)
|
|
604
|
-
# return 0
|
|
605
|
-
|
|
606
|
-
# # # from ..modrinth.apis import get_project_versions
|
|
607
|
-
|
|
608
|
-
# # def get_project_versions(
|
|
609
|
-
# # project_id, loader_names, game_versions, featured=None, include_changelog=True
|
|
610
|
-
# # ):
|
|
611
|
-
# # project_version = {
|
|
612
|
-
# # "embeddium": {
|
|
613
|
-
# # "dependencies": [
|
|
614
|
-
# # {"project_id": "AANobbMI", "dependency_type": "incompatible"}
|
|
615
|
-
# # ],
|
|
616
|
-
# # "project_id": "sk9rgfiA",
|
|
617
|
-
# # },
|
|
618
|
-
# # "fabric-api": {"dependencies": [], "project_id": "P7dR8mSH"},
|
|
619
|
-
# # "jade": {
|
|
620
|
-
# # "dependencies": [
|
|
621
|
-
# # {"project_id": "AANobbMI", "dependency_type": "required"},
|
|
622
|
-
# # {"project_id": "u6dRKJwZ", "dependency_type": "optional"},
|
|
623
|
-
# # ],
|
|
624
|
-
# # "project_id": "nvQzSEkH",
|
|
625
|
-
# # },
|
|
626
|
-
# # "jei": {"dependencies": [], "project_id": "u6dRKJwZ"},
|
|
627
|
-
# # "just-enough-resources-jer": {
|
|
628
|
-
# # "dependencies": [
|
|
629
|
-
# # {"project_id": "u6dRKJwZ", "dependency_type": "required"}
|
|
630
|
-
# # ],
|
|
631
|
-
# # "project_id": "uEfK2CXF",
|
|
632
|
-
# # },
|
|
633
|
-
# # "origins": {
|
|
634
|
-
# # "dependencies": [
|
|
635
|
-
# # {"project_id": "P7dR8mSH", "dependency_type": "required"}
|
|
636
|
-
# # ],
|
|
637
|
-
# # "project_id": "3BeIrqZR",
|
|
638
|
-
# # },
|
|
639
|
-
# # "pehkui": {
|
|
640
|
-
# # "dependencies": [
|
|
641
|
-
# # {"project_id": "P7dR8mSH", "dependency_type": "required"}
|
|
642
|
-
# # ],
|
|
643
|
-
# # "project_id": "t5W7Jfwy",
|
|
644
|
-
# # },
|
|
645
|
-
# # "podium": {
|
|
646
|
-
# # "dependencies": [
|
|
647
|
-
# # {"project_id": "AANobbMI", "dependency_type": "required"}
|
|
648
|
-
# # ],
|
|
649
|
-
# # "project_id": "fW8woQj4",
|
|
650
|
-
# # },
|
|
651
|
-
# # "sodium": {"dependencies": [], "project_id": "AANobbMI"},
|
|
652
|
-
# # "thdilos-fox-origin-expanded": {
|
|
653
|
-
# # "dependencies": [
|
|
654
|
-
# # {"project_id": "9qGn08Dr", "dependency_type": "required"},
|
|
655
|
-
# # {"project_id": "3BeIrqZR", "dependency_type": "required"},
|
|
656
|
-
# # {"project_id": "t5W7Jfwy", "dependency_type": "required"},
|
|
657
|
-
# # ],
|
|
658
|
-
# # "project_id": "CbsRGXBx",
|
|
659
|
-
# # },
|
|
660
|
-
# # "thdilos-fox-origin": {
|
|
661
|
-
# # "dependencies": [
|
|
662
|
-
# # {"project_id": "3BeIrqZR", "dependency_type": "required"},
|
|
663
|
-
# # {"project_id": "t5W7Jfwy", "dependency_type": "required"},
|
|
664
|
-
# # ],
|
|
665
|
-
# # "project_id": "9qGn08Dr",
|
|
666
|
-
# # },
|
|
667
|
-
# # }
|
|
668
|
-
|
|
669
|
-
# # id_slug = {
|
|
670
|
-
# # "3BeIrqZR": "origins",
|
|
671
|
-
# # "9qGn08Dr": "thdilos-fox-origin",
|
|
672
|
-
# # "AANobbMI": "sodium",
|
|
673
|
-
# # "CbsRGXBx": "thdilos-fox-origin-expanded",
|
|
674
|
-
# # "P7dR8mSH": "fabric-api",
|
|
675
|
-
# # "fW8woQj4": "podium",
|
|
676
|
-
# # "nvQzSEkH": "jade",
|
|
677
|
-
# # "sk9rgfiA": "embeddium",
|
|
678
|
-
# # "t5W7Jfwy": "pehkui",
|
|
679
|
-
# # "u6dRKJwZ": "jei",
|
|
680
|
-
# # "uEfK2CXF": "just-enough-resources-jer",
|
|
681
|
-
# # }
|
|
682
|
-
|
|
683
|
-
# # a = [
|
|
684
|
-
# # (
|
|
685
|
-
# # project_version[project_id]
|
|
686
|
-
# # if project_id in project_version
|
|
687
|
-
# # else project_version[id_slug[project_id]]
|
|
688
|
-
# # )
|
|
689
|
-
# # ]
|
|
690
|
-
# # return a
|
|
691
|
-
|
|
692
|
-
# # server_config = config.read_config(
|
|
693
|
-
# # "server", shared.default_configs["server"]["format_version"]
|
|
694
|
-
# # )
|
|
695
|
-
# # loader_name = server_config["loader"]["name"]
|
|
696
|
-
# # game_version = server_config["game_version"]
|
|
697
|
-
|
|
698
|
-
# # cached_project_versions = {}
|
|
699
|
-
# # project_ids = []
|
|
700
|
-
|
|
701
|
-
# # for project in projects:
|
|
702
|
-
# # project_version = get_project_versions(
|
|
703
|
-
# # project, loader_name, game_version, include_changelog=False
|
|
704
|
-
# # )[0]
|
|
705
|
-
|
|
706
|
-
# # cached_project_versions[project_version["project_id"]] = project_version
|
|
707
|
-
# # project_ids.append(project_version["project_id"])
|
|
708
|
-
|
|
709
|
-
# # id_to_slug: dict[str, str] = {}
|
|
710
|
-
|
|
711
|
-
# # def get_dependencies(project_id: str) -> dict[str, int]:
|
|
712
|
-
# # dependencies: list[Dependency] = []
|
|
713
|
-
|
|
714
|
-
# # # Get the latest version
|
|
715
|
-
# # project_version = get_project_versions(
|
|
716
|
-
# # project_id, loader_name, game_version, include_changelog=False
|
|
717
|
-
# # )[0]
|
|
718
|
-
# # if "dependencies" in project_version:
|
|
719
|
-
# # project_dependencies = project_version["dependencies"]
|
|
720
|
-
# # for dependency in project_dependencies:
|
|
721
|
-
# # if not "project_id" in dependency:
|
|
722
|
-
# # continue
|
|
723
|
-
|
|
724
|
-
# # if dependency["project_id"] is None:
|
|
725
|
-
# # continue
|
|
726
|
-
|
|
727
|
-
# # dependencies.append(
|
|
728
|
-
# # {
|
|
729
|
-
# # "project_id": dependency["project_id"],
|
|
730
|
-
# # "dependency_type": dependency["dependency_type"],
|
|
731
|
-
# # }
|
|
732
|
-
# # )
|
|
733
|
-
|
|
734
|
-
# # return human_to_resolver(dependencies)
|
|
735
|
-
|
|
736
|
-
# # def required_only(dependency_type: int) -> bool:
|
|
737
|
-
# # return dependency_type == 2
|
|
738
|
-
|
|
739
|
-
# # resolved_projects = resolver_to_human(
|
|
740
|
-
# # resolve_dependencies(project_ids, get_dependencies, required_only)
|
|
741
|
-
# # )
|
|
742
|
-
|
|
743
|
-
# # print(json.dumps(resolved_projects, indent=2))
|
|
744
|
-
|
|
745
|
-
# # required_projects: set[str] = set()
|
|
746
|
-
# # optional_projects: set[str] = set()
|
|
747
|
-
# # incompatible_projects: set[str] = set()
|
|
748
|
-
|
|
749
|
-
# # for project in resolved_projects:
|
|
750
|
-
# # for dependent in project["dependents"]:
|
|
751
|
-
# # match dependent["dependency_type"]:
|
|
752
|
-
# # case "required":
|
|
753
|
-
# # required_projects.add(project["project_id"])
|
|
754
|
-
# # case "optional":
|
|
755
|
-
# # optional_projects.add(project["project_id"])
|
|
756
|
-
# # case "incompatible":
|
|
757
|
-
# # incompatible_projects.add(project["project_id"])
|
|
758
|
-
|
|
759
|
-
# # conflicting_projects: set[str] = required_projects & incompatible_projects
|
|
760
|
-
|
|
761
|
-
# # if conflicting_projects:
|
|
762
|
-
# # print(f"I think we have conflicting project -_-, like {conflicting_projects} are in required and incompatible")
|
|
763
|
-
|
|
764
|
-
# # print(required_projects, optional_projects, incompatible_projects, conflicting_projects)
|
|
765
|
-
|
|
766
|
-
# # return 0
|
|
240
|
+
logger.info("Complete!")
|
|
241
|
+
return 0
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
import logging
|
|
1
2
|
from argparse import Namespace
|
|
2
3
|
|
|
4
|
+
logger = logging.getLogger(__name__)
|
|
3
5
|
|
|
4
6
|
def run(args: Namespace) -> int:
|
|
5
|
-
import logging as log
|
|
6
7
|
|
|
7
8
|
from .. import state
|
|
8
9
|
|
|
9
10
|
# Check MCServer status
|
|
10
11
|
if not state.state_file.parent.exists():
|
|
11
|
-
|
|
12
|
+
logger.error("State file not exist, is MCServer initialized?")
|
|
12
13
|
return 1
|
|
13
14
|
|
|
14
15
|
current_state = state.get_state()
|
|
@@ -22,7 +23,7 @@ def run(args: Namespace) -> int:
|
|
|
22
23
|
error_message += f" with process ID: {current_state['process_id']}"
|
|
23
24
|
error_message += "."
|
|
24
25
|
|
|
25
|
-
|
|
26
|
+
logger.error(error_message)
|
|
26
27
|
return 1
|
|
27
28
|
|
|
28
29
|
# Set state
|
|
@@ -60,7 +61,7 @@ def run(args: Namespace) -> int:
|
|
|
60
61
|
loader_version = server_loader["version"]
|
|
61
62
|
|
|
62
63
|
if loader_name != "vanilla" and loader_version is None:
|
|
63
|
-
|
|
64
|
+
logger.error("Loader version cannot be null")
|
|
64
65
|
return 1
|
|
65
66
|
|
|
66
67
|
match loader_name:
|
|
@@ -68,7 +69,7 @@ def run(args: Namespace) -> int:
|
|
|
68
69
|
case "fabric":
|
|
69
70
|
from ..fabricmc import meta as fabricmc_meta
|
|
70
71
|
|
|
71
|
-
|
|
72
|
+
logger.info(
|
|
72
73
|
f"Downloading Fabric loader {loader_version} for Minecraft version {game_version}..."
|
|
73
74
|
)
|
|
74
75
|
networking.download(
|
|
@@ -88,7 +89,7 @@ def run(args: Namespace) -> int:
|
|
|
88
89
|
case "paper":
|
|
89
90
|
from ..papermc import api as papermc_api
|
|
90
91
|
|
|
91
|
-
|
|
92
|
+
logger.info(
|
|
92
93
|
f"Downloading Paper build {loader_version} for Minecraft version {game_version}..."
|
|
93
94
|
)
|
|
94
95
|
|
|
@@ -103,7 +104,7 @@ def run(args: Namespace) -> int:
|
|
|
103
104
|
case "purpur":
|
|
104
105
|
from ..purpurmc import api as purpurmc_api
|
|
105
106
|
|
|
106
|
-
|
|
107
|
+
logger.info(
|
|
107
108
|
f"Downloading Purpur build {loader_version} for Minecraft version {game_version}..."
|
|
108
109
|
)
|
|
109
110
|
project_build = purpurmc_api.get_project_build(
|
|
@@ -119,7 +120,7 @@ def run(args: Namespace) -> int:
|
|
|
119
120
|
case "vanilla":
|
|
120
121
|
from ..mojang import manifest as mojang_manifest
|
|
121
122
|
|
|
122
|
-
|
|
123
|
+
logger.info(f"Downloading vanilla Minecraft version {game_version}...")
|
|
123
124
|
|
|
124
125
|
version_manifest = mojang_manifest.get_version_manifest()[
|
|
125
126
|
"game_versions"
|
|
@@ -131,7 +132,7 @@ def run(args: Namespace) -> int:
|
|
|
131
132
|
break
|
|
132
133
|
|
|
133
134
|
if package_url is None:
|
|
134
|
-
|
|
135
|
+
logger.error(f"Minecraft version not found: {game_version}")
|
|
135
136
|
return 1
|
|
136
137
|
|
|
137
138
|
package_data = networking.request(package_url)["text"]
|
|
@@ -144,18 +145,18 @@ def run(args: Namespace) -> int:
|
|
|
144
145
|
hashes={"sha1": version_download["sha1"]},
|
|
145
146
|
)
|
|
146
147
|
case _:
|
|
147
|
-
|
|
148
|
+
logger.error(
|
|
148
149
|
f"Loader is not supported ({loader_name}), you may have to edit '.mcserver/configs/server.json' to fix it."
|
|
149
150
|
)
|
|
150
151
|
return 1
|
|
151
152
|
|
|
152
153
|
# Check stuff
|
|
153
154
|
if not shutil.which("java"):
|
|
154
|
-
|
|
155
|
+
logger.error("'java' not found")
|
|
155
156
|
return 1
|
|
156
157
|
|
|
157
158
|
if memory_config["min"] > memory_config["max"]:
|
|
158
|
-
|
|
159
|
+
logger.error("Minimum RAM is bigger than maximum RAM")
|
|
159
160
|
return 1
|
|
160
161
|
|
|
161
162
|
# Run the server
|
|
@@ -171,5 +172,5 @@ def run(args: Namespace) -> int:
|
|
|
171
172
|
java_command_argv.append("nogui")
|
|
172
173
|
|
|
173
174
|
# Execute java
|
|
174
|
-
|
|
175
|
+
logger.debug(f"Executing command: {' '.join(java_command_argv)}")
|
|
175
176
|
os.execvp(java_command_argv[0], java_command_argv)
|
mcserver/modrinth/slug_index.py
CHANGED
|
@@ -6,6 +6,7 @@ from datetime import UTC, datetime, timedelta
|
|
|
6
6
|
from typing import TypedDict
|
|
7
7
|
|
|
8
8
|
# MCServer
|
|
9
|
+
from .. import shared
|
|
9
10
|
from ..paths import mcserver_cache_dir
|
|
10
11
|
|
|
11
12
|
logger = logging.getLogger(__name__)
|
|
@@ -28,7 +29,7 @@ slug_index_file = mcserver_cache_dir / "slug_index.json"
|
|
|
28
29
|
def _load_slug_index() -> None:
|
|
29
30
|
global _slug_index
|
|
30
31
|
if _slug_index is not None:
|
|
31
|
-
logger.debug("
|
|
32
|
+
logger.debug("Slug index is already set, not reloading")
|
|
32
33
|
return
|
|
33
34
|
|
|
34
35
|
if not slug_index_file.exists():
|
|
@@ -52,6 +53,8 @@ def _load_slug_index() -> None:
|
|
|
52
53
|
f"{slug_index_file} is corrupted! Rebuilding it from scratch"
|
|
53
54
|
) # that's all I can say.
|
|
54
55
|
_slug_index = {}
|
|
56
|
+
|
|
57
|
+
logger.debug("Loaded slug index from file")
|
|
55
58
|
|
|
56
59
|
|
|
57
60
|
def is_index_outdated(project_slug: str) -> bool:
|
|
@@ -90,10 +93,13 @@ def slug_to_id(project_slug: str) -> str:
|
|
|
90
93
|
global _slug_index
|
|
91
94
|
project_id: str = ""
|
|
92
95
|
if _slug_index is None:
|
|
96
|
+
logger.debug("Idk how _slug_index can be None")
|
|
93
97
|
_slug_index = {}
|
|
94
98
|
|
|
95
99
|
slug_index = _slug_index.get(project_slug, {})
|
|
96
100
|
project_id = slug_index.get("project_id", project_id)
|
|
101
|
+
|
|
102
|
+
logger.debug(f"Project slug {project_slug} is project ID {project_id}")
|
|
97
103
|
return project_id
|
|
98
104
|
|
|
99
105
|
|
|
@@ -110,13 +116,15 @@ def update_slug_index(project_slug: str, project_id: str):
|
|
|
110
116
|
}
|
|
111
117
|
|
|
112
118
|
_slug_index[project_slug] = slug_index
|
|
119
|
+
logger.debug(f"Updated slug index for project slug {project_slug} to project ID {project_id}")
|
|
113
120
|
|
|
114
121
|
|
|
115
122
|
def save_slug_index() -> None:
|
|
116
|
-
global _slug_index
|
|
117
123
|
if _slug_index is None:
|
|
118
|
-
|
|
124
|
+
logger.debug("Slug index is not set")
|
|
125
|
+
return
|
|
119
126
|
|
|
120
|
-
_slug_index_json = json.dumps(_slug_index)
|
|
121
127
|
mcserver_cache_dir.mkdir(parents=True, exist_ok=True)
|
|
122
|
-
|
|
128
|
+
|
|
129
|
+
logger.debug("Saving slug index to file")
|
|
130
|
+
shared.update_file(slug_index_file, json.dumps(_slug_index).encode())
|
mcserver/networking.py
CHANGED
|
@@ -4,10 +4,11 @@ import hashlib
|
|
|
4
4
|
import json
|
|
5
5
|
import logging
|
|
6
6
|
import shutil
|
|
7
|
+
import urllib.error
|
|
7
8
|
import urllib.parse
|
|
8
9
|
import urllib.request
|
|
9
10
|
from pathlib import Path
|
|
10
|
-
from typing import
|
|
11
|
+
from typing import TypedDict
|
|
11
12
|
|
|
12
13
|
# MCServer
|
|
13
14
|
from . import __version__
|
|
@@ -19,7 +20,7 @@ logger = logging.getLogger(__name__)
|
|
|
19
20
|
# TypedDict
|
|
20
21
|
class ResponseObject(TypedDict):
|
|
21
22
|
text: str
|
|
22
|
-
json:
|
|
23
|
+
json: dict | list | None
|
|
23
24
|
headers: dict
|
|
24
25
|
status_code: int
|
|
25
26
|
|
|
@@ -47,6 +48,7 @@ def request(
|
|
|
47
48
|
headers: dict | None = None,
|
|
48
49
|
method: str = "GET",
|
|
49
50
|
timeout: int = 10,
|
|
51
|
+
always_json: bool = False
|
|
50
52
|
) -> ResponseObject:
|
|
51
53
|
method = method.upper()
|
|
52
54
|
if query is None:
|
|
@@ -60,24 +62,40 @@ def request(
|
|
|
60
62
|
f"{url}{query_string}", data=data, headers=headers, method=method
|
|
61
63
|
)
|
|
62
64
|
|
|
63
|
-
response_object: ResponseObject = {} # type: ignore[typeddict-items]
|
|
64
|
-
|
|
65
65
|
logger.debug(f"Requesting URL: {method} {request.full_url}")
|
|
66
|
-
|
|
67
|
-
|
|
66
|
+
try:
|
|
67
|
+
with urllib.request.urlopen(request, timeout=timeout) as response:
|
|
68
|
+
logger.debug(f"Responded with status: {response.status} {response.reason}")
|
|
69
|
+
|
|
70
|
+
response_headers = {}
|
|
71
|
+
for key, value in response.getheaders():
|
|
72
|
+
response_headers[key.lower()] = value
|
|
73
|
+
|
|
74
|
+
response_object: ResponseObject = {
|
|
75
|
+
"status_code": response.code,
|
|
76
|
+
"headers": response_headers,
|
|
77
|
+
"text": response.read().decode("utf-8"),
|
|
78
|
+
"json": None
|
|
79
|
+
}
|
|
68
80
|
|
|
81
|
+
if always_json or response_headers.get("content-type", "").startswith("application/json"):
|
|
82
|
+
response_object["json"] = json.loads(response_object["text"])
|
|
83
|
+
|
|
84
|
+
return response_object
|
|
85
|
+
|
|
86
|
+
except urllib.error.HTTPError as response:
|
|
69
87
|
response_headers = {}
|
|
70
88
|
for key, value in response.getheaders():
|
|
71
89
|
response_headers[key.lower()] = value
|
|
72
90
|
|
|
73
|
-
response_object
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
91
|
+
response_object: ResponseObject = {
|
|
92
|
+
"status_code": response.code,
|
|
93
|
+
"headers": response_headers,
|
|
94
|
+
"text": response.reason,
|
|
95
|
+
"json": None
|
|
96
|
+
}
|
|
79
97
|
|
|
80
|
-
|
|
98
|
+
return response_object
|
|
81
99
|
|
|
82
100
|
|
|
83
101
|
def download(
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: mcserver-cli
|
|
3
|
-
Version: 4.
|
|
3
|
+
Version: 4.6.2
|
|
4
4
|
Summary: A CLI tool to manage Minecraft: Java Edition servers.
|
|
5
5
|
Project-URL: Homepage, https://github.com/Othecat35/MCServer
|
|
6
6
|
Project-URL: Repository, https://github.com/Othecat35/MCServer.git
|
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
mcserver/__init__.py,sha256=
|
|
1
|
+
mcserver/__init__.py,sha256=btQ57LP4XGqnYnt3ZNMsfrFb8JbjcJHBRLKB5n6F9MI,22
|
|
2
2
|
mcserver/__main__.py,sha256=3-WYJCtLQ8TbzmLMYBiAsm9PC89DwjXc6s_J-izMEz8,30
|
|
3
3
|
mcserver/app.py,sha256=3JUqv2jbv8ZZnvx6GTqX8mkTN08es2RQjcpfajfPeY0,1025
|
|
4
4
|
mcserver/caching.py,sha256=oLIQuiBqlJLxSTCVyrtHoYEZvmtnb3duxhhE-P5bOR8,411
|
|
5
|
-
mcserver/cli.py,sha256=
|
|
5
|
+
mcserver/cli.py,sha256=_0bNGnMm27sVXk3C_-cZ4-MbUp6Wb7SVvYj46SdJwys,11876
|
|
6
6
|
mcserver/config.py,sha256=JlIATmTETwVTmXzrmONDBbYddj_aB4hcn8zYu5CQHTQ,2136
|
|
7
7
|
mcserver/constants.py,sha256=ME5f4dv1PbqyQ6G1lQkKtvHQ4b722De4xu5B5Vp1Hw8,480
|
|
8
8
|
mcserver/metadata.py,sha256=sPstt7jrtPh1_kthje-loQ6UYB2c5m496IOJFYeGxjI,977
|
|
9
9
|
mcserver/mysterious.py,sha256=giH_NRs7CuV51NACh3AUIIXKEKowHKb6DFGQQVPgtxE,642
|
|
10
|
-
mcserver/networking.py,sha256=
|
|
10
|
+
mcserver/networking.py,sha256=lxGaTRELH0vRWe5hl6h3YKy85P9TUJCn3mBy6QFA16I,5414
|
|
11
11
|
mcserver/paths.py,sha256=ZwCKOj4VdVgEzq30ZtnZyGjTgW5S3CiuX3Su-csgb2k,462
|
|
12
12
|
mcserver/resolver.py,sha256=RSCfPLQ5S3ZrKk2nd57Df694TrQ1Irrbt77nK8Bx0xA,7516
|
|
13
13
|
mcserver/shared.py,sha256=J9YQio3I0d9efizUi_3Nol9b5-zOz2exdNs1-ePr4pw,7509
|
|
14
14
|
mcserver/state.py,sha256=LVok4DbjiassDk1W9RCLIQZiXezaHxK1PInIW_Bm1bQ,2028
|
|
15
15
|
mcserver/commands/__init__.py,sha256=h-rdpn8r32rrHIZzs9fFu3pYWuc3KoRZIJO8IX0vU3U,1230
|
|
16
|
-
mcserver/commands/add_projects.py,sha256=
|
|
16
|
+
mcserver/commands/add_projects.py,sha256=_tzqBMv26y4ltY2qrj_w_1TI8EwmybekME_GyCfj9q0,9431
|
|
17
17
|
mcserver/commands/import_setup.py,sha256=NbByM4seH0dAYo2QEj37VsL_J_Mtvg0S7NTsTFbcneA,181
|
|
18
18
|
mcserver/commands/initialize_server.py,sha256=ZvpEHjpCsvfA2vRHJzt5uypuIq96UUvhCUANA53gUgg,5939
|
|
19
19
|
mcserver/commands/list_projects.py,sha256=XG7U6oMVxQrTuV_GFCsp5aYZJphjyYwFDZiiURnjzNw,155
|
|
@@ -25,7 +25,7 @@ mcserver/commands/remove_projects.py,sha256=XG7U6oMVxQrTuV_GFCsp5aYZJphjyYwFDZii
|
|
|
25
25
|
mcserver/commands/search_projects.py,sha256=jfMqrWuan7rqeadG1I9E9coJJUJQnSJ4Oo--rQ1DWjE,6389
|
|
26
26
|
mcserver/commands/server_status.py,sha256=XG7U6oMVxQrTuV_GFCsp5aYZJphjyYwFDZiiURnjzNw,155
|
|
27
27
|
mcserver/commands/show_projects.py,sha256=2mnuV8z8Ws1GSX_iMGsI5lrdu32ZsvAHI11eq7NAdlc,4029
|
|
28
|
-
mcserver/commands/start_server.py,sha256=
|
|
28
|
+
mcserver/commands/start_server.py,sha256=IzsSiS4PW6OdgwmJsDDlmTqdb9-tto-lTYLewuy493U,5826
|
|
29
29
|
mcserver/commands/stop_server.py,sha256=l3-OiInwPlj1ApWQ8ZTqBsMKmkAPCh1MAjoqYLnHnO4,555
|
|
30
30
|
mcserver/commands/update_projects.py,sha256=XG7U6oMVxQrTuV_GFCsp5aYZJphjyYwFDZiiURnjzNw,155
|
|
31
31
|
mcserver/commands/whitelist_add.py,sha256=CCrXuuIJDFKv_IMSW3uRawwjba-g4sWoEDa3bYK6qXI,2823
|
|
@@ -40,7 +40,7 @@ mcserver/modrinth/modpack.py,sha256=uBx51G8sxQZEK127EMyXEZbyFMayps9pPGzTa49Vk6w,
|
|
|
40
40
|
mcserver/modrinth/paths.py,sha256=DCKgbtVDPMvkvclab21bjr_7la0rbdkG2foLLgRYyAY,129
|
|
41
41
|
mcserver/modrinth/project_records.py,sha256=4xEk7971LoTlQsInHF2-LhxOQEalnA8uHAaiD-zQdSI,3494
|
|
42
42
|
mcserver/modrinth/shared.py,sha256=-bVTwhYxif2jufZ_jcH5Gifa4d7uUtq_SGVgHfVXsyQ,3013
|
|
43
|
-
mcserver/modrinth/slug_index.py,sha256=
|
|
43
|
+
mcserver/modrinth/slug_index.py,sha256=Ouu8xtXRQxEC_bn1KAmYKGEcggdEo13jO7owhBTYoMQ,3526
|
|
44
44
|
mcserver/modrinth/apis/__init__.py,sha256=gCQwcpU3Duj2AfVKtcnm8wb91EqiQT3nsLbABYa6JC0,261
|
|
45
45
|
mcserver/modrinth/apis/get_project_informations.py,sha256=bDM6Y6GgNXaO-qCpJ5Sw6Ifost2ShhqryVR0lT_mUOk,8284
|
|
46
46
|
mcserver/modrinth/apis/get_project_versions.py,sha256=DDWjufayTaaHXVGENtz8490yTTT6oSdb60Si4DMRsbM,6100
|
|
@@ -64,8 +64,8 @@ mcserver/server_files/server_properties.py,sha256=8b8gY6haiPi5fKuCgrEZBH6S4yYLst
|
|
|
64
64
|
mcserver/server_files/shared.py,sha256=7xrjv77KAsfREqEsgU2HyBNv9hI9bNWaWTDu5geOSqs,385
|
|
65
65
|
mcserver/server_files/usercaches.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
66
66
|
mcserver/server_files/whitelist.py,sha256=88Q_iKXgFuYOaz769MGWIn52QOlc-7LSXTPQTqsAk6Q,5711
|
|
67
|
-
mcserver_cli-4.
|
|
68
|
-
mcserver_cli-4.
|
|
69
|
-
mcserver_cli-4.
|
|
70
|
-
mcserver_cli-4.
|
|
71
|
-
mcserver_cli-4.
|
|
67
|
+
mcserver_cli-4.6.2.dist-info/METADATA,sha256=bD6ViA-DYJm05XpuVTKL20LxYDc00Pf_7ASoINTMrug,2861
|
|
68
|
+
mcserver_cli-4.6.2.dist-info/WHEEL,sha256=2iZrJkDIkeDh0k9SikKMqFuRP-ua6mb4Ir1AsER4BEw,87
|
|
69
|
+
mcserver_cli-4.6.2.dist-info/entry_points.txt,sha256=p7uN6UdTzjea7nGIkhjiYDYd7wznkxz9amUPY_fpz24,47
|
|
70
|
+
mcserver_cli-4.6.2.dist-info/licenses/LICENSE,sha256=OzeasqJgwxVpwtMkEYOLoDPUnIDSbVcW62rk-voA3eI,1076
|
|
71
|
+
mcserver_cli-4.6.2.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|