Пример #1
0
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
Пример #2
0
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
Пример #3
0
def check_app_version(parameter_pool, eb_client = None):
    #TODO: Do we need to blast version info away if this part is strong enough?
    if not parameter_pool.has(PName.ApplicationVersionName) \
        or parameter_pool.get_source(PName.ApplicationVersionName) == PSource.Default:

        version_name = get_head_version(parameter_pool, eb_client=eb_client, quiet=True)        
        
        if version_name is not None:
            log.info(u'Found a version from local repository: {0}. Using this version.'.\
                     format(version_name))
            return version_name
        else:
            # Otherwise try push a new one
            if not parameter_pool.get_value(PName.Force) == ServiceDefault.ENABLED\
                and not TerminalBase.ask_confirmation(DevToolsMessage.PushLocalHead):
                return ServiceDefault.DEFAULT_VERSION_NAME
            else:
                if shell_utils.git_aws_push(False):
                    version_name = get_head_version(parameter_pool, 
                                                    eb_client=eb_client, 
                                                    quiet=False)
                    if version_name:
                        return version_name   
                return ServiceDefault.DEFAULT_VERSION_NAME
    else:
        # Verify existence of version
        app_name = parameter_pool.get_value(PName.ApplicationName, False)
        version_names = api_wrapper.get_all_versions(parameter_pool, app_name, eb_client)
        version_name = parameter_pool.get_value(PName.ApplicationVersionName)    
        if version_name in version_names:
            # Assume version is still valid and compatible with current solution stack
            return version_name
        else:
            # 
            return ServiceDefault.DEFAULT_VERSION_NAME
Пример #4
0
def check_app_version(parameter_pool, eb_client = None):
    #TODO: Do we need to blast version info away if this part is strong enough?
    if not parameter_pool.has(PName.ApplicationVersionName) \
        or parameter_pool.get_source(PName.ApplicationVersionName) == PSource.Default:

        version_name = get_head_version(parameter_pool, eb_client=eb_client, quiet=True)        
        
        if version_name is not None:
            log.info(u'Found a version from local repository: {0}. Using this version.'.\
                     format(version_name))
            return version_name
        else:
            # Otherwise try push a new one
            if not parameter_pool.get_value(PName.Force) == ServiceDefault.ENABLED\
                and not TerminalBase.ask_confirmation(DevToolsMessage.PushLocalHead):
                return ServiceDefault.DEFAULT_VERSION_NAME
            else:
                if shell_utils.git_aws_push(push_only=True, quiet=False):
                    version_name = get_head_version(parameter_pool, 
                                                    eb_client=eb_client, 
                                                    quiet=False)
                    if version_name:
                        return version_name   
                return ServiceDefault.DEFAULT_VERSION_NAME
    else:
        # Verify existence of version
        app_name = parameter_pool.get_value(PName.ApplicationName, False)
        version_names = api_wrapper.get_all_versions(parameter_pool, app_name, eb_client)
        version_name = parameter_pool.get_value(PName.ApplicationVersionName)    
        if version_name in version_names:
            # Assume version is still valid and compatible with current solution stack
            return version_name
        else:
            # 
            return ServiceDefault.DEFAULT_VERSION_NAME