1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-11-12 23:56:13 +01:00

Move addcontainers code from commandline to _private

This commit is contained in:
Daniel Mach 2022-11-09 08:57:47 +01:00
parent 6dcc45f272
commit 2f70408dea
6 changed files with 97 additions and 19 deletions

View File

@ -0,0 +1,24 @@
Feature: `osc addcontainers` command
# common steps for all scenarios
Background:
Given I set working directory to "{context.osc.temp}"
And I execute osc with args "checkout test:factory test-pkgA"
And I set working directory to "{context.osc.temp}/test:factory/test-pkgA"
Scenario: Run `osc addcontainers`
When I execute osc with args "addcontainers"
Then stdout is
"""
Adding containers to package 'test:factory/test-pkgA'
"""
Scenario: Run `osc addcontainers --extend-package-names`
When I execute osc with args "addcontainers --extend-package-names"
Then stdout is
"""
Adding containers to package 'test:factory/test-pkgA' options: extend-package-names
"""

View File

@ -0,0 +1,17 @@
Feature: `osc addcontainers` command
# common steps for all scenarios
Background:
Given I set working directory to "{context.osc.temp}"
And I execute osc with args "checkout test:factory"
And I set working directory to "{context.osc.temp}/test:factory"
Scenario: Run `osc addcontainers`
When I execute osc with args "addcontainers"
Then the exit code is 1
And stderr is
"""
Directory '{context.osc.temp}/test:factory' is not a working copy of a package
"""

View File

@ -0,0 +1,30 @@
Feature: `osc addcontainers` command
# common steps for all scenarios
Background:
Given I set working directory to "{context.osc.temp}"
Scenario: Run `osc addcontainers <project> <package>`
When I execute osc with args "addcontainers test:factory test-pkgA"
Then stdout is
"""
Adding containers to package 'test:factory/test-pkgA'
"""
Scenario: Run `osc addcontainers <project>/<package>`
When I execute osc with args "addcontainers test:factory/test-pkgA"
Then stdout is
"""
Adding containers to package 'test:factory/test-pkgA'
"""
Scenario: Run `osc addcontainers <project> <package> --extend-package-names`
When I execute osc with args "addcontainers test:factory test-pkgA --extend-package-names"
Then stdout is
"""
Adding containers to package 'test:factory/test-pkgA' options: extend-package-names
"""

View File

@ -4,6 +4,7 @@
# The cherry-picked imports will be the supported API.
from .api_source import add_channels
from .api_source import add_containers
from .api_source import enable_channels
from .common import print_msg
from .common import format_msg_project_package_options

View File

@ -30,6 +30,24 @@ def add_channels(apiurl, project, package=None, enable_all=False, skip_disabled=
return api.post(apiurl, url_path, url_query)
def add_containers(apiurl, project, package, extend_package_names=False, print_to="debug"):
msg = format_msg_project_package_options(
"Adding containers to",
project,
package,
extend_package_names=extend_package_names,
)
print_msg(msg, print_to=print_to)
url_path = ["source", project, package]
url_query = {"cmd": "addcontainers"}
if extend_package_names:
url_query["extend_package_names"] = "1"
return api.post(apiurl, url_path, url_query)
def enable_channels(apiurl, project, package=None, print_to="debug"):
msg = format_msg_project_package_options(
"Enabling channels in",

View File

@ -595,28 +595,16 @@ class Osc(cmdln.Cmdln):
osc addcontainers [PROJECT PACKAGE]
"""
args = slash_split(args)
apiurl = self.get_api_url()
localdir = Path.cwd()
project = package = None
if not args:
if is_package_dir(localdir):
project = store_read_project(localdir)
package = store_read_package(localdir)
elif len(args) == 2:
project = self._process_project_name(args[0])
package = args[1]
if project is None or package is None:
raise oscerr.WrongArgs('Either specify project and package or call it from a package working copy')
args = list(args)
project, package = pop_project_package_from_args(
args, default_project=".", default_package=".", package_is_optional=False
)
query = {'cmd': 'addcontainers'}
if opts.extend_package_names:
query['extend_package_names'] = '1'
print("Add containers...")
url = makeurl(apiurl, ['source', project, package], query=query)
f = http_POST(url)
_private.add_containers(
apiurl, project, package, extend_package_names=opts.extend_package_names, print_to="stdout"
)
@cmdln.option('-s', '--skip-disabled', action='store_true',
help='Skip disabled channels. Otherwise the source gets added, but not the repositories.')