Skip to content

Commit a45ba32

Browse files
Urist-McGitfmoessbauer
authored andcommitted
feat(download): add new --skip-pkgs option
Any packages that are passed in --skip-pkgs are excluded from the download. We accept the usual package-list universal ingress. This feature might be useful for users who do not want to leak some internal component name to snapshot.debian.org. Signed-off-by: Christoph Steiger <[email protected]>
1 parent 6ac588a commit a45ba32

File tree

1 file changed

+21
-2
lines changed

1 file changed

+21
-2
lines changed

src/debsbom/commands/download.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,13 @@
33
# SPDX-License-Identifier: MIT
44

55
from importlib.metadata import version
6+
from io import BytesIO
67
import logging
78
from pathlib import Path
89

910
from .input import PkgStreamInput, SbomInput
1011
from ..dpkg import package
12+
from ..resolver.resolver import PackageStreamResolver
1113
from ..util.progress import progress_cb
1214

1315
try:
@@ -51,7 +53,12 @@ def _check_for_dsc(p, files):
5153
logger.warning(f"no .dsc file found for {p}")
5254

5355
@staticmethod
54-
def _filter_pkg(p: package.Package, sources: bool, binaries: bool) -> bool:
56+
def _filter_pkg(
57+
p: package.Package, sources: bool, binaries: bool, skip: list[package.Package] | None = None
58+
) -> bool:
59+
if skip and p in skip:
60+
return False
61+
5562
if not sources and not binaries:
5663
return True
5764
if sources and p.is_source():
@@ -74,7 +81,14 @@ def run(cls, args):
7481
sdl = sdlclient.SnapshotDataLake(session=rs)
7582
u_resolver = UpstreamResolver(sdl, cache)
7683
downloader = PackageDownloader(args.outdir, session=rs)
77-
pkgs = list(filter(lambda p: cls._filter_pkg(p, args.sources, args.binaries), resolver))
84+
85+
if args.skip_pkgs:
86+
skip = list(PackageStreamResolver(BytesIO(args.skip_pkgs.encode())))
87+
else:
88+
skip = None
89+
pkgs = list(
90+
filter(lambda p: cls._filter_pkg(p, args.sources, args.binaries, skip), resolver)
91+
)
7892

7993
logger.info("Resolving upstream packages...")
8094
for idx, pkg in enumerate(pkgs):
@@ -115,3 +129,8 @@ def setup_parser(cls, parser):
115129
)
116130
parser.add_argument("--sources", help="download source packages", action="store_true")
117131
parser.add_argument("--binaries", help="download binary packages", action="store_true")
132+
parser.add_argument(
133+
"--skip-pkgs",
134+
metavar="SKIP",
135+
help="packages to exclude from the download, in package-list format",
136+
)

0 commit comments

Comments
 (0)