added logging

This commit is contained in:
embed@git.macaw.me
2023-12-21 19:42:13 +00:00
parent f7303dce15
commit 06cffbdbd7
14 changed files with 321 additions and 51 deletions

View File

@@ -14,6 +14,8 @@ import hashlib
import progressbar
from urllib.request import urlretrieve
import tempfile
from gentooimgr import LOG
import gentooimgr.config as config
from gentooimgr.common import older_than_a_day
@@ -75,12 +77,14 @@ def verify(args, _type: str, baseurl: str, hashpattern, filename: str) -> bool:
Whether iso was verified using the specified hash
"""
digest = hashlib.file_digest(open(os.path.join(args.download_dir, filename), 'rb'), _type.lower())
thefile = os.path.join(args.download_dir, filename)
LOG.info(f"verifying hash of {thefile}")
digest = hashlib.file_digest(open(thefile, 'rb'), _type.lower())
filename = filename+f".{_type.lower()}" # Update to hash file
hashfile = os.path.join(baseurl, filename)
fullpath = os.path.join(args.download_dir, os.path.basename(hashfile))
if not os.path.exists(fullpath) or args.redownload or older_than_a_day(fullpath):
print(f"Downloading {filename}")
LOG.info(f"Downloading {filename}")
urlretrieve(hashfile, fullpath, DownloadProgressBar())
hd = digest.hexdigest()
@@ -110,7 +114,7 @@ def download_stage3(args, url=None) -> str:
filename = latest
fullpath = os.path.join(args.download_dir, filename)
if not os.path.exists(fullpath) or args.redownload:
print(f"Downloading {filename}")
LOG.info(f"Downloading {filename}")
url = os.path.join(
config.GENTOO_BASE_STAGE_SYSTEMD_URL if args.profile == "systemd" else \
config.GENTOO_BASE_STAGE_OPENRC_URL,
@@ -145,7 +149,7 @@ def download_portage(args, url=None) -> str:
fullpath = os.path.join(args.download_dir, filename)
# Portage is always "latest" in this case, so definitely check if older than a day and redownload.
if not os.path.exists(fullpath) or args.redownload or older_than_a_day(fullpath):
print(f"Downloading {filename} ({base})")
LOG.info(f"Downloading {filename} ({base})")
urlretrieve(url, fullpath, DownloadProgressBar())
return fullpath
@@ -169,7 +173,7 @@ def download(args, url=None) -> str:
filename = os.path.basename(url)
fullpath = os.path.join(args.download_dir, filename)
if not os.path.exists(fullpath) or args.redownload or older_than_a_day(fullpath):
print(f"Downloading {filename}")
LOG.info(f"Downloading {fullpath}")
urlretrieve(url, fullpath, DownloadProgressBar())
hashtype, latest, size = parse_latest_iso_text(fullpath)
@@ -178,8 +182,8 @@ def download(args, url=None) -> str:
# Download the iso file
filename = latest
fullpath = os.path.join(args.download_dir, filename)
if not os.path.exists(fullpath) or args.redownload :
print(f"Downloading {filename}")
if not os.path.exists(fullpath) or args.redownload:
LOG.info(f"Downloading {filename}")
url = os.path.join(config.GENTOO_BASE_ISO_URL, filename)
urlretrieve(url, fullpath, DownloadProgressBar())