@@ -73,6 +73,19 @@ def has_bomin(cls, args):
7373 return args .bomin is not None
7474
7575
76+ class PkgStreamInput :
77+ """
78+ Mixin that takes a pkgstream as input. A pkgstream is either a stream
79+ of newline separated tuples "<pkg-name> <pkg-version> <pkg-arch>" or a
80+ stream of newline separated debian PURLs.
81+ """
82+
83+ @classmethod
84+ def get_pkgstream_resolver (cls ):
85+ warn_if_tty ()
86+ return PackageStreamResolver (sys .stdin )
87+
88+
7689class GenerateCmd :
7790 """
7891 Generate SBOMs from the dpkg package list
@@ -194,7 +207,7 @@ def setup_parser(parser):
194207 )
195208
196209
197- class DownloadCmd (SbomInput ):
210+ class DownloadCmd (SbomInput , PkgStreamInput ):
198211 """
199212 Processes a SBOM and downloads the referenced packages.
200213 If no SBOM is provided, it reads line separated entries (name version arch)
@@ -228,8 +241,7 @@ def run(cls, args):
228241 if cls .has_bomin (args ):
229242 resolver = cls .get_sbom_resolver (args )
230243 else :
231- warn_if_tty ()
232- resolver = PackageStreamResolver (sys .stdin )
244+ resolver = cls .get_pkgstream_resolver ()
233245 rs = requests .Session ()
234246 rs .headers .update ({"User-Agent" : f"debsbom/{ version ('debsbom' )} " })
235247 sdl = sdlclient .SnapshotDataLake (session = rs )
@@ -272,7 +284,7 @@ def setup_parser(cls, parser):
272284 parser .add_argument ("--binaries" , help = "download binary packages" , action = "store_true" )
273285
274286
275- class MergeCmd (SbomInput ):
287+ class MergeCmd (SbomInput , PkgStreamInput ):
276288 """
277289 Processes an SBOM and merges the .orig and .debian tarballs. The tarballs have to be
278290 downloaded first.
@@ -286,8 +298,7 @@ def run(cls, args):
286298 if cls .has_bomin (args ):
287299 resolver = cls .get_sbom_resolver (args )
288300 else :
289- warn_if_tty ()
290- resolver = PackageStreamResolver (sys .stdin )
301+ resolver = cls .get_pkgstream_resolver ()
291302 merger = SourceArchiveMerger (pkgdir , outdir , compress )
292303 pkgs = list (resolver .sources ())
293304
0 commit comments