From b78b6ad56809b5d753d0d15cd275c24667004e8a Mon Sep 17 00:00:00 2001 From: Daniel Mach Date: Thu, 20 Jun 2024 08:54:01 +0200 Subject: [PATCH] Improve 'getbinaries' command by accepting '-M' / '--multibuild-package' option outside checkouts --- ...ies-project-package-repo-arch-file.feature | 6 ++++-- ...binaries-project-package-repo-arch.feature | 9 +++++++-- .../getbinaries-project-repo-arch.feature | 9 +++++++-- .../getbinaries-repo-arch-prjcheckout.feature | 9 +++++++-- .../getbinaries-repo-prjcheckout.feature | 10 ++++++++-- osc/commandline.py | 19 ++++++++++++------- 6 files changed, 45 insertions(+), 17 deletions(-) diff --git a/behave/features/getbinaries-project-package-repo-arch-file.feature b/behave/features/getbinaries-project-package-repo-arch-file.feature index 2e816f8135..7c13e2e43a 100644 --- a/behave/features/getbinaries-project-package-repo-arch-file.feature +++ b/behave/features/getbinaries-project-package-repo-arch-file.feature @@ -16,8 +16,10 @@ Scenario: Run `osc getbinaries ` Scenario: Run `osc getbinaries --multibuild-package=` When I execute osc with args "getbinaries test:factory multibuild-pkg standard x86_64 multibuild-pkg-flavor1-1-1.x86_64.rpm --multibuild-package=flavor1" - # the option is allowed only in a package checkout - Then the exit code is 2 + Then directory listing of "{context.osc.temp}/binaries/" is + """ + multibuild-pkg-flavor1-1-1.x86_64.rpm + """ Scenario: Run `osc getbinaries : ` where file is a package diff --git a/behave/features/getbinaries-project-package-repo-arch.feature b/behave/features/getbinaries-project-package-repo-arch.feature index 3865433746..69e6d5350d 100644 --- a/behave/features/getbinaries-project-package-repo-arch.feature +++ b/behave/features/getbinaries-project-package-repo-arch.feature @@ -19,8 +19,13 @@ Scenario: Run `osc getbinaries ` Scenario: Run `osc getbinaries --multibuild-package=` When I execute osc with args "getbinaries test:factory multibuild-pkg standard x86_64 --multibuild-package=flavor1" - # the option is allowed only in a package checkout - Then the exit code is 2 + Then directory listing of "{context.osc.temp}/binaries/" is + """ + multibuild-pkg-flavor1-1-1.x86_64.rpm + _buildenv + _statistics + rpmlint.log + """ Scenario: Run `osc getbinaries : ` diff --git a/behave/features/getbinaries-project-repo-arch.feature b/behave/features/getbinaries-project-repo-arch.feature index 689c323c18..00e2fad68f 100644 --- a/behave/features/getbinaries-project-repo-arch.feature +++ b/behave/features/getbinaries-project-repo-arch.feature @@ -35,8 +35,13 @@ Scenario: Run `osc getbinaries ` Scenario: Run `osc getbinaries --multibuild-package=` When I execute osc with args "getbinaries test:factory standard x86_64 --multibuild-package=flavor1" - # the option is allowed only in a package checkout - Then the exit code is 2 + Then directory tree in "{context.osc.temp}/binaries/" is + """ + multibuild-pkg-flavor1-1-1.x86_64.rpm + multibuild-pkg:flavor1/_buildenv + multibuild-pkg:flavor1/_statistics + multibuild-pkg:flavor1/rpmlint.log + """ Scenario: Run `osc getbinaries --debuginfo` diff --git a/behave/features/getbinaries-repo-arch-prjcheckout.feature b/behave/features/getbinaries-repo-arch-prjcheckout.feature index 281472751d..38835e3370 100644 --- a/behave/features/getbinaries-repo-arch-prjcheckout.feature +++ b/behave/features/getbinaries-repo-arch-prjcheckout.feature @@ -37,8 +37,13 @@ Scenario: Run `osc getbinaries ` from a project checkout Scenario: Run `osc getbinaries --multibuild-package=` from a project checkout When I execute osc with args "getbinaries standard x86_64 --multibuild-package=flavor1" - # the option is allowed only in a package checkout - Then the exit code is 2 + Then directory tree in "{context.osc.temp}/test:factory/binaries/" is + """ + multibuild-pkg-flavor1-1-1.x86_64.rpm + multibuild-pkg:flavor1/_buildenv + multibuild-pkg:flavor1/_statistics + multibuild-pkg:flavor1/rpmlint.log + """ Scenario: Run `osc getbinaries --sources` from a project checkout diff --git a/behave/features/getbinaries-repo-prjcheckout.feature b/behave/features/getbinaries-repo-prjcheckout.feature index c7bb918a95..808a94c28a 100644 --- a/behave/features/getbinaries-repo-prjcheckout.feature +++ b/behave/features/getbinaries-repo-prjcheckout.feature @@ -40,8 +40,14 @@ Scenario: Run `osc getbinaries ` from a project checkout Scenario: Run `osc getbinaries --multibuild-package=` from a project checkout When I execute osc with args "getbinaries standard --multibuild-package=flavor1" - # the option is allowed only in a package checkout - Then the exit code is 2 + Then directory tree in "{context.osc.temp}/test:factory/binaries/" is + """ + multibuild-pkg-flavor1-1-1.i586.rpm + multibuild-pkg-flavor1-1-1.x86_64.rpm + multibuild-pkg:flavor1/_buildenv + multibuild-pkg:flavor1/_statistics + multibuild-pkg:flavor1/rpmlint.log + """ Scenario: Run `osc getbinaries --sources` from a project checkout diff --git a/osc/commandline.py b/osc/commandline.py index 860754be33..4f56c8aa3f 100644 --- a/osc/commandline.py +++ b/osc/commandline.py @@ -8135,9 +8135,6 @@ def do_getbinaries(self, subcmd, opts, *args): package = None binary = None - if opts.multibuild_package and ((len(args) > 2) or (len(args) <= 2 and is_project_dir(Path.cwd()))): - self.argparse_error("The -M/--multibuild-package option can be only used from a package checkout.") - if len(args) < 1 and is_package_dir('.'): self.print_repos() @@ -8177,13 +8174,21 @@ def do_getbinaries(self, subcmd, opts, *args): if package is None: package_specified = False package = meta_get_packagelist(apiurl, project, deleted=0) + if opts.multibuild_package: + # remove packages that do not have matching flavor + for i in package.copy(): + package_flavor = i.rsplit(":", 1) + # package has flavor, check if the flavor is in opts.multibuild_packages + flavor_match = len(package_flavor) == 2 and package_flavor[1] in opts.multibuild_package + # package nas no flavor, check if "" is in opts.multibuild_package + no_flavor_match = len(package_flavor) == 1 and "" in opts.multibuild_package + if not flavor_match and not no_flavor_match: + package.remove(i) else: package_specified = True if opts.multibuild_package: - packages = [] - for subpackage in opts.multibuild_package: - packages.append(package + ":" + subpackage) - package = packages + resolver = MultibuildFlavorResolver(apiurl, project, package, use_local=False) + package = resolver.resolve_as_packages(opts.multibuild_package) else: package = [package]