Skip to content
Snippets Groups Projects
Commit 89d13eb6 authored by Lorenz Huedepohl's avatar Lorenz Huedepohl
Browse files

Fix flake8 errors

parent 5ccb69f9
Branches
No related tags found
No related merge requests found
Pipeline #
#!/usr/bin/python2 #!/usr/bin/python2
from __future__ import print_function from __future__ import print_function
import sys
import argparse
from functools import partial
from xml.etree import ElementTree from xml.etree import ElementTree
from mpcdf_common import * import mpcdf_common
import os
import osc import osc
import osc.conf import osc.conf
import osc.core import osc.core
import osc.cmdln import osc.cmdln
@osc.cmdln.option('--cuda-mpi', action="store_true", @osc.cmdln.option('--cuda-mpi', action="store_true",
help="Enable for all CUDA+MPI repositories") help="Enable for all CUDA+MPI repositories")
@osc.cmdln.option('--cuda', action="store_true", @osc.cmdln.option('--cuda', action="store_true",
...@@ -52,11 +51,11 @@ def do_mpcdf_enable_repositories(self, subcmd, opts, *args): ...@@ -52,11 +51,11 @@ def do_mpcdf_enable_repositories(self, subcmd, opts, *args):
""" """
if len(args) == 0: 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) package = osc.core.store_read_package(os.curdir)
project = osc.core.store_read_project(os.curdir) project = osc.core.store_read_project(os.curdir)
else: 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: elif len(args) == 1:
package, = args package, = args
...@@ -65,7 +64,7 @@ def do_mpcdf_enable_repositories(self, subcmd, opts, *args): ...@@ -65,7 +64,7 @@ def do_mpcdf_enable_repositories(self, subcmd, opts, *args):
elif len(args) == 2: elif len(args) == 2:
project, package = args project, package = args
else: else:
raise oscerr.WrongArgs("Too many arguments") raise osc.oscerr.WrongArgs("Too many arguments")
api_url = self.get_api_url() api_url = self.get_api_url()
...@@ -96,9 +95,9 @@ def do_mpcdf_enable_repositories(self, subcmd, opts, *args): ...@@ -96,9 +95,9 @@ def do_mpcdf_enable_repositories(self, subcmd, opts, *args):
if opts.cuda_mpi: if opts.cuda_mpi:
value("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: 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: 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"))
#!/usr/bin/python2 #!/usr/bin/python2
from __future__ import print_function from __future__ import print_function
import sys from functools import reduce
import argparse
from mpcdf_common import * import mpcdf_common
import os
import osc import osc
import osc.conf import osc.conf
import osc.core import osc.core
import osc.cmdln import osc.cmdln
from xml.etree import ElementTree
def do_mpcdf_info(self, subcmd, opts, *args): def do_mpcdf_info(self, subcmd, opts, *args):
"""${cmd_name}: Basic information about an MPCDF OBS project """${cmd_name}: Basic information about an MPCDF OBS project
...@@ -21,15 +24,15 @@ def do_mpcdf_info(self, subcmd, opts, *args): ...@@ -21,15 +24,15 @@ def do_mpcdf_info(self, subcmd, opts, *args):
""" """
if len(args) == 0: 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) project = osc.core.store_read_project(os.curdir)
else: 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: elif len(args) == 1:
project, = args project, = args
else: else:
raise oscerr.WrongArgs("Too many arguments") raise osc.oscerr.WrongArgs("Too many arguments")
print("Project `{0}`\n".format(project)) print("Project `{0}`\n".format(project))
...@@ -37,8 +40,8 @@ def do_mpcdf_info(self, subcmd, opts, *args): ...@@ -37,8 +40,8 @@ def do_mpcdf_info(self, subcmd, opts, *args):
def print_attribute(description, attribute): def print_attribute(description, attribute):
try: try:
values = list(sorted(get_attribute_values(api_url, project, None, attribute))) values = list(sorted(mpcdf_common.get_attribute_values(api_url, project, None, attribute)))
except: except Exception:
print("This project unmanaged, i.e. it does not have the required MPCDF: attributes set") print("This project unmanaged, i.e. it does not have the required MPCDF: attributes set")
raise SystemExit(0) raise SystemExit(0)
...@@ -58,7 +61,7 @@ def do_mpcdf_info(self, subcmd, opts, *args): ...@@ -58,7 +61,7 @@ def do_mpcdf_info(self, subcmd, opts, *args):
pkg_name_width = max(pkg_name_width, len("Package")) pkg_name_width = max(pkg_name_width, len("Package"))
r = osc.core.http_request("GET", api_url + "/attribute/MPCDF/enable_repositories/_meta") 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")) kinds = list(value.text for value in root.findall("./allowed/value"))
pkg_name_fmt = "{{:{0}}}".format(pkg_name_width) pkg_name_fmt = "{{:{0}}}".format(pkg_name_width)
...@@ -68,11 +71,11 @@ def do_mpcdf_info(self, subcmd, opts, *args): ...@@ -68,11 +71,11 @@ def do_mpcdf_info(self, subcmd, opts, *args):
for package in packages: for package in packages:
try: try:
enabled_repos = get_attribute_values(api_url, project, package, "MPCDF:enable_repositories") enabled_repos = mpcdf_common.get_attribute_values(api_url, project, package, "MPCDF:enable_repositories")
except: except Exception:
unmanaged.append(package) unmanaged.append(package)
continue 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() print()
if unmanaged: if unmanaged:
......
#!/usr/bin/python2 #!/usr/bin/python2
from __future__ import print_function 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
import osc.conf import osc.conf
...@@ -46,11 +47,11 @@ def do_mpcdf_push(self, subcmd, opts, *args): ...@@ -46,11 +47,11 @@ def do_mpcdf_push(self, subcmd, opts, *args):
for attribute in project_attributes: for attribute in project_attributes:
try: try:
get_attribute(api_url, to_project, None, attribute) mpcdf_common.get_attribute(api_url, to_project, None, attribute)
except Exception: 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) 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: for package in from_packages:
if package not in to_packages: if package not in to_packages:
...@@ -66,18 +67,18 @@ def do_mpcdf_push(self, subcmd, opts, *args): ...@@ -66,18 +67,18 @@ def do_mpcdf_push(self, subcmd, opts, *args):
for attribute in package_attributes: for attribute in package_attributes:
try: 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: except Exception as e:
continue 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 # 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"]') sys_repo = to_prj_meta.find('./repository[@name="System"]')
if sys_repo is None: 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: else:
distribution = sys_repo.find('./path[@project="distributions"]').get("repository") distribution = sys_repo.find('./path[@project="distributions"]').get("repository")
print("Creating repository configuration") 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)
#!/usr/bin/python2 #!/usr/bin/python2
from __future__ import print_function 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
import osc.conf import osc.conf
import osc.core import osc.core
...@@ -13,12 +11,11 @@ import osc.cmdln ...@@ -13,12 +11,11 @@ import osc.cmdln
default_distribution = "SLE_12_SP1" default_distribution = "SLE_12_SP1"
@osc.cmdln.option('-n', '--dry-run', action="store_true", @osc.cmdln.option('-n', '--dry-run', action="store_true",
help="Do not actually run anything but output the resulting XML configuration") help="Do not actually run anything but output the resulting XML configuration")
@osc.cmdln.option('--parent', metavar="PARENT", @osc.cmdln.option('--parent', metavar="PARENT",
help="Setup the repositories to be based on the upstream project PARENT (e.g. for home: projects)") help="Setup the repositories to be based on the upstream project PARENT (e.g. for home: projects)")
@osc.cmdln.option('--distribution', @osc.cmdln.option('--distribution',
default=default_distribution, default=default_distribution,
help="Base distribution [default: %default]") help="Base distribution [default: %default]")
...@@ -36,14 +33,14 @@ def do_mpcdf_setup_repos(self, subcmd, opts, *args): ...@@ -36,14 +33,14 @@ def do_mpcdf_setup_repos(self, subcmd, opts, *args):
""" """
if len(args) == 0: 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) project = osc.core.store_read_project(os.curdir)
else: 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: elif len(args) == 1:
project, = args project, = args
else: 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) mpcdf_setup_repos(self.get_api_url(), project, opts.distribution, parent=opts.parent, dry_run=opts.dry_run)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment