1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-11-10 22:56:15 +01:00

Move enablechannels code from commandline to _private

This commit is contained in:
Daniel Mach 2022-11-01 14:50:18 +01:00
parent ad85ff437f
commit 59e7013cf2
7 changed files with 95 additions and 27 deletions

View File

@ -0,0 +1,16 @@
Feature: `osc enablechannels` 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 enablechannels`
When I execute osc with args "enablechannels"
Then stdout is
"""
Enabling channels in project: 'test:factory' package: 'test-pkgA'
"""

View File

@ -0,0 +1,16 @@
Feature: `osc enablechannels` 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 enablechannels`
When I execute osc with args "enablechannels"
Then stdout is
"""
Enabling channels in project: 'test:factory'
"""

View File

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

View File

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

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 enable_channels
from .common import print_msg
from .common import format_msg_project_package_options
from .package import ApiPackage

View File

@ -28,3 +28,23 @@ def add_channels(apiurl, project, package=None, enable_all=False, skip_disabled=
url_query["mode"] = "skip_disabled"
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",
project,
package,
)
print_msg(msg, print_to=print_to)
url_path = ["source", project]
if package:
url_path += [package]
if package:
url_query = {"cmd": "enablechannel"}
else:
url_query = {"cmd": "modifychannels", "mode": "enable_all"}
return api.post(apiurl, url_path, url_query)

View File

@ -653,37 +653,16 @@ class Osc(cmdln.Cmdln):
The command can be used to enable a specific one or all channels of a project.
Examples:
osc enablechannels [PROJECT [CHANNEL_PACKAGE]]
osc enablechannels [PROJECT [PACKAGE]]
"""
args = slash_split(args)
apiurl = self.get_api_url()
localdir = Path.cwd()
channel = None
if not args:
if is_project_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])
if len(args) > 1:
channel = args[1]
query = {}
if channel:
query['cmd'] = 'enablechannel'
else:
query = {'cmd': 'modifychannels', 'mode': 'enable_all'}
args = list(args)
project, package = pop_project_package_from_args(
args, default_project=".", default_package=".", package_is_optional=True
)
print("Enable channel(s)...")
url = makeurl(apiurl, ['source', project], query=query)
if channel:
url = makeurl(apiurl, ['source', project, channel], query=query)
f = http_POST(url)
_private.enable_channels(apiurl, project, package, print_to="stdout")
@cmdln.option('-f', '--force', action='store_true',
help='force generation of new patchinfo file, do not update existing one.')