Use mmc-export for packwiz pack (#474)

* Use mmc-export for packwiz pack

* Whoopsie

* Oh god

* Shorten the ifs

* Spacing

Co-authored-by: Madis <Madis0@users.noreply.github.com>
This commit is contained in:
Project D.D 2022-09-15 15:02:43 +00:00 committed by GitHub
parent 9e46353a3c
commit 58403c1d46
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,5 +1,6 @@
import os
from zipfile import ZipFile
from shutil import unpack_archive
from pathlib import Path
import toml # pip install toml
@ -18,6 +19,7 @@ refresh_only = False
is_legacy = False
hydrogen = False
modrinth_overrides = True
mmc_export_packwiz_export = True
mmc_export_modrinth_export = True
packwiz_modrinth_export = False
@ -30,16 +32,17 @@ def extract_file(from_zip, from_file, to_path, from_desc, to_desc):
print("Skipped " + from_desc + " copying to " + to_desc + ", didn't exist")
mod_files = os.listdir(mods_path)
if refresh_only == False:
if not refresh_only:
for item in mod_files:
os.remove( os.path.join(mods_path, item))
os.chdir(packwiz_path)
if refresh_only == False:
if not refresh_only:
cf_zip_path = input("Please drag the CurseForge zip file here: ")[3:][:-1] # Because dragging the file adds "& " and double quotes
# Update pack.toml first
pack_version = "-".join(str(Path(cf_zip_path).with_suffix("")).split("-")[1:])
if not mmc_export_packwiz_export and not refresh_only:
# Update pack.toml first
with open(packwiz_manifest, "r") as f:
pack_toml = toml.load(f)
pack_toml["version"] = pack_version
@ -54,13 +57,30 @@ if refresh_only == False:
if modrinth_overrides:
os.system(packwiz_exe_path + " remove entityculling")
os.system(packwiz_exe_path + " mr install entityculling")
os.system(packwiz_exe_path + " refresh")
elif not mmc_export_packwiz_export and refresh_only:
os.system(packwiz_exe_path + " refresh")
# Copy fresh manifest/modlist to git
if is_legacy == False and refresh_only == False:
if not is_legacy and not refresh_only:
extract_file(cf_zip_path, "manifest.json", git_path + "CurseForge", "CurseForge manifest.json", "Git")
extract_file(cf_zip_path, "modlist.html", git_path + "CurseForge", "CurseForge modlist.html", "Git")
# Export packwiz pack via mmc-export method
if mmc_export_packwiz_export and not refresh_only:
mmc_zip_root = str(Path(cf_zip_path).parents[0])
mmc_zip_path = mmc_zip_root + "\\Fabulously Optimized " + pack_version + ".zip"
packwiz_config = git_path + "Packwiz\\mmc-export.toml"
cmd = f'mmc-export -i "{mmc_zip_path}" -f packwiz --modrinth-search loose -o "{mmc_zip_root}" -c "{packwiz_config}" -v {pack_version} --provider-priority Modrinth CurseForge Other --scheme ' + '"mmc_export_packwiz_output"'
os.system(cmd)
packwiz_zip_path = Path(mmc_zip_root) / "mmc_export_packwiz_output.zip"
packwiz_out_path = Path(git_path) / "Packwiz" / minecraft_version
packwiz_out_path.mkdir(parents=True, exist_ok=True)
unpack_archive(packwiz_zip_path, packwiz_out_path)
os.remove(packwiz_zip_path)
# Export Modrinth pack and manifest via mmc-export method
if mmc_export_modrinth_export: