forked from Mirror/pmbootstrap
treewide: adopt pathlib.Path and type hinting (MR 2252)
With the new chroot type, we can now write fancy paths in the pythonic way. Convert most of the codebase over, as well as adding various other type hints. Signed-off-by: Caleb Connolly <caleb@postmarketos.org>
This commit is contained in:
parent
00383bf354
commit
31cc898dd5
64 changed files with 513 additions and 385 deletions
|
@ -4,12 +4,17 @@ import hashlib
|
|||
import json
|
||||
from pmb.helpers import logging
|
||||
import os
|
||||
from pathlib import Path
|
||||
import shutil
|
||||
import urllib.request
|
||||
|
||||
from pmb.core.types import PmbArgs
|
||||
import pmb.helpers.run
|
||||
|
||||
def cache_file(prefix: str, url: str) -> Path:
|
||||
prefix = prefix.replace("/", "_")
|
||||
return Path(f"{prefix}_{hashlib.sha256(url.encode('utf-8')).hexdigest()}")
|
||||
|
||||
|
||||
def download(args: PmbArgs, url, prefix, cache=True, loglevel=logging.INFO,
|
||||
allow_404=False):
|
||||
|
@ -33,9 +38,7 @@ def download(args: PmbArgs, url, prefix, cache=True, loglevel=logging.INFO,
|
|||
pmb.helpers.run.user(args, ["mkdir", "-p", pmb.config.work / "cache_http"])
|
||||
|
||||
# Check if file exists in cache
|
||||
prefix = prefix.replace("/", "_")
|
||||
path = (pmb.config.work / "cache_http/" + prefix + "_" +
|
||||
hashlib.sha256(url.encode("utf-8")).hexdigest())
|
||||
path = pmb.config.work / "cache_http" / cache_file(prefix, url)
|
||||
if os.path.exists(path):
|
||||
if cache:
|
||||
return path
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue