Support extract bin from gz. (github releases)

This commit is contained in:
Jordan ERNST 2022-04-26 10:22:36 +02:00
parent 36c46920ec
commit 78bebf19d5

View File

@ -9,6 +9,7 @@ import subprocess
from io import BytesIO from io import BytesIO
import zipfile import zipfile
import rpmfile import rpmfile
import gzip
def compute_file_hash(filepath): def compute_file_hash(filepath):
@ -53,6 +54,9 @@ def extract_bin(archtype, binpath, destpath, content):
with open(destpath, 'wb') as f: with open(destpath, 'wb') as f:
f.write(fd.read()) f.write(fd.read())
elif archtype == 'gz':
with open(destpath, 'wb') as f:
f.write(gzip.decompress(content))
ioobj.close() ioobj.close()
@ -87,14 +91,27 @@ def githubreleasesync(reponame, repoinfo, credz):
filenames = repoinfo['files'] filenames = repoinfo['files']
for filename in filenames: for filename in filenames:
localfile = pathlib.Path('files').joinpath(pathlib.Path(filename).name) if isinstance(filename, dict):
binpath = filename['binpath']
filename = filename['filename']
localfile = pathlib.Path('files').joinpath(pathlib.Path(binpath).name)
if filename.endswith('.gz'):
is_gz = True
print(f" * {localfile} ", end='')
else:
localfile = pathlib.Path('files').joinpath(pathlib.Path(filename).name)
print(f" * {localfile} ", end='')
urldl = f'https://github.com/{reponame}/releases/download/{last_version}/{filename}' urldl = f'https://github.com/{reponame}/releases/download/{last_version}/{filename}'
print(f" * {localfile} ", end='')
if not localfile.exists(): if not localfile.exists():
content = requests.get(urldl, auth=credz).content content = requests.get(urldl, auth=credz).content
with open(localfile, 'wb') as f: if is_gz:
f.write(content) extract_bin('gz', binpath, localfile, content)
else:
with open(localfile, 'wb') as f:
f.write(content)
print('-> Installed! ;)') print('-> Installed! ;)')
else: else:
@ -103,8 +120,11 @@ def githubreleasesync(reponame, repoinfo, credz):
else: else:
content = requests.get(urldl, auth=credz).content content = requests.get(urldl, auth=credz).content
with open(localfile, 'wb') as f: if is_gz:
f.write(content) extract_bin('gz', binpath, localfile, content)
else:
with open(localfile, 'wb') as f:
f.write(content)
print('-> Updated!') print('-> Updated!')
with open("config.json", "r") as jsonfile: with open("config.json", "r") as jsonfile: