"""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
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
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)
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
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')
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: