def get_head_version(parameter_pool, eb_client=None, quiet=True): # Get all versions app_name = parameter_pool.get_value(PName.ApplicationName, False) version_names = api_wrapper.get_all_versions(parameter_pool, app_name, eb_client) # Try get local commit HEAD hash head_hash = shell_utils.get_repo_head_hash(quiet) if head_hash is None: return ServiceDefault.DEFAULT_VERSION_NAME # Try find a version corresponding to local HEAD version_re = re.compile(DevToolsDefault.VersionNameRe.format(head_hash), re.UNICODE) timestamp = 0 for version in version_names: if version_re.match(version): cur_timestamp = int( version.split(DevToolsDefault.NameDelimiter)[2]) timestamp = cur_timestamp if cur_timestamp > timestamp else timestamp if timestamp > 0: # Found a version generated from local repos HEAD log.info(u'Found a version generated from local HEAD {0}. Using this version.'.\ format(head_hash)) return DevToolsDefault.VersionNameMask.format(head_hash, timestamp) else: return None
def get_head_version(parameter_pool, eb_client = None, quiet = True): # Get all versions app_name = parameter_pool.get_value(PName.ApplicationName, False) version_names = api_wrapper.get_all_versions(parameter_pool, app_name, eb_client) # Try get local commit HEAD hash head_hash = shell_utils.get_repo_head_hash(quiet) if head_hash is None: return ServiceDefault.DEFAULT_VERSION_NAME # Try find a version corresponding to local HEAD version_re = re.compile(DevToolsDefault.VersionNameRe.format(head_hash),re.UNICODE) timestamp = 0 for version in version_names: if version_re.match(version): cur_timestamp = int(version.split(DevToolsDefault.NameDelimiter)[2]) timestamp = cur_timestamp if cur_timestamp > timestamp else timestamp if timestamp > 0: # Found a version generated from local repos HEAD log.info(u'Found a version generated from local HEAD {0}. Using this version.'.\ format(head_hash)) return DevToolsDefault.VersionNameMask.format(head_hash, timestamp) else: return None