summaryrefslogtreecommitdiff
path: root/mdbp/common.py
diff options
context:
space:
mode:
Diffstat (limited to 'mdbp/common.py')
-rw-r--r--mdbp/common.py27
1 files changed, 16 insertions, 11 deletions
diff --git a/mdbp/common.py b/mdbp/common.py
index 719a8b6..5c67f58 100644
--- a/mdbp/common.py
+++ b/mdbp/common.py
@@ -118,6 +118,11 @@ def download(uri: str, checksums: typing.Dict[str, str],
dest.unlink()
raise
+def parse_dsc(dscpath: pathlib.Path) -> debian.deb822.Dsc:
+ """Parse a dsc file."""
+ with dscpath.open("r") as dscf:
+ return debian.deb822.Dsc(dscf)
+
def download_dsc(buildinput: JsonObject,
destdir: pathlib.Path) -> pathlib.Path:
"""Download the .input.source_package_url including referenced components
@@ -130,12 +135,11 @@ def download_dsc(buildinput: JsonObject,
assert isinstance(dscpath, pathlib.Path)
download(dscuri, buildinput.get("checksums", {}), dscpath)
files: typing.Dict[str, typing.Dict[str, str]] = {}
- with dscpath.open("r") as dscf:
- for key, value in debian.deb822.Dsc(dscf).items():
- if key.lower().startswith("checksums-"):
- for entry in value:
- algo = key[10:].lower()
- files.setdefault(entry["name"], dict())[algo] = entry[algo]
+ for key, value in parse_dsc(dscpath).items():
+ if key.lower().startswith("checksums-"):
+ for entry in value:
+ algo = key[10:].lower()
+ files.setdefault(entry["name"], dict())[algo] = entry[algo]
for name, checksums in files.items():
download(urllib.parse.urljoin(dscuri, name), checksums, destdir / name)
return dscpath
@@ -155,11 +159,12 @@ def get_dsc(build: JsonObject) -> typing.Iterator[pathlib.Path]:
else:
yield pathlib.Path(dscpath)
-def get_dsc_files(dscpath: pathlib.Path) -> typing.List[pathlib.Path]:
- """Get the component names referenced by the .dsc file."""
- with dscpath.open("r") as dscf:
- dsc = debian.deb822.Dsc(dscf)
- return [dscpath.parent / item["name"] for item in dsc["Files"]]
+def get_dsc_files(dscpath: pathlib.Path,
+ dscobj: typing.Optional[debian.deb822.Dsc] = None) -> \
+ typing.List[pathlib.Path]:
+ """Get the component names referenced by the .dsc."""
+ return [dscpath.parent / item["name"]
+ for item in (dscobj or parse_dsc(dscpath))["Files"]]
def make_option(optname: str, value: typing.Optional[str]) -> typing.List[str]:
"""Construct a valued option if a value is given."""