diff --git a/mpcdf_enable_repositories.py b/mpcdf_enable_repositories.py index 556d97585fe46d8986817bcd64f46a1ebbae50e9..b40e81a5a9db380a1aab73f9898fcef0c50332b8 100644 --- a/mpcdf_enable_repositories.py +++ b/mpcdf_enable_repositories.py @@ -1,17 +1,16 @@ #!/usr/bin/python2 from __future__ import print_function -import sys -import argparse -from functools import partial from xml.etree import ElementTree -from mpcdf_common import * +import mpcdf_common +import os import osc import osc.conf import osc.core import osc.cmdln + @osc.cmdln.option('--cuda-mpi', action="store_true", help="Enable for all CUDA+MPI repositories") @osc.cmdln.option('--cuda', action="store_true", @@ -52,11 +51,11 @@ def do_mpcdf_enable_repositories(self, subcmd, opts, *args): """ if len(args) == 0: - if is_package_dir(os.curdir): + if osc.core.is_package_dir(os.curdir): package = osc.core.store_read_package(os.curdir) project = osc.core.store_read_project(os.curdir) else: - raise oscerr.WrongArgs('Specify PACKAGE or run command in an osc package checkout directory') + raise osc.oscerr.WrongArgs('Specify PACKAGE or run command in an osc package checkout directory') elif len(args) == 1: package, = args @@ -65,7 +64,7 @@ def do_mpcdf_enable_repositories(self, subcmd, opts, *args): elif len(args) == 2: project, package = args else: - raise oscerr.WrongArgs("Too many arguments") + raise osc.oscerr.WrongArgs("Too many arguments") api_url = self.get_api_url() @@ -96,9 +95,9 @@ def do_mpcdf_enable_repositories(self, subcmd, opts, *args): if opts.cuda_mpi: value("cuda_mpi") - set_attribute(api_url, (project, package), root) + mpcdf_common.set_attribute(api_url, (project, package), root) if opts.reset or opts.set: - mpcdf_enable_repositories(api_url, project, package, verbose=True) + mpcdf_common.mpcdf_enable_repositories(api_url, project, package, verbose=True) else: - print("Enabled for:", *get_attribute_values(api_url, project, package, "MPCDF:enable_repositories")) + print("Enabled for:", *mpcdf_common.get_attribute_values(api_url, project, package, "MPCDF:enable_repositories")) diff --git a/mpcdf_info.py b/mpcdf_info.py index f593121f39577c730db3ef975de8df9706fb3606..c8ff7cf41f14a4f7b941e2e620a048e73ed7ff1b 100644 --- a/mpcdf_info.py +++ b/mpcdf_info.py @@ -1,15 +1,18 @@ #!/usr/bin/python2 from __future__ import print_function -import sys -import argparse +from functools import reduce -from mpcdf_common import * +import mpcdf_common +import os import osc import osc.conf import osc.core import osc.cmdln +from xml.etree import ElementTree + + def do_mpcdf_info(self, subcmd, opts, *args): """${cmd_name}: Basic information about an MPCDF OBS project @@ -21,15 +24,15 @@ def do_mpcdf_info(self, subcmd, opts, *args): """ if len(args) == 0: - if is_project_dir(os.curdir) or is_package_dir(os.curdir): + if osc.core.is_project_dir(os.curdir) or osc.core.is_package_dir(os.curdir): project = osc.core.store_read_project(os.curdir) else: - raise oscerr.WrongArgs('Specify PROJECT or run command in an osc checkout directory') + raise osc.oscerr.WrongArgs('Specify PROJECT or run command in an osc checkout directory') elif len(args) == 1: project, = args else: - raise oscerr.WrongArgs("Too many arguments") + raise osc.oscerr.WrongArgs("Too many arguments") print("Project `{0}`\n".format(project)) @@ -37,8 +40,8 @@ def do_mpcdf_info(self, subcmd, opts, *args): def print_attribute(description, attribute): try: - values = list(sorted(get_attribute_values(api_url, project, None, attribute))) - except: + values = list(sorted(mpcdf_common.get_attribute_values(api_url, project, None, attribute))) + except Exception: print("This project unmanaged, i.e. it does not have the required MPCDF: attributes set") raise SystemExit(0) @@ -58,7 +61,7 @@ def do_mpcdf_info(self, subcmd, opts, *args): pkg_name_width = max(pkg_name_width, len("Package")) r = osc.core.http_request("GET", api_url + "/attribute/MPCDF/enable_repositories/_meta") - root = ET.parse(r).getroot() + root = ElementTree.parse(r).getroot() kinds = list(value.text for value in root.findall("./allowed/value")) pkg_name_fmt = "{{:{0}}}".format(pkg_name_width) @@ -68,11 +71,11 @@ def do_mpcdf_info(self, subcmd, opts, *args): for package in packages: try: - enabled_repos = get_attribute_values(api_url, project, package, "MPCDF:enable_repositories") - except: + enabled_repos = mpcdf_common.get_attribute_values(api_url, project, package, "MPCDF:enable_repositories") + except Exception: unmanaged.append(package) continue - print(" " + pkg_name_fmt.format(package), ", ".join(filter(lambda q : q in enabled_repos, kinds))) + print(" " + pkg_name_fmt.format(package), ", ".join(filter(lambda q: q in enabled_repos, kinds))) print() if unmanaged: diff --git a/mpcdf_push.py b/mpcdf_push.py index d59f3dbee43c2cd2bfd2a473d3295f2db28d4a75..7c369ce1fc2db8a5846d3e6769e46202315c2d86 100644 --- a/mpcdf_push.py +++ b/mpcdf_push.py @@ -1,6 +1,7 @@ #!/usr/bin/python2 from __future__ import print_function -from mpcdf_common import get_attribute, set_attribute, project_meta, mpcdf_setup_repos + +import mpcdf_common import osc import osc.conf @@ -46,11 +47,11 @@ def do_mpcdf_push(self, subcmd, opts, *args): for attribute in project_attributes: try: - get_attribute(api_url, to_project, None, attribute) + mpcdf_common.get_attribute(api_url, to_project, None, attribute) except Exception: - attr = get_attribute(api_url, from_project, None, attribute) + attr = mpcdf_common.get_attribute(api_url, from_project, None, attribute) print("Setting attribute", attribute) - set_attribute(api_url, (to_project,), attr) + mpcdf_common.set_attribute(api_url, (to_project,), attr) for package in from_packages: if package not in to_packages: @@ -66,18 +67,18 @@ def do_mpcdf_push(self, subcmd, opts, *args): for attribute in package_attributes: try: - attr = get_attribute(api_url, from_project, package, attribute) + attr = mpcdf_common.get_attribute(api_url, from_project, package, attribute) except Exception as e: continue - set_attribute(api_url, (to_project, package), attr) + mpcdf_common.set_attribute(api_url, (to_project, package), attr) # Check if distribution is already set in to_project - to_prj_meta = project_meta(api_url, to_project) + to_prj_meta = mpcdf_common.project_meta(api_url, to_project) sys_repo = to_prj_meta.find('./repository[@name="System"]') if sys_repo is None: - distribution = project_meta(api_url, from_project).find('./repository[@name="System"]/path[@project="distributions"]').get("repository") + distribution = mpcdf_common.project_meta(api_url, from_project).find('./repository[@name="System"]/path[@project="distributions"]').get("repository") else: distribution = sys_repo.find('./path[@project="distributions"]').get("repository") print("Creating repository configuration") - mpcdf_setup_repos(api_url, to_project, distribution, packages=[package] if package else None) + mpcdf_common.mpcdf_setup_repos(api_url, to_project, distribution, packages=[package] if package else None) diff --git a/mpcdf_setup_repos.py b/mpcdf_setup_repos.py index 09cbbb236efbe1227c7ea3642b3aa47fdcf83640..e8169697602a283c6493af586486a53dbc86d0ad 100644 --- a/mpcdf_setup_repos.py +++ b/mpcdf_setup_repos.py @@ -1,11 +1,9 @@ #!/usr/bin/python2 from __future__ import print_function -import sys -import argparse -from xml.etree import ElementTree -from mpcdf_common import * +from mpcdf_common import mpcdf_setup_repos +import os import osc import osc.conf import osc.core @@ -13,12 +11,11 @@ import osc.cmdln default_distribution = "SLE_12_SP1" + @osc.cmdln.option('-n', '--dry-run', action="store_true", help="Do not actually run anything but output the resulting XML configuration") - @osc.cmdln.option('--parent', metavar="PARENT", help="Setup the repositories to be based on the upstream project PARENT (e.g. for home: projects)") - @osc.cmdln.option('--distribution', default=default_distribution, help="Base distribution [default: %default]") @@ -36,14 +33,14 @@ def do_mpcdf_setup_repos(self, subcmd, opts, *args): """ if len(args) == 0: - if is_project_dir(os.curdir) or is_package_dir(os.curdir): + if osc.core.is_project_dir(os.curdir) or osc.core.is_package_dir(os.curdir): project = osc.core.store_read_project(os.curdir) else: - raise oscerr.WrongArgs('Specify PROJECT or run command in an osc checkout directory') + raise osc.oscerr.WrongArgs('Specify PROJECT or run command in an osc checkout directory') elif len(args) == 1: project, = args else: - raise oscerr.WrongArgs("Too many arguments") + raise osc.oscerr.WrongArgs("Too many arguments") mpcdf_setup_repos(self.get_api_url(), project, opts.distribution, parent=opts.parent, dry_run=opts.dry_run)