From 55fd77650deee4592d09ed03f50b1eb778339330 Mon Sep 17 00:00:00 2001 From: Daniel Mach Date: Mon, 2 Jan 2023 15:21:45 +0100 Subject: [PATCH] copypac: Migrate to pop_project_package_targetproject_targetpackage_from_args() --- behave/features/copypac.feature | 23 ++++++++++++++++++++++ osc/commandline.py | 34 ++++++++++++--------------------- osc/core.py | 4 ++++ 3 files changed, 39 insertions(+), 22 deletions(-) create mode 100644 behave/features/copypac.feature diff --git a/behave/features/copypac.feature b/behave/features/copypac.feature new file mode 100644 index 00000000..0d370f9a --- /dev/null +++ b/behave/features/copypac.feature @@ -0,0 +1,23 @@ +Feature: `osc copypac` command + + +# common steps for all scenarios +Background: + Given I set working directory to "{context.osc.temp}" + + +@destructive +Scenario: Run `osc copypac / ` + When I execute osc with args "copypac test:factory/test-pkgA home:Admin" + Then the exit code is 0 + + +@destructive +Scenario: Run `osc copypac / /` + When I execute osc with args "copypac test:factory/test-pkgA home:Admin/test-pkgAA" + Then the exit code is 0 + + +Scenario: Run `osc copypac` where the source and target are the same + When I execute osc with args "copypac test:factory/test-pkgA test:factory" + Then the exit code is 1 diff --git a/osc/commandline.py b/osc/commandline.py index 70762404..9a3d3f59 100644 --- a/osc/commandline.py +++ b/osc/commandline.py @@ -3156,30 +3156,26 @@ Please submit there instead, or use --nodevelproject to force direct submission. usage: osc copypac SOURCEPRJ SOURCEPAC DESTPRJ [DESTPAC] """ + 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) - args = slash_split(args) + if not tgt_package: + tgt_package = src_package - 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 src_apiurl = conf.config['apiurl'] if opts.to_apiurl: - dst_apiurl = conf.config['apiurl_aliases'].get(opts.to_apiurl, opts.to_apiurl) + tgt_apiurl = conf.config['apiurl_aliases'].get(opts.to_apiurl, opts.to_apiurl) else: - dst_apiurl = src_apiurl + tgt_apiurl = src_apiurl - if src_apiurl != dst_apiurl: + if src_apiurl != tgt_apiurl: opts.client_side_copy = True opts.expand = True - rev, dummy = parseRevisionOption(opts.revision) + rev, _ = parseRevisionOption(opts.revision) if opts.message: comment = opts.message @@ -3194,14 +3190,8 @@ Please submit there instead, or use --nodevelproject to force direct submission. if opts.client_side_copy: comment += ", using client side copy" - if src_project == dst_project and \ - src_package == dst_package and \ - not rev and \ - src_apiurl == dst_apiurl: - raise oscerr.WrongArgs('Source and destination are the same.') - r = copy_pac(src_apiurl, src_project, src_package, - dst_apiurl, dst_project, dst_package, + tgt_apiurl, tgt_project, tgt_package, client_side_copy=opts.client_side_copy, keep_maintainers=opts.keep_maintainers, keep_develproject=opts.keep_develproject, diff --git a/osc/core.py b/osc/core.py index 2c110d80..b74ea99e 100644 --- a/osc/core.py +++ b/osc/core.py @@ -5928,6 +5928,10 @@ def copy_pac( them into the other by uploading them (client-side copy) -- or by the server, in a single api call. """ + if (src_apiurl, src_project, src_package) == (dst_apiurl, dst_project, dst_package): + # copypac is also used to expand sources, let's allow that + if not expand: + raise oscerr.OscValueError("Cannot copy package. Source and target are the same.") if not (src_apiurl == dst_apiurl and src_project == dst_project and src_package == dst_package):