Rename hash function name

This commit is contained in:
jimmy 2021-08-01 02:12:50 +00:00
parent da0ae0136e
commit 5c63add3b2
3 changed files with 18 additions and 12 deletions

View File

@ -27,7 +27,7 @@ async def hook(req: Request):
pack.pull() pack.pull()
pack.collate() pack.collate()
pack.compress() pack.compress()
pack.hash() pack.hashPack()
pack.upload() pack.upload()
return "Updated " + pack.gethash() return "Updated " + pack.gethash()

View File

@ -49,18 +49,24 @@ class Pack:
print("Compressing") print("Compressing")
shutil.make_archive("files/pack", 'zip', "files/pack") shutil.make_archive("files/pack", 'zip', "files/pack")
shutil.rmtree("files/pack") shutil.rmtree("files/pack")
print("Compressed")
def hash(self): def hashPack(self):
print("Hashing") try:
sha1sum = hashlib.sha1() print("Hashing")
with open("files/pack.zip", "rb") as pack: sha1sum = hashlib.sha1()
block = pack.read(2**16) with open("files/pack.zip", "rb") as pack:
while len(block) != 0:
sha1sum.update(block)
block = pack.read(2**16) block = pack.read(2**16)
self.hash = sha1sum.hexdigest() while len(block) != 0:
with open("files/hash", 'w') as hashfile: sha1sum.update(block)
hashfile.write(self.hash) block = pack.read(2**16)
self.hash = sha1sum.hexdigest()
print("Write hash")
with open("files/hash", 'w') as hashfile:
hashfile.write(self.hash)
except Exception:
print("Failed to hash")
def upload(self): def upload(self):
print("Uploading") print("Uploading")

View File

@ -7,6 +7,6 @@ def test_pack():
pack.pull() pack.pull()
pack.collate() pack.collate()
pack.compress() pack.compress()
pack.hash() pack.hashPack()
pack.upload() pack.upload()