Always update git-ref-map
authortizenrobot <tizenrobot@noreply.samsung.com>
Tue, 16 May 2017 06:20:54 +0000 (06:20 +0000)
committerhyokeun <hyokeun.jeon@samsung.com>
Tue, 16 May 2017 07:45:27 +0000 (16:45 +0900)
Change-Id: I01501535f04e88f4ff15f1e98ee5f3fb41d9e0b2

common/mapping.py
job_ref_snapshot_info_update.py

index 3077704..ffbdcf0 100644 (file)
@@ -18,7 +18,7 @@
 
 """Handle XML data with Python objects"""
 
-import os
+import os,sys
 from common.utils import xml_to_obj
 from common.git import clone_gitproject
 from xml.sax import SAXException
@@ -209,7 +209,14 @@ class MappingV2(object):
                 if (obs_project and brch.OBS_project != obs_project) or (staging_project and brch.OBS_staging_project != staging_project):
                     continue
                 for prj in brch.project:
-                    mapping.append(self.__encode_to_ascii([prj.name, brch.name, brch.OBS_project, brch.OBS_staging_project, prj.OBS_package]))
+                    item = {}
+                    item['Project_name'] = prj.name
+                    item['Branch_name'] = brch.name
+                    item['OBS_project'] = brch.OBS_project
+                    item['OBS_staging_project'] = brch.OBS_staging_project
+                    item['OBS_package'] = prj.OBS_package
+                    item = self.__encode_to_ascii(item)
+                    mapping.append(item)
             return mapping
 
         return mapping
@@ -348,6 +355,10 @@ def git_obs_map_full_list(obs_project=None, staging_project=None, gitcache=None,
 
     obs_prjs = []
 
+    # get mappings v1
+    mymapping = Mapping(mapping_path_v1)
+    obs_prjs = mymapping.get_submit_mapping('/', None)
+
     # get v2 mapping files list
     mapping_path_v2 = '{0}/profiles/'.format(git_obs_mapping_path)
     mapping_v2_file_lists = get_xml_file_list(mapping_path_v2)
index 7f3558d..1af9194 100644 (file)
@@ -18,7 +18,7 @@ import sys
 
 from common.buildtrigger import trigger_info
 from common.git import Git
-import xml.etree.cElementTree as ElementTree
+from common.mapping import git_obs_map, git_obs_map_full_list
 from lxml import etree
 from common.git import clone_gitproject
 
@@ -55,9 +55,12 @@ def main():
     parser = etree.XMLParser(remove_comments=False)
     tree = etree.fromstring(''.join(lines))
 
-    for dft in tree.getiterator('path'):
+    # replace old version to new
+    insert_new = True
+    for dft in tree.getiterator('branch'):
         for item in dft.getiterator():
             if item.get('OBS_project') == base_project:
+                insert_new = False
                 orgn_prj = item.get('OBS_project')
                 orgn_brch = item.get('name')
                 old_ref = item.get('OBS_staging_project')
@@ -67,15 +70,36 @@ def main():
                     print '  Replace [%s][%s] %s -> %s' % (orgn_prj, orgn_brch, old_ref, new_ref)
                     item.set('OBS_staging_project', new_ref)
 
+    # Insert new target to tizen branch
+    if insert_new == True:
+        new_branch_list = []
+        full_list = git_obs_map_full_list()
+        for t in full_list:
+            if 'OBS_project' in t and 'Branch_name' in t:
+                if t['OBS_project'] == base_project:
+                    [ new_branch_list.append(x) for x in t['Branch_name'].split(',') if x not in new_branch_list ]
+        print new_branch_list
+        for _br in new_branch_list:
+            new_ref = base_project + ':ref:' + release_version
+            newKid = etree.Element('branch', \
+                                   name                = _br, \
+                                   OBS_project         = base_project, \
+                                   OBS_staging_project = new_ref)
+            newKid.tail = '\n        '
+            for dft in tree.getiterator('path'):
+                dft.insert(-1, newKid)
+            print '  Insert %s[%s](%s)' % (base_project, new_ref, _br)
+
     new_xml_string = XML_DECLARATION + '\n' + etree.tostring(tree)
+    print 'After change...\n%s' % etree.tostring(tree)
 
     # update git repository
-    if need_update:
+    if need_update or insert_new:
         with open(mapping_file, 'w') as mf:
             mf.write(new_xml_string)
         mygit = Git(prjdir)
         mygit.add_files('*', True)
-        mygit.commit_staged('Updating %s => %s' % (base_project, release_id))
+        mygit.commit_staged('%s' % (release_id))
         mygit.push(repo = 'origin', src = 'master')
         print "\"Title\": \"%s\"" % (release_id)
     else: