Copy minified instance.cf to MultiMC in MultiMC to Git.py (#390)

* Update MMC instance.cfg in MultiMC to Git.py

* Whoops...

* Whoops... (2)

* Looks about right.

* Fix missing backslash

* Fix my inconsistent slashes

* More consistency

* Get version from instance.cfg instead of zip filename

* Well, glob can be removed now

Co-authored-by: Madis <Madis0@users.noreply.github.com>
This commit is contained in:
Project D.D 2022-06-28 17:12:56 +07:00 committed by GitHub
parent 0a1ef4402a
commit 73e7784efc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -1,9 +1,10 @@
import os, shutil
import os, shutil, re, zipfile
from distutils import dir_util
user_path = os.path.expanduser("~")
mmc_path = user_path + "/Documents/MultiMC/instances/Fabulously Optimized/"
git_path = user_path + "/Documents/GitHub/fabulously-optimized/"
output_path = user_path + "/Desktop/"
# Functions
@ -14,8 +15,33 @@ def copy_file(from_path, to_path, from_desc, to_desc):
else:
print("Skipped " + from_desc + " copying to " + to_desc + ", didn't exist")
def copy_to_archive(from_path, to_path, archive_path):
files = []
with zipfile.ZipFile(archive_path) as archive:
for zipinfo in archive.infolist():
if zipinfo.filename != to_path:
files.append((zipinfo.filename, archive.read(zipinfo.filename)))
with zipfile.ZipFile(archive_path, "w") as archive:
for filename, content in files:
archive.writestr(filename, content)
archive.write(from_path, to_path)
# MultiMC to Git
copy_file(mmc_path + "instance.cfg", git_path + "MultiMC\Fabulously Optimized x.y.z/instance.cfg", "MultiMC instance.cfg", "Git")
copy_file(mmc_path + "mmc-pack.json", git_path + "MultiMC\Fabulously Optimized x.y.z/mmc-pack.json", "MultiMC mmc-pack.json", "Git")
copy_file(mmc_path + "pack.png", git_path + "MultiMC\Fabulously Optimized x.y.z/pack.png", "MultiMC pack.png", "Git")
version = "0.0.0"
pattern = re.compile(r"\d+\.\d+\.\d+-?\w*\.?\d*")
with open(mmc_path + "instance.cfg") as file:
if match := pattern.search(file.read()):
version = match.group()
with open(git_path + "/MultiMC/Fabulously Optimized x.y.z/instance.cfg", "r+") as file:
data = pattern.sub(version, file.read())
file.seek(0); file.truncate(); file.write(data)
copy_to_archive(git_path + "/MultiMC/Fabulously Optimized x.y.z/instance.cfg", f"Fabulously Optimized {version}/instance.cfg", output_path + f"Fabulously Optimized {version}.zip")
copy_file(mmc_path + "mmc-pack.json", git_path + "MultiMC/Fabulously Optimized x.y.z/mmc-pack.json", "MultiMC mmc-pack.json", "Git")
copy_file(mmc_path + "pack.png", git_path + "MultiMC/Fabulously Optimized x.y.z/pack.png", "MultiMC pack.png", "Git")