Exemplo n.º 1
0
def select_version(versions_str, query, stable=False):
    if isinstance(query, str):
        query = query.split(",")
    query = [x.replace(" ", "") for x in query]
    stable = True
    if "-" in str(query):
        stable = False
    spec = Spec(*query)
    return spec.select(versions(versions_str, stable))
Exemplo n.º 2
0
def main():
    vs = [
        "0.2.0", "0.1.6", "0.1.5", "0.1.4", "0.1.3", "0.1.2", "0.1.1", "0.1.0"
    ]
    s = Spec('>=0.1.3,<0.2.0')
    print('versions:', vs)
    print('rule:', s.specs, '\n')
    versions = [Version(v) for v in vs]
    filtered = [str(v) for v in s.filter(versions)]
    print('filtered:', filtered)
    print('selected:', s.select(versions))
Exemplo n.º 3
0
def _select_pragma_version(pragma_string, version_list):
    comparator_set_range = pragma_string.replace(" ", "").split('||')
    comparator_regex = re.compile(r"(([<>]?=?|\^)\d+\.\d+\.\d+)+")
    version = None

    for comparator_set in comparator_set_range:
        spec = Spec(*(i[0] for i in comparator_regex.findall(comparator_set)))
        selected = spec.select(version_list)
        if selected and (not version or version < selected):
            version = selected
    if version:
        return str(version)
Exemplo n.º 4
0
    def find_version_by_spec(self, artifact):
        path = "/%s/%s" % (artifact.path(False), self.metadata_file_name)
        content = self._getContent(
            self.base + path,
            "Failed to retrieve the maven metadata file: " + path)
        xml = etree.fromstring(content)
        original_versions = xml.xpath(
            "/metadata/versioning/versions/version/text()")
        versions = []
        for version in original_versions:
            try:
                versions.append(Version.coerce(version))
            except ValueError:
                # This means that version string is not a valid semantic versioning
                pass

        parse_versions_syntax = {
            # example -> (,1.0]
            r"^\(,(?P<upper_bound>[0-9.]*)]$": "<={upper_bound}",
            # example -> 1.0
            r"^(?P<version>[0-9.]*)$": "~={version}",
            # example -> [1.0]
            r"^\[(?P<version>[0-9.]*)\]$": "=={version}",
            # example -> [1.2, 1.3]
            r"^\[(?P<lower_bound>[0-9.]*),\s*(?P<upper_bound>[0-9.]*)\]$":
            ">={lower_bound},<={upper_bound}",
            # example -> [1.2, 1.3)
            r"^\[(?P<lower_bound>[0-9.]*),\s*(?P<upper_bound>[0-9.]+)\)$":
            ">={lower_bound},<{upper_bound}",
            # example -> [1.5,)
            r"^\[(?P<lower_bound>[0-9.]*),\)$": ">={lower_bound}",
        }

        for regex, spec_format in parse_versions_syntax.items():
            regex_result = match(regex, artifact.version_by_spec)
            if regex_result:
                spec = Spec(spec_format.format(**regex_result.groupdict()))
                selected_version = spec.select(versions)

                if not selected_version:
                    raise ValueError(
                        "No version found with this spec version: {0}".format(
                            artifact.version_by_spec))

                # To deal when repos on maven don't have patch number on first build (e.g. 3.8 instead of 3.8.0)
                if str(selected_version) not in original_versions:
                    selected_version.patch = None

                return str(selected_version)

        raise ValueError("The spec version {0} is not supported! ".format(
            artifact.version_by_spec))
Exemplo n.º 5
0
def best_upgrade(current: Version,
                 candidates: List[Version],
                 track: str = 'MajorVersion'):
    if track == 'PatchLevel':
        spec = Spec('>{current},<{next_minor}'.format(
            current=str(current), next_minor=str(current.next_minor())))
    elif track == 'MinorVersion':
        spec = Spec('>{current},<{next_minor}'.format(
            current=str(current), next_minor=str(current.next_major())))
    elif track == 'MajorVersion':
        spec = Spec('>{current}'.format(current=str(current)))
    else:
        raise ValueError('unsupported "track": {track}'.format(track=track))
    return spec.select(candidates)
Exemplo n.º 6
0
def _fetch_latest_nextcloud(major: int,
                            curver: Optional[Version]) -> Optional[Nextcloud]:
    versions = _get_nextcloud_versions()
    if curver is None:
        version = Spec(f'^{major}').select(versions.keys())
    else:
        spec = Spec(f'<{curver.next_major()},>{_strip_build(curver)}')
        version = spec.select(versions.keys())
    if version is None:
        return None
    url = versions[version]

    sha_response = download_pbar(url + '.sha256',
                                 desc='Fetching checksum for ' + url)
    sha256: str = sha_response.split(maxsplit=1)[0].decode()
    ziphash: Sha256 = _hash_zip(url, Sha256(sha256))

    nc = Nextcloud(version, url, ziphash)
    return _update_with_real_version(nc)
Exemplo n.º 7
0
Arquivo: ide.py Projeto: scztt/qpm
def find_ide(version='>0.0.0', hint=None, interactive=True):
    print 'Searching for SC versions matching %s...' % version
    versions = find_sc_versions(hint=hint)
    try:
        version_spec = Spec(version)
    except ValueError:
        version_spec = Spec('==' + version)

    matches = list()

    for v in versions:
        semver = versions[v]
        if version_spec.match(semver):
            matches.append(v)

    if matches:
        best_match_ver = version_spec.select(map(lambda m: versions[m], matches))
        for m in matches:
            if best_match_ver is versions[m]:
                best_match = m
                break

        if interactive and len(matches) > 1:
            best_num = -1
            for i, match in enumerate(matches):
                print "[%s] %s (%s)" % (i, match, versions[match])
                if match == best_match: best_num = i

            selection = None
            while not(selection):
                selection = raw_input("Which ide do you want to use for this project? [default: %s]: " % best_num)
                if not(selection): selection = best_num
                try:
                    selection = int(selection)
                    selected_path = matches[selection]
                    return selected_path
                except Exception:
                    selection = None
                    pass
        else:
            return matches[0]
Exemplo n.º 8
0
    def iter_component_providers(self, comp, subs=False, vers=False, reqs="*"):
        """An iterater function to interate providers of a component

        Takes a conponent name and yeilds providers of the conponent

        if `subs` is `True` yeilds providers of subtypes too

        if `vers` is `True` yeilds all version of the provider
        not just the highest

        `reqs` is a version requirement for the providers to meet.
        Defaults to any version

        yeilds tuples that look like:
        `(<component_name>, <plugin_name>, <version>)`

        Examples:

            >>> for t in iter_component_providers("foo", subs=True): print(t);
            ("foo", "foo_plugin", "0.1.0")
            ("foo", "foo_plugin2", "1.0.0")
            ("foo.a", "foo.a_plugin", "0.1.0")
            ("foo.a.b", "footastic", "10.0.0")

        Args:
            comp (str): component name to use as a base
            subs (bool): should subtypes be yeilded too?
            vers (bool): should all version be yeilded not just the highest?
            reqs (str, list, tuple): version spec string or list there of
                all items are passed to a `Spec`
        Raises:
            TypeError: if `comp` or `reqs` are passed wrong
        """
        if isinstance(reqs, basestring):
            reqs = (reqs,)
        if not isinstance(reqs, (list, tuple)):
            raise TypeError(
                "Invalid requierment type, must be string, list, or tuple: %r"
                % (reqs,))
        if not isinstance(comp, basestring):
            raise TypeError(
                "comp is niether a Component instance nor a string: %r"
                % (comp,))

        spec = Spec(*reqs)

        if subs:
            comps = self.component_map.keys()
        else:
            comps = (comp,)

        for com in comps:
            if com in self.component_map and issubcomponent(com, comp):
                providers = self.component_map[com]
                for prov in providers:
                    versions = providers[prov]
                    if vers:
                        for ver in sorted(versions):
                            yield (com, prov, ver)
                    else:
                        yield (com, prov, spec.select(versions))
Exemplo n.º 9
0
def pick_version(versions, rule):
    spec = Spec(rule)
    vs = [Version(v) for v in versions]
    return str(spec.select(vs))