Esempio n. 1
0
    def from_dict(cls, data):
        version_spec_str = data.get('version_spec', None)

        # If we are specifying a version in the spec_data, then
        # assume we want to install exactly that version, so build
        # a version_spec to indicate that (ie, '==1.0.0' etc)
        if not version_spec_str:
            if data.get('version', None):
                ver = data['version']

                # try to handle matching 'v1.0.0' etc
                if version_needs_aka(str(ver)):
                    data['version'] = normalize_version_string(ver)
                    data['version_aka'] = ver
                version_spec_str = '==%s' % data['version']
            else:
                # No version_spec, and version is None, that means match anything
                version_spec_str = '*'

        instance = cls(
            namespace=data['namespace'],
            name=data['name'],
            version_spec=version_spec_str,
            version_aka=data.get('version_aka', None),
            fetch_method=data.get('fetch_method', None),
            req_spec_string=data.get('req_spec_string', None),
            src=data.get('src', None),
        )
        return instance
Esempio n. 2
0
def get_content_version(content_data, version, content_versions, content_content_name):
    '''find and compare content version found in content_data dict

    content_data is a dict based on /api/v1/content/13 for ex
    content_content_data is the name of the content specified by user?
    version is the version string asked for by user
    content_versions is a list of version strings in order
    '''

    log.debug('%s want ver: %s', content_content_name, version)
#    log.debug('%s vers avail: %s',
#              content_content_name, json.dumps(content_versions, indent=2))

    # normalize versions, but also build a map of the normalized version string to the orig string
    available_normalized_versions, norm_to_orig_map = normalize_versions(content_versions)

    # verify that the normalized versions are valid semver now so that we dont worry about it
    # in the sort
    available_versions, dummy = \
        validate_versions(available_normalized_versions)

    normalized_version = normalize_version_string(version)

#    log.debug('normalized_version: %s', normalized_version)
#    log.debug('avail_normalized_versions: %s', json.dumps(available_normalized_versions, indent=4))

    # we specified a particular version is required so look for it in available versions
    if version and version != 'master':
        if not available_versions:
            # FIXME: should we show the actual available versions or the available
            #        versions we searched in?  act: ['v1.0.0', '1.1'] nor: ['1.0.0', '1.1']
            msg = "- The list of available versions for %s is empty (%s)." % \
                (content_content_name or 'content', available_versions)
            raise exceptions.GalaxyError(msg)

        if str(normalized_version) not in available_versions:
            # TODO: how do we msg 'couldn't find the version you specified
            #       in actual version tags or ones we made up without the leading v'
            msg = "- the specified version (%s) of %s was not found in the list of available versions (%s)." % \
                (version, content_content_name or 'content', available_versions)
            raise exceptions.GalaxyError(msg)

        # if we get here, 'version' is in available_normalized_versions
        # return the exact match version since it was available
        orig_version = norm_to_orig_map[normalized_version]
        log.debug('%s requested ver: %s, matched: %s, using real ver: %s ', content_content_name, version, normalized_version, orig_version)
        return orig_version

    # At this point, we have a list of the available versions. The available versions have
    # been normalized (leading 'v' or 'V' stripped off).
    # No specific version was requested, so we return the latest one.
    content_version = get_latest_version(available_versions, content_data)

    log.debug('%s using latest ver: %s', content_content_name, content_version)
    return content_version
Esempio n. 3
0
def normalize_versions(content_versions):
    # a list of tuples of (normalized_version, original_version) for building
    # map of normalized version to original version
    normalized_versions = [(normalize_version_string(x), x) for x in content_versions]

    available_normalized_versions = [v[0] for v in normalized_versions]

    # map the 'normalized' version back to the original version string, we need it for
    # content archive download urls
    norm_to_orig_map = dict(normalized_versions)

    return (available_normalized_versions, norm_to_orig_map)
Esempio n. 4
0
def get_content_version(content_data, version, content_versions,
                        content_content_name):
    '''find and compare content version found in content_data dict

    content_data is a dict based on /api/v1/content/13 for ex
    content_content_data is the name of the content specified by user?
    version is the version string asked for by user
    content_versions is a list of version strings in order
    '''

    log.debug('%s want ver: %s', content_content_name, version)
    log.debug('%s vers avail: %s', content_content_name,
              json.dumps(content_versions, indent=2))

    # a list of tuples of (normalized_version, original_version) for building map of normalized version to original version
    normalized_versions = [(normalize_version_string(x), x)
                           for x in content_versions]

    available_normalized_versions = [v[0] for v in normalized_versions]

    # map the 'normalized' version back to the original version string, we need it for content archive download urls
    norm_to_orig_map = dict(normalized_versions)

    normalized_version = normalize_version_string(version)

    log.debug('normalized_version: %s', normalized_version)
    log.debug('avail_normalized_versions: %s',
              json.dumps(available_normalized_versions, indent=4))

    # we specified a particular version is required so look for it in available versions
    if version and version != 'master':
        if not available_normalized_versions:
            # FIXME: should we show the actual available versions or the available
            #        versions we searched in?  act: ['v1.0.0', '1.1'] nor: ['1.0.0', '1.1']
            msg = "- The list of available versions for %s is empty (%s)." % \
                (content_content_name or 'content', available_normalized_versions)
            raise exceptions.GalaxyError(msg)

        if str(normalized_version) not in available_normalized_versions:
            # TODO: how do we msg 'couldn't find the version you specified
            #       in actual version tags or ones we made up without the leading v'
            msg = "- the specified version (%s) of %s was not found in the list of available versions (%s)." % \
                (version, content_content_name or 'content', available_normalized_versions)
            raise exceptions.GalaxyError(msg)

        # if we get here, 'version' is in available_normalized_versions
        # return the exact match version since it was available
        orig_version = norm_to_orig_map[normalized_version]
        log.debug('%s requested ver: %s, matched: %s, using real ver: %s ',
                  content_content_name, version, normalized_version,
                  orig_version)
        return orig_version

    # and sort them to get the latest version. If there
    # are no versions in the list, we'll grab the head
    # of the master branch
    if len(available_normalized_versions) > 0:
        loose_versions = [
            LooseVersion(a) for a in available_normalized_versions
        ]
        try:
            loose_versions.sort()
        except TypeError as e:
            log.exception(e)
            log.error('ver: %s loose_versions: %s', version, loose_versions)
            raise exceptions.GalaxyClientError(
                'Unable to compare content versions (%s) to determine the most recent version due to incompatible version formats. '
                'Please contact the content author to resolve versioning conflicts, or specify an explicit content version to '
                'install.' % ', '.join([v.vstring for v in loose_versions]))
        content_version = str(loose_versions[-1])
    # FIXME: follow 'repository' branch and it's ['import_branch'] ?
    elif content_data.get('github_branch', None):
        content_version = content_data['github_branch']
    else:
        content_version = 'master'

    log.debug('%s using latest ver: %s', content_content_name, content_version)
    return content_version
Esempio n. 5
0
def test_normalize_version_string_unmodified(version_string_unmodified):
    res = normalize_version_string(version_string_unmodified)
    log.debug('res: %s version_string: %s', res, version_string_unmodified)
    assert res == version_string_unmodified
Esempio n. 6
0
def test_normalize_version_string_to_strip(version_string_to_strip):
    res = normalize_version_string(version_string_to_strip)
    log.debug('res: %s version_string: %s', res, version_string_to_strip)
    assert res != version_string_to_strip