From c70bf9a8c2b3dec463fb9bf01e6c43c36e0e9e6c Mon Sep 17 00:00:00 2001 From: jimmy Date: Tue, 25 May 2021 02:22:30 +0000 Subject: [PATCH] Add resource pack processing --- src/pack.py | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) create mode 100644 src/pack.py diff --git a/src/pack.py b/src/pack.py new file mode 100644 index 0000000..4b780eb --- /dev/null +++ b/src/pack.py @@ -0,0 +1,60 @@ +import os +import re +import shutil +import zipfile +import hashlib +from dotenv import load_dotenv + +class Pack: + def __init__(self): + load_dotenv() + self.repourl = os.environ.get("RESOURCE_PACK_URL") + command = "git clone git@github.com:" + self.repourl + self.dir = re.split("/|\.", self.repourl)[1] + status = os.system(command) + print(status) + + def __del__(self): + shutil.rmtree(self.dir) + + def pull(self) -> None: + + os.system("git -C {} pull origin master".format(self.dir)) + + def collate(self) -> None: + if os.path.exists("pack"): + shutil.rmtree("pack") + os.mkdir("pack") + shutil.copytree(self.dir+"/assets", "pack/assets") + shutil.copy("ResourcePack/pack.mcmeta", "pack/pack.mcmeta") + shutil.copy("ResourcePack/pack.png", "pack/pack.png") + + + def compress(self) -> None: + if not os.path.exists("files"): + os.mkdir("files") + os.system("zip -r files/pack.zip pack") + shutil.rmtree("pack") + + def hash(self): + sha1sum = hashlib.sha1() + with open("files/pack.zip", "rb") as pack: + block = pack.read(2**16) + while len(block) != 0: + sha1sum.update(block) + block = pack.read(2**16) + self.hash = sha1sum.hexdigest() + with open("files/hash", 'w') as hashfile: + hashfile.write(self.hash) + + + +if __name__ == "__main__": + from dotenv import load_dotenv + load_dotenv() + pack = Pack() + pack.pull() + pack.collate() + pack.compress() + pack.hash() + #pack = None \ No newline at end of file