From fd851bbe8355613f45c5e95eb685495c6c8b049b Mon Sep 17 00:00:00 2001 From: Daniel Mach Date: Mon, 2 Jan 2023 15:05:35 +0100 Subject: [PATCH] aggregatepac: Migrate to pop_project_package_targetproject_targetpackage_from_args() --- behave/features/aggregatepac.feature | 23 +++++++++++++++++++++++ osc/commandline.py | 23 ++++++++--------------- osc/core.py | 3 +++ 3 files changed, 34 insertions(+), 15 deletions(-) create mode 100644 behave/features/aggregatepac.feature diff --git a/behave/features/aggregatepac.feature b/behave/features/aggregatepac.feature new file mode 100644 index 00000000..f5a258c1 --- /dev/null +++ b/behave/features/aggregatepac.feature @@ -0,0 +1,23 @@ +Feature: `osc aggregatepac` command + + +# common steps for all scenarios +Background: + Given I set working directory to "{context.osc.temp}" + + +@destructive +Scenario: Run `osc aggregatepac / ` + When I execute osc with args "aggregatepac test:factory/test-pkgA home:Admin" + Then the exit code is 0 + + +@destructive +Scenario: Run `osc aggregatepac / /` + When I execute osc with args "aggregatepac test:factory/test-pkgA home:Admin/test-pkgAA" + Then the exit code is 0 + + +Scenario: Run `osc aggregatepac` where the source and target are the same + When I execute osc with args "aggregatepac test:factory/test-pkgA test:factory" + Then the exit code is 1 diff --git a/osc/commandline.py b/osc/commandline.py index e3a5407d..70762404 100644 --- a/osc/commandline.py +++ b/osc/commandline.py @@ -3100,21 +3100,14 @@ Please submit there instead, or use --nodevelproject to force direct submission. osc aggregatepac SOURCEPRJ SOURCEPAC[:FLAVOR] DESTPRJ [DESTPAC] """ - args = slash_split(args) + args = list(args) + src_project, src_package, tgt_project, tgt_package = pop_project_package_targetproject_targetpackage_from_args( + args, target_package_is_optional=True, + ) + ensure_no_remaining_args(args) - if not args or len(args) < 3: - self.argparse_error("Incorrect number of arguments.") - - src_project = self._process_project_name(args[0]) - src_package = args[1] - dst_project = self._process_project_name(args[2]) - if len(args) > 3: - dst_package = args[3] - else: - dst_package = src_package - - if src_project == dst_project and src_package == dst_package: - raise oscerr.WrongArgs('Error: source and destination are the same.') + if not tgt_package: + tgt_package = src_package repo_map = {} if opts.map_repo: @@ -3124,7 +3117,7 @@ Please submit there instead, or use --nodevelproject to force direct submission. raise oscerr.WrongOptions('map "%s" must be SRC=TARGET[,SRC=TARGET]' % opts.map_repo) repo_map[src_tgt[0]] = src_tgt[1] - aggregate_pac(src_project, src_package, dst_project, dst_package, repo_map, opts.disable_publish, opts.nosources) + aggregate_pac(src_project, src_package, tgt_project, tgt_package, repo_map, opts.disable_publish, opts.nosources) @cmdln.option('-c', '--client-side-copy', action='store_true', help='do a (slower) client-side copy') diff --git a/osc/core.py b/osc/core.py index 168e8655..2c110d80 100644 --- a/osc/core.py +++ b/osc/core.py @@ -5631,6 +5631,9 @@ def aggregate_pac( - "map" is a dictionary SRC => TARGET repository mappings - "repo_check" determines if presence of repos in the source and destination repos is checked """ + if (src_project, src_package) == (dst_project, dst_package): + raise oscerr.OscValueError("Cannot aggregate package. Source and target are the same.") + meta_change = False dst_meta = '' apiurl = conf.config['apiurl']