1
0
mirror of https://github.com/openSUSE/osc.git synced 2025-02-03 18:16:17 +01:00

Move addchannels code from commandline to _private

This commit is contained in:
Daniel Mach 2022-11-01 14:29:23 +01:00
parent 78c3cf1c4c
commit ad85ff437f
7 changed files with 172 additions and 25 deletions

View File

@ -0,0 +1,32 @@
Feature: `osc addchannels` 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 addchannels`
When I execute osc with args "addchannels"
Then stdout is
"""
Adding channels to project: 'test:factory' package: 'test-pkgA'
"""
Scenario: Run `osc addchannels --enable-all`
When I execute osc with args "addchannels --enable-all"
Then stdout is
"""
Adding channels to project: 'test:factory' package: 'test-pkgA' options: enable-all
"""
Scenario: Run `osc addchannels --skip-disabled`
When I execute osc with args "addchannels --skip-disabled"
Then stdout is
"""
Adding channels to project: 'test:factory' package: 'test-pkgA' options: skip-disabled
"""

View File

@ -0,0 +1,32 @@
Feature: `osc addchannels` 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 addchannels`
When I execute osc with args "addchannels"
Then stdout is
"""
Adding channels to project: 'test:factory'
"""
Scenario: Run `osc addchannels --enable-all`
When I execute osc with args "addchannels --enable-all"
Then stdout is
"""
Adding channels to project: 'test:factory' options: enable-all
"""
Scenario: Run `osc addchannels --skip-disabled`
When I execute osc with args "addchannels --skip-disabled"
Then stdout is
"""
Adding channels to project: 'test:factory' options: skip-disabled
"""

View File

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

View File

@ -0,0 +1,31 @@
Feature: `osc addchannels` command
# common steps for all scenarios
Background:
Given I set working directory to "{context.osc.temp}"
Scenario: Run `osc addchannels <project>`
When I execute osc with args "addchannels test:factory"
Then stdout is
"""
Adding channels to project: 'test:factory'
"""
Scenario: Run `osc addchannels <project> --enable-all`
When I execute osc with args "addchannels test:factory --enable-all"
Then stdout is
"""
Adding channels to project: 'test:factory' options: enable-all
"""
Scenario: Run `osc addchannels <project> --skip-disabled`
When I execute osc with args "addchannels test:factory --skip-disabled"
Then stdout is
"""
Adding channels to project: 'test:factory' options: skip-disabled
"""

View File

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

View File

@ -0,0 +1,30 @@
from . import api
from .common import format_msg_project_package_options
from .common import print_msg
from .. import oscerr
def add_channels(apiurl, project, package=None, enable_all=False, skip_disabled=False, print_to="debug"):
if all((enable_all, skip_disabled)):
raise oscerr.OscValueError("Options 'enable_all' and 'skip_disabled' are mutually exclusive")
msg = format_msg_project_package_options(
"Adding channels to",
project,
package,
enable_all=enable_all,
skip_disabled=skip_disabled,
)
print_msg(msg, print_to=print_to)
url_path = ["source", project]
if package:
url_path += [package]
url_query = {"cmd": "addchannels"}
if enable_all:
url_query["mode"] = "enable_all"
if skip_disabled:
url_query["mode"] = "skip_disabled"
return api.post(apiurl, url_path, url_query)

View File

@ -629,36 +629,19 @@ class Osc(cmdln.Cmdln):
Examples: Examples:
osc addchannels [PROJECT [PACKAGE]] osc addchannels [PROJECT [PACKAGE]]
""" """
args = slash_split(args)
apiurl = self.get_api_url() apiurl = self.get_api_url()
localdir = Path.cwd()
channel = None
if not args:
if is_project_dir(localdir) or is_package_dir(localdir):
project = store_read_project(localdir)
elif is_package_dir(localdir):
project = store_read_project(localdir)
channel = store_read_package(localdir)
else:
raise oscerr.WrongArgs('Either specify project [package] or call it from a project/package working copy')
else:
project = self._process_project_name(args[0])
query = {'cmd': 'addchannels'} args = list(args)
project, package = pop_project_package_from_args(
args, default_project=".", default_package=".", package_is_optional=True
)
if opts.enable_all and opts.skip_disabled: if opts.enable_all and opts.skip_disabled:
raise oscerr.WrongOptions('--enable-all and --skip-disabled options are mutually exclusive') self.argparse_error("Options '--enable-all' and '--skip-disabled' are mutually exclusive")
elif opts.enable_all:
query['mode'] = 'enable_all'
elif opts.skip_disabled:
query['mode'] = 'skip_disabled'
print("Looking for channels...") _private.add_channels(
url = makeurl(apiurl, ['source', project], query=query) apiurl, project, package, enable_all=opts.enable_all, skip_disabled=opts.skip_disabled, print_to="stdout"
if channel: )
url = makeurl(apiurl, ['source', project, channel], query=query)
f = http_POST(url)
@cmdln.alias('enablechannel') @cmdln.alias('enablechannel')
def do_enablechannels(self, subcmd, opts, *args): def do_enablechannels(self, subcmd, opts, *args):