print 'Found git-obs-mapping: %s -> %s' % (gerrit_prj, obs_prjs)
return obs_prjs
+
+def git_ref_map(prjdir=None, mapping_file=None, base_project=None):
+ """
+ Find an OBS Reference Projects correspondent to base_project
+ by parsing git-ref-mapping.xml.
+ @ Return: [[branch, OBS project, Ref project], ...]
+ """
+
+ # clone scm/git-ref-mapping.git
+ if not clone_gitproject(os.getenv('REF_MAPPING_PRJ'), prjdir):
+ print >> sys.stderr, 'Error cloning %s' % os.getenv('REF_MAPPING_PRJ')
+ return []
+ # read xml contents
+ with open(mapping_file) as mf:
+ map_obj = xml_to_obj(''.join(mf.readlines()))
+ # find matching projects
+ found = []
+ for path in map_obj.default.path:
+ for item in path.branch:
+ if base_project is None or item.OBS_project == base_project:
+ found.append([item.name, item.OBS_project, item.OBS_staging_project])
+ return found
+
--- /dev/null
+#!/usr/bin/env python
+#
+# Copyright (c) 2014, 2015, 2016 Samsung Electronics.Co.Ltd.
+#
+# This program is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the Free
+# Software Foundation; version 2 of the License
+#
+# This program is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+# or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+# for more details.
+#
+"""This script is used to update git-ref-mapping"""
+
+import os
+import sys
+
+from common.buildtrigger import trigger_info
+from common.git import Git
+from common.mapping import git_ref_map
+
+TEMPLATE = """ <branch name="%s" OBS_project="%s" OBS_staging_project="%s"/>"""
+
+def main():
+ """The main body"""
+
+ # parameters
+ fields = trigger_info(os.getenv('TRIGGER_INFO'))
+ profile = fields['profile']
+ base_project = fields['base_project']
+ release_version = fields['release_id'].split('_')[-1]
+
+ prjdir = os.path.join(os.getenv('WORKSPACE'), os.path.basename(os.getenv('REF_MAPPING_PRJ')))
+ mapping_file = '{0}/git-ref-mapping.xml'.format(prjdir)
+
+ # retrieve contents from mapping xml
+ found = git_ref_map(prjdir, mapping_file, base_project=base_project)
+ if not os.path.exists(mapping_file):
+ print '** NO MAPPING FILE FOUND %s' % (mapping_file)
+ return 1
+ if len(found) == 0:
+ print '** REF MAP HAVE NO ITEMS FOR %s' % (base_project)
+ return 2
+
+ # replace old version to new
+ need_update = False
+ with open(mapping_file) as mf:
+ lines = mf.readlines()
+ for idx,line in enumerate(lines):
+ for x in found:
+ old_item = TEMPLATE % (x[0], x[1], x[2])
+ new_item = TEMPLATE % (x[0], x[1], ':'.join([':'.join(x[2].split(':')[:-1]), release_version]))
+ if old_item == new_item:
+ continue
+ if line.rstrip() == old_item:
+ lines[idx] = line.replace(old_item, new_item)
+ need_update = True
+ print ' Updating to %s for %s / %s' % (release_version, x[1], x[0])
+
+ # update git repository
+ if need_update:
+ with open(mapping_file, 'w') as mf:
+ for line in lines:
+ mf.write(line)
+ mygit = Git(prjdir)
+ mygit.add_files('*', True)
+ mygit.commit_staged('Updating %s => %s' % (base_project, fields['release_id']))
+ mygit.push(repo = 'origin', src = 'master')
+ print "\"Title\": \"%s\"" % (fields['release_id'])
+ else:
+ print 'No updates for git-ref-mapping.'
+
+if __name__ == '__main__':
+
+ sys.exit(main())
+
from common.utils import sync
from common.utils import make_latest_link
from common.backenddb import BackendDB
+from common.buildtrigger import trigger_next
def main():
# update the latest link
make_latest_link(path_latest_release_snapshot)
+ # update reference project information with release id
+ if os.getenv("REF_MAPPING_PRJ") is not None:
+ trigger_next("ref-snapshot-info-update", \
+ {'profile':release_profile, \
+ 'base_project':profile_info['Project'], \
+ 'release_id':release_id})
+
if __name__ == '__main__':
sys.exit(main())