Delete duplicate items for the abs and prerelease 11/118911/2
authorYonghee Han <onstudy@samsung.com>
Tue, 14 Mar 2017 11:59:00 +0000 (20:59 +0900)
committerYonghee Han <onstudy@samsung.com>
Thu, 16 Mar 2017 04:52:29 +0000 (13:52 +0900)
Delete prerelease items. Choice the abs item.
Remove the duplicate function

Change-Id: I8f878eb33768e97397a7906542b94e45cd3f51ba

common/mapping.py

index ba6d93b..a357fc1 100644 (file)
@@ -214,6 +214,43 @@ class MappingV2(object):
 
         return mapping
 
+def remove_overlaps(orig_list):
+    """docstring for make_unique"""
+    result = []
+    [result.append(obj) for obj in orig_list if obj not in result]
+    # Delete duplicate items for the abs and prerelease
+    # Delete prerelease items. Choice the abs item.
+    prjs = {}
+    for obj in result:
+        if obj.get('OBS_project') not in prjs:
+            prjs[obj.get('OBS_project')] = [ prj for prj in result \
+                                          if prj.get('OBS_project') == obj.get('OBS_project') ]
+    for obj in prjs:
+        prerelease_index = abs_index = -1
+        i = 0
+        for prj in prjs[obj]:
+            if 'prerelease' == prj.get('OBS_staging_project'):
+                prerelease_index = i
+            if 'abs' ==  prj.get('OBS_staging_project'):
+                abs_index = i
+            i += 1
+        if prerelease_index != -1 and abs_index != -1:
+            prjs[obj].pop(prerelease_index)
+
+    result = []
+    [ result.append(prj) for obj in prjs for prj in prjs[obj] ]
+
+    return result
+
+def get_xml_file_list(path):
+    """ get list of xml files """
+    file_list = []
+    for root, dirs, files in os.walk(path):
+        for file in files:
+            if file.endswith('.xml'):
+                file_list.append(os.path.join(path, file))
+    return file_list
+
 def git_obs_map(gerrit_prj, gerrit_branch=None, gitcache=None, \
                 gerrit_hostname=None, gerrit_username=None, gerrit_sshport=None):
     """
@@ -221,20 +258,6 @@ def git_obs_map(gerrit_prj, gerrit_branch=None, gitcache=None, \
     by parsing git-obs-mapping.xml.
     """
 
-    def remove_overlaps(orig_list):
-        """docstring for make_unique"""
-        result = []
-        [result.append(obj) for obj in orig_list if obj not in result]
-        return result
-
-    def get_xml_file_list(path):
-        file_list = []
-        for root, dirs, files in os.walk(path):
-            for file in files:
-                if file.endswith('.xml'):
-                    file_list.append(os.path.join(path, file))
-        return file_list
-
     if gitcache:
         git_cache = gitcache
     else:
@@ -328,20 +351,6 @@ def git_obs_map_full_list(obs_project=None, staging_project=None, gitcache=None,
     by parsing git-obs-mapping.xml.
     """
 
-    def remove_overlaps(orig_list):
-        """docstring for make_unique"""
-        result = []
-        [result.append(obj) for obj in orig_list if obj not in result]
-        return result
-
-    def get_xml_file_list(path):
-        file_list = []
-        for root, dirs, files in os.walk(path):
-            for file in files:
-                if file.endswith('.xml'):
-                    file_list.append(os.path.join(path, file))
-        return file_list
-
     if gitcache:
         git_cache = gitcache
     else: