forked from skywardmc/additive
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_missing_mods.py
More file actions
executable file
·124 lines (96 loc) · 3.52 KB
/
Copy pathadd_missing_mods.py
File metadata and controls
executable file
·124 lines (96 loc) · 3.52 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
#!/usr/bin/env python3
"""
Script to process missing mods and attempt to add them using packwiz.
Successfully added mods are removed from the missing-mods file.
Usage:
python add_missing_mods.py 1.21.10 # Provide version as argument
echo "1.21.10" | python add_missing_mods.py # Pipe version from stdin
python add_missing_mods.py # Interactive mode
"""
import subprocess
import sys
import os
def get_version():
"""Get version from command line args, stdin, or user input."""
# Try command line argument first
if len(sys.argv) > 1:
return sys.argv[1].strip()
# Try stdin (non-interactive)
if not sys.stdin.isatty():
return sys.stdin.read().strip()
# Interactive input
return input("Enter Minecraft version (e.g., 1.21.10): ").strip()
def read_missing_mods(missing_mods_file):
"""Read mod IDs from the missing-mods file."""
if not os.path.exists(missing_mods_file):
return []
with open(missing_mods_file, "r") as f:
return [line.strip() for line in f if line.strip()]
def add_mod(mod_id, working_dir):
"""Try to add a mod using packwiz mr add. Returns True if successful, False otherwise."""
try:
result = subprocess.run(
["packwiz", "mr", "add", mod_id],
cwd=working_dir,
capture_output=True,
text=True,
check=True,
)
print(f"✓ Successfully added: {mod_id}")
return True
except subprocess.CalledProcessError as e:
print(f"✗ Failed to add: {mod_id}")
if e.stderr:
print(f" Error: {e.stderr.strip()}")
return False
except FileNotFoundError:
print("✗ Error: packwiz command not found. Make sure it's installed.")
return False
def write_missing_mods(missing_mods_file, mod_ids):
"""Write the remaining mod IDs back to the missing-mods file."""
with open(missing_mods_file, "w") as f:
for mod_id in mod_ids:
f.write(f"{mod_id}\n")
def main():
# Get version from user
version = get_version()
if not version:
print("Error: No version provided.")
sys.exit(1)
# Setup paths based on version
working_dir = f"versions/active/{version}"
missing_mods_file = os.path.join(working_dir, "missing-mods")
# Check if directory exists
if not os.path.exists(working_dir):
print(f"Error: Directory '{working_dir}' does not exist.")
sys.exit(1)
print(f"Processing version: {version}")
print(f"Working directory: {working_dir}\n")
# Read all mod IDs
mod_ids = read_missing_mods(missing_mods_file)
print(f"Found {len(mod_ids)} mods to process\n")
if not mod_ids:
print("No mods to process.")
return
# Track which mods still need to be added
still_missing = []
# Try to add each mod
for mod_id in mod_ids:
if not add_mod(mod_id, working_dir):
still_missing.append(mod_id)
print() # Empty line between mods
# Update the missing-mods file with only the failed ones
write_missing_mods(missing_mods_file, still_missing)
# Summary
print("=" * 40)
print("SUMMARY")
print("=" * 40)
print(f"Total mods processed: {len(mod_ids)}")
print(f"Successfully added: {len(mod_ids) - len(still_missing)}")
print(f"Still missing: {len(still_missing)}")
if still_missing:
print("\nMods that still need to be added:")
for mod_id in still_missing:
print(f" - {mod_id}")
if __name__ == "__main__":
main()