From a01eb03f3f4fee68ab789e176883496b39a21672 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lorenz=20H=C3=BCdepohl?= <lorenz.huedepohl@rzg.mpg.de>
Date: Tue, 13 Feb 2018 12:44:52 +0100
Subject: [PATCH] Support to push just one package in mpcdf_push

---
 mpcdf_push.py | 40 ++++++++++++++++++++++------------------
 1 file changed, 22 insertions(+), 18 deletions(-)

diff --git a/mpcdf_push.py b/mpcdf_push.py
index ba5cf1c..91b56c2 100644
--- a/mpcdf_push.py
+++ b/mpcdf_push.py
@@ -53,32 +53,36 @@ def do_mpcdf_push(self, subcmd, opts, *args):
             print("Setting attribute", attribute)
             mpcdf_common.set_attribute(api_url, (to_project,), attr)
 
-    for package in from_packages:
-        if package not in to_packages:
-            filelist = osc.core.meta_get_filelist(api_url, from_project, package)
+    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(package))
+                print("Not branching package {0}, is a link".format(orig_package))
             else:
-                print("Branching package {0}".format(package))
+                print("Branching package {0}".format(orig_package))
                 exists, targetprj, targetpkg, srcprj, srcpkg = \
-                    osc.core.branch_pkg(api_url, from_project, package, target_project=to_project, nodevelproject=True)
+                    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(package))
+            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, package, attribute)
+                attr = mpcdf_common.get_attribute(api_url, from_project, orig_package, attribute)
             except Exception:
                 continue
-            mpcdf_common.set_attribute(api_url, (to_project, package), attr)
+            mpcdf_common.set_attribute(api_url, (to_project, orig_package), attr)
 
-    # 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")
+    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_repos(api_url, to_project, distribution, packages=[package] if package else None)
+        print("Creating repository configuration")
+        mpcdf_common.mpcdf_setup_repos(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