self.set_meta(ElementTree.tostring(xml_root), project)
+ def get_link_project_info(self, project):
+ """
+ Retrieve link project info
+ """
+ if not self.exists(project):
+ return None
+
+ meta_xml = self.get_meta(project)
+ xml_root = ElementTree.fromstringlist(meta_xml)
+
+ link_element = xml_root.find('link')
+ if link_element is None:
+ return None
+
+ return link_element.attrib.get('project')
+
def create_sr(self, src_project, packages, tgt_project, message=''):
"""Create submit request for the project."""
content = '<request><description>%s</description>' % \
import json
import base64
import re
+import ast
import xml.etree.cElementTree as ElementTree
from xml.sax.saxutils import escape
from time import sleep
from gitbuildsys.errors import ObsError
from common import utils
-from common.mapping import git_obs_map, git_virtual_branch_map
+from common.mapping import git_obs_map, git_virtual_branch_map, get_ref_map
from common.git import Git, clone_gitproject
from common.upload_service import upload_obs_service, UploadError
from common.gerrit import is_ref_deleted
else:
obs_target_prjs = git_obs_map(os.getenv("GERRIT_PROJECT"), git_branch)
+ # get lis of ref projects from git-ref-mapping
+ obs_ref_prjs = get_ref_map(os.getenv("GERRIT_PROJECT"), git_branch)
+
build = BuildService(obs_api, obs_user, obs_passwd)
+ # Get all project lists
+ all_obs_prjs = build.get_project_list()
+
# prepare submit_info
submit_info={}
submit_info['submitted'] = {
obs_target_prj
continue
project = get_prerelease_project_name(obs_target_prj, git_tag)
+
+ ref_obs_target_prj = obs_target_prj
+ # Set obs_target_prj to ref project if it is enabled
+ if os.getenv("REF_CREATE_PRJ_OBS_ENABLE","0") == "1":
+ # Check if this is the group submit.
+ existing_link_info = build.get_link_project_info(project)
+ if existing_link_info is not None and build.exists(existing_link_info):
+ print 'Project already exist. Use previous ref project %s' % existing_link_info
+ ref_obs_target_prj = existing_link_info
+ else:
+ if obs_target_prj in [ x['project'] for x in ast.literal_eval(os.getenv('REF_ACTIVE_PRJS')) ]:
+ for ref_info in obs_ref_prjs:
+ if ref_info['OBS_project'] != obs_target_prj:
+ continue
+ ret_ref = re.search(r'(%s):ref:([0-9]{8}.[0-9]+)' % obs_target_prj, \
+ ref_info['OBS_staging_project'])
+ if not ret_ref or not ret_ref.groups() or len(ret_ref.groups()) != 2:
+ continue
+ print ' ** Set target link project to %s' % ref_info['OBS_staging_project']
+ ref_obs_target_prj = ref_info['OBS_staging_project']
+ # If ref-map does not exists, set the most recent ref project
+ associated_prjs = sorted([ p for p in all_obs_prjs if '%s:ref:' % obs_target_prj in p ])
+ if not associated_prjs or len(associated_prjs) < 1:
+ print 'No ref project for %s' % obs_target_prj
+ ref_obs_target_prj = obs_target_prj
+ elif ref_obs_target_prj not in associated_prjs:
+ print 'No ref map exist. Set it recent ref project %s' % associated_prjs[-1]
+ ref_obs_target_prj = associated_prjs[-1]
+ sys.stdout.flush()
+
if is_ref_deleted(gerrit_oldrev, gerrit_newrev):
build.cleanup(project, "Cleaned by job_submit")
else:
while retry_count > 0:
try:
create_project(url, gerrit_project, git_tag, gerrit_newrev,
- build, obs_target_prj, project, submitter, package, build_flag=enable_build)
+ build, ref_obs_target_prj, project, submitter, package, build_flag=enable_build)
if pub_enabled:
rest.publish_event("pre_created", {
"project": project,