From 7f669521ceb0d0336561a100f80d3b5812e2f544 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lorenz=20H=C3=BCdepohl?= <lorenz.huedepohl@rzg.mpg.de> Date: Wed, 21 Mar 2018 10:46:01 +0100 Subject: [PATCH] Rename mpcdf_push to mpcdf_sync_project The old mpcdf_push is from now on only used to push individual packages from user projects to software --- mpcdf_sync_projects.py | 88 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 mpcdf_sync_projects.py diff --git a/mpcdf_sync_projects.py b/mpcdf_sync_projects.py new file mode 100644 index 0000000..6d36b62 --- /dev/null +++ b/mpcdf_sync_projects.py @@ -0,0 +1,88 @@ +#!/usr/bin/python2 +from __future__ import print_function + +import mpcdf_common + +import osc +import osc.conf +import osc.core +import osc.cmdln + + +def do_mpcdf_sync_projects(self, subcmd, opts, *args): + """${cmd_name}: Push all packages from a project to another + + Branch all missing packages from one project into a target project + + Usage: + osc mpcdf_push FROM_PROJECT TO_PROJECT + osc mpcdf_push FROM_PROJECT PACKAGE TO_PROJECT + + Examples: + - Update the software:SLE_12_SP3:skylake project + #> osc mpcdf_sync_projects software software:SLE_12_SP3:skylake + + ${cmd_option_list} + """ + if len(args) < 2: + raise osc.oscerr.WrongArgs("Not enough arguments") + elif len(args) == 2: + from_project, to_project = args + package = None + elif len(args) == 3: + from_project, package, to_project = args + else: + raise osc.oscerr.WrongArgs("Too many arguments") + + api_url = self.get_api_url() + + if package is None: + from_packages = osc.core.meta_get_packagelist(api_url, from_project) + else: + from_packages = [package] + to_packages = osc.core.meta_get_packagelist(api_url, to_project) + + project_attributes = ["MPCDF:compiler_modules", "MPCDF:cuda_modules", "MPCDF:mpi_modules"] + package_attributes = ["MPCDF:enable_repositories"] + project_attributes + + for attribute in project_attributes: + try: + mpcdf_common.get_attribute(api_url, to_project, None, attribute) + except Exception: + attr = mpcdf_common.get_attribute(api_url, from_project, None, attribute) + print("Setting attribute", attribute) + mpcdf_common.set_attribute(api_url, to_project, None, attr) + + for orig_package in from_packages: + if orig_package not in to_packages: + filelist = osc.core.meta_get_filelist(api_url, from_project, orig_package) + if "_link" in filelist: + print("Not branching package {0}, is a link".format(orig_package)) + else: + print("Branching package {0}".format(orig_package)) + exists, targetprj, targetpkg, srcprj, srcpkg = \ + osc.core.branch_pkg(api_url, from_project, orig_package, target_project=to_project, nodevelproject=True) + else: + print("Not branching package {0}, already present in target".format(orig_package)) + + for attribute in package_attributes: + try: + attr = mpcdf_common.get_attribute(api_url, from_project, orig_package, attribute) + except Exception: + continue + mpcdf_common.set_attribute(api_url, to_project, orig_package, attr) + + if package is None: + # Check if distribution is already set in 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 = 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_common.mpcdf_setup_repositories(api_url, to_project, distribution) + else: + if not mpcdf_common.mpcdf_enable_repositories(api_url, to_project, package): + print("ATTENTION: Not changing unmanaged package {0}".format(package)) -- GitLab