return self.__get_mapping(path, branch) or []
return []
- def get_contains_branch_mapping(self, project, branch=None):
- """ Get contains branch mapping """
- branchs = []
-
- if self.mapping_obj.project:
- for prj in self.mapping_obj.project:
- if prj.name == project or prj.name == '/' + project:
- branchs.append(prj.branch)
-
- if self.mapping_obj.default:
- # Search in path list
- prj_path = project
- while True:
- # parent directory of project/directory
- prj_path = os.path.dirname(os.path.join('/', prj_path))
-
- if prj_path == '/':
- for path in self.mapping_obj.default.path:
- if path.name == '/':
- if branch == path.branch:
- return branchs.append(path.branch) or []
- return []
-
- # Search path
- for path in self.mapping_obj.default.path:
- # path match
- if os.path.dirname(os.path.join('/', path.name) +
- '/') == prj_path:
- if branch == path.branch:
- return branchs.append(path.branch) or []
- return []
- return []
+ def get_virtual_branch_mapping(self):
+ """ Get virtual branch mapping """
+
+ mapping = []
+ if self.mapping_obj.default.virtual:
+ brch_dict = {}
+ for branch in self.mapping_obj.default.virtual.branch:
+ brch_dict[branch.name] = branch.real
+ mapping.append(self.__encode_to_ascii(brch_dict))
+ return mapping
class MappingV2(object):
"""A class to handle mapping xml file """
return mapping
- def get_contains_branch_mapping(self, project, branch=None):
- """ Get contains branch mapping """
- branchs = []
- if self.mapping_obj.configure:
- # if configure.enable is false then return []
- if self.mapping_obj.configure.enable == 'false':
- return branchs
-
- if self.mapping_obj.branch:
- for brch in self.mapping_obj.branch:
- for prj in brch.project:
- if (prj.name == project or prj.name == '/' + project) and (branch in brch.name.split(",") ):
- for b in brch.name.split(","):
- branchs.append(b)
-
- return branchs
-
def git_obs_map(gerrit_prj, gerrit_branch=None, gitcache=None, \
gerrit_hostname=None, gerrit_username=None, gerrit_sshport=None, \
include_config=False):
found.append([item.name, item.OBS_project, item.OBS_staging_project])
return found
-def git_contains_branch_map(gerrit_prj, gerrit_branch=None, gitcache=None, \
- gerrit_hostname=None, gerrit_username=None, gerrit_sshport=None):
+def git_virtual_branch_map():
"""
- Find an branch by parsing git-obs-mapping.xml.
+ Find an virtual branch 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:
- git_cache = os.getenv("GIT_CACHE_DIR")
+ git_cache = os.getenv("GIT_CACHE_DIR")
mapping_prj = os.getenv("MAPPING_PRJ")
git_obs_mapping_path = os.path.join(git_cache, mapping_prj)
# get mappings v1
mymapping = Mapping(mapping_path_v1)
- branchs = mymapping.get_contains_branch_mapping(gerrit_prj, gerrit_branch)
+ branchs = mymapping.get_virtual_branch_mapping()
- # 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)
-
- # get mappings v2
- for file in mapping_v2_file_lists:
- mymapping_v2 = MappingV2(file)
- branchs.extend(mymapping_v2.get_contains_branch_mapping(gerrit_prj,
- gerrit_branch))
- branchs = remove_overlaps(branchs)
return branchs
def git_obs_map_full_list(obs_project=None, staging_project=None, gitcache=None, \
from gitbuildsys.errors import ObsError
from common import utils
-from common.mapping import git_obs_map, git_contains_branch_map
+from common.mapping import git_obs_map, git_virtual_branch_map
from common.git import Git, clone_gitproject
from common.upload_service import upload_obs_service, UploadError
from common.gerrit import is_ref_deleted
WRONG_FORMAT_MSG = '- Wrong tag format,\n please follow the format '\
'submit/{branch}/{date.time}. \n'\
- 'Your branch : %s. Git-obs-mapping branch: %s'
-
-NOT_ANNOTATED_MSG = '- Tag should be annotated tag.'
+ 'Git branch : %s. Tag branch: %s'
SUGGESTION = 'Suggest to use "gbs submit" to trigger submission\n'\
return tag
-def check_tag_format(git, mygerrit, event, tag, mappingbranchs):
+def check_tag_format(git, mygerrit, event, tag):
"""check whether tag follow proper format"""
branch, date = parse_submit_tag(tag)
else:
# cannot find tagged commit in git tree or gerrit open change
message.append(WRONG_COMMIT_MSG % psr)
-
- contain = False
- containsbranch = git.branch_contains(tag)
- for b in containsbranch:
- if b in mappingbranchs:
+ else:
+ # check for contains branch
+ contain = False
+ cbrch = git.branch_contains(tag)
+ if branch in cbrch:
+ print '%s branch is contains in %s branch' %(branch, cbrch)
contain = True
- if not contain:
- # wrong tag format
- message.append(WRONG_FORMAT_MSG % (containsbranch,mappingbranchs))
-
+ else:
+ vbrch = git_virtual_branch_map()
+ for items in vbrch:
+ if '%s' %(branch) in items and \
+ items['%s' %(branch)] is not None \
+ and items['%s' %(branch)] in cbrch:
+ print '%s branch is virtual %s branch' %(branch, items['%s' %(branch)])
+ contain = True
+ if not contain:
+ # wrong tag format
+ print '%s branch is not contains in %s branch' %(branch, cbrch)
+ message.append(WRONG_FORMAT_MSG % (cbrch, branch))
else:
# wrong tag format
message.append(UNKNOWN_FORMAT_MSG)
if gerrit_account_email:
submitter += ' <%s>' % gerrit_account_email
- mappingbranchs = git_contains_branch_map(event['project'], git_branch, \
- gitcache=git_cache, \
- gerrit_hostname=event['hostname'], \
- gerrit_username=event['username'], \
- gerrit_sshport=event['sshport']
- )
-
- # precheck tpk branch (ABS)
- if '_tpk' in git_branch:
- mappingbranchs.append(git_branch)
- print 'mapping branch = %s ' %(mappingbranchs)
-
# check whether tag meet format
- if not check_tag_format(mygit, mygerrit, event, tag, mappingbranchs):
+ if not check_tag_format(mygit, mygerrit, event, tag):
print 'The check for the tag format is error, exit now\n'
return 0