diff --git a/behave/features/addchannels-pkgcheckout.feature b/behave/features/addchannels-pkgcheckout.feature new file mode 100644 index 00000000..54013d22 --- /dev/null +++ b/behave/features/addchannels-pkgcheckout.feature @@ -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 + """ diff --git a/behave/features/addchannels-prjcheckout.feature b/behave/features/addchannels-prjcheckout.feature new file mode 100644 index 00000000..a968e7fb --- /dev/null +++ b/behave/features/addchannels-prjcheckout.feature @@ -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 + """ diff --git a/behave/features/addchannels-project-package.feature b/behave/features/addchannels-project-package.feature new file mode 100644 index 00000000..34c13786 --- /dev/null +++ b/behave/features/addchannels-project-package.feature @@ -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 ` + 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 /` + 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 --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 --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 + """ diff --git a/behave/features/addchannels-project.feature b/behave/features/addchannels-project.feature new file mode 100644 index 00000000..2c1a6cf7 --- /dev/null +++ b/behave/features/addchannels-project.feature @@ -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 ` + When I execute osc with args "addchannels test:factory" + Then stdout is + """ + Adding channels to project: 'test:factory' + """ + + +Scenario: Run `osc addchannels --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 --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 + """ + diff --git a/osc/_private/__init__.py b/osc/_private/__init__.py index 6c4d4302..32eaa0cb 100644 --- a/osc/_private/__init__.py +++ b/osc/_private/__init__.py @@ -3,6 +3,7 @@ # # The cherry-picked imports will be the supported API. +from .api_source import add_channels from .common import print_msg from .common import format_msg_project_package_options from .package import ApiPackage diff --git a/osc/_private/api_source.py b/osc/_private/api_source.py new file mode 100644 index 00000000..f1e7abb7 --- /dev/null +++ b/osc/_private/api_source.py @@ -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) diff --git a/osc/commandline.py b/osc/commandline.py index 10296ed9..a4d91e66 100644 --- a/osc/commandline.py +++ b/osc/commandline.py @@ -629,36 +629,19 @@ class Osc(cmdln.Cmdln): Examples: osc addchannels [PROJECT [PACKAGE]] """ - - args = slash_split(args) 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: - raise oscerr.WrongOptions('--enable-all and --skip-disabled options are mutually exclusive') - elif opts.enable_all: - query['mode'] = 'enable_all' - elif opts.skip_disabled: - query['mode'] = 'skip_disabled' + self.argparse_error("Options '--enable-all' and '--skip-disabled' are mutually exclusive") - print("Looking for channels...") - url = makeurl(apiurl, ['source', project], query=query) - if channel: - url = makeurl(apiurl, ['source', project, channel], query=query) - f = http_POST(url) + _private.add_channels( + apiurl, project, package, enable_all=opts.enable_all, skip_disabled=opts.skip_disabled, print_to="stdout" + ) @cmdln.alias('enablechannel') def do_enablechannels(self, subcmd, opts, *args):