|
|
@ -2,13 +2,57 @@ |
|
|
|
|
|
|
|
import sys |
|
|
|
import os |
|
|
|
import shutil |
|
|
|
|
|
|
|
def error(msg): |
|
|
|
sys.stderr.write("{}\n".format(msg)) |
|
|
|
sys.stderr.flush() |
|
|
|
|
|
|
|
def add_depends(mod_path): |
|
|
|
mod_dir_name = os.path.basename(mod_path) |
|
|
|
modpack_conf = os.path.join(mod_path, "modpack.conf") |
|
|
|
modpack_txt = os.path.join(mod_path, "modpack.txt") |
|
|
|
found_modpack_file = None |
|
|
|
if os.path.isfile(modpack_txt): |
|
|
|
found_modpack_file = "modpack.txt" |
|
|
|
if os.path.isfile(modpack_conf): |
|
|
|
found_modpack_file = "modpack.conf" |
|
|
|
if not os.path.isfile(modpack_txt): |
|
|
|
# shutil.copy(modpack_conf, modpack_txt) |
|
|
|
with open(modpack_txt, 'w') as outs: |
|
|
|
wroteCount = 0 |
|
|
|
with open(modpack_conf, 'r') as ins: |
|
|
|
for rawL in ins: |
|
|
|
line = line.strip() |
|
|
|
signI = line.find("=") |
|
|
|
if signI < 1: |
|
|
|
continue |
|
|
|
name = line[:signI].strip() |
|
|
|
value = line[signI+1:].strip() |
|
|
|
if name == "description": |
|
|
|
outs.write(value) |
|
|
|
wroteCount += 1 |
|
|
|
pass |
|
|
|
if wroteCount < 1: |
|
|
|
outs.write("\n") |
|
|
|
# ^ The modpack.txt file just needs to exist. |
|
|
|
print("* created {}/modpack.txt" |
|
|
|
"".format(mod_dir_name)) |
|
|
|
else: |
|
|
|
error("{}/modpack.txt already exists for compatibility." |
|
|
|
"".format(mod_dir_name)) |
|
|
|
if os.path.isfile(modpack_txt): |
|
|
|
error("{}/{} indicates it is a modpack." |
|
|
|
"".format(mod_dir_name, found_modpack_file)) |
|
|
|
for sub in os.listdir(mod_path): |
|
|
|
if sub.startswith('.'): |
|
|
|
continue |
|
|
|
subPath = os.path.join(mod_path, sub) |
|
|
|
add_depends(subPath) |
|
|
|
# It must be a modpack, so return after doing subdirectories. |
|
|
|
return |
|
|
|
depends_path = os.path.join(mod_path, "depends.txt") |
|
|
|
description_path = os.path.join(mod_path, "description.txt") |
|
|
|
if os.path.isfile(depends_path): |
|
|
|
error("WARNING: Writing {} will be skipped since it exists." |
|
|
|
"".format(depends_path)) |
|
|
@ -19,8 +63,9 @@ def add_depends(mod_path): |
|
|
|
" not exist." |
|
|
|
"".format(depends_path, mod_conf)) |
|
|
|
return |
|
|
|
optional_depends = [] |
|
|
|
depends = [] |
|
|
|
optional_depends = None |
|
|
|
depends = None |
|
|
|
description = None |
|
|
|
lineN = 0 |
|
|
|
with open(mod_conf, 'r') as ins: |
|
|
|
for rawL in ins: |
|
|
@ -41,33 +86,41 @@ def add_depends(mod_path): |
|
|
|
continue |
|
|
|
name = line[:signI].strip() |
|
|
|
value = line[signI+1:].strip() |
|
|
|
values = [depend.strip() for depend in value.split(",")] |
|
|
|
if name == "depends": |
|
|
|
depends = [depend.strip() for depend in value.split(",")] |
|
|
|
depends = values |
|
|
|
elif name == "optional_depends": |
|
|
|
optional_depends = [depend.strip() for depend in value.split(",")] |
|
|
|
optional_depends = values |
|
|
|
elif name == "description": |
|
|
|
description = value |
|
|
|
print("") |
|
|
|
mod_dir_name = os.path.basename(mod_path) |
|
|
|
print("mod: {}".format(mod_dir_name)) |
|
|
|
print("* depends: {}".format(depends)) |
|
|
|
print("* optional_depends: {}".format(optional_depends)) |
|
|
|
depends_count = 0 |
|
|
|
if depends is not None: |
|
|
|
depends_count += len(depends) |
|
|
|
if optional_depends is not None: |
|
|
|
depends_count += len(optional_depends) |
|
|
|
if depends_count > 0: |
|
|
|
with open(depends_path, 'w') as outs: |
|
|
|
if depends is not None: |
|
|
|
for depend in depends: |
|
|
|
outs.write("{}\n".format(depend)) |
|
|
|
if optional_depends is not None: |
|
|
|
for depend in optional_depends: |
|
|
|
outs.write("{}?\n".format(depend)) |
|
|
|
print("* wrote {}/depends.txt".format(mod_dir_name)) |
|
|
|
if description is not None: |
|
|
|
if os.path.isfile(description_path): |
|
|
|
print("* INFO: There is already a description.txt so it" |
|
|
|
" will be left intact.") |
|
|
|
return |
|
|
|
with open(description_path, 'w') as outs: |
|
|
|
outs.write("{}\n".format(description)) |
|
|
|
print("* wrote {}/description.txt".format(mod_dir_name)) |
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
|
|
parent = os.path.realpath(".") |
|
|
|
modpack_conf = os.path.join(parent, "modpack.conf") |
|
|
|
if os.path.isfile(modpack_conf): |
|
|
|
for sub in os.listdir(parent): |
|
|
|
subPath = os.path.join(parent, sub) |
|
|
|
if sub.startswith("."): |
|
|
|
continue |
|
|
|
if not os.path.isdir(subPath): |
|
|
|
continue |
|
|
|
add_depends(subPath) |
|
|
|
else: |
|
|
|
add_depends(parent) |
|
|
|