def select_latest_version(input_version='0.0.0', libio='0.0.0', anitya='0.0.0'): libio_latest_version = convert_version_to_proper_semantic(libio) anitya_latest_version = convert_version_to_proper_semantic(anitya) input_version = convert_version_to_proper_semantic(input_version) try: latest_version = libio if libio else '' if sv.SpecItem('<' + anitya_latest_version).match( sv.Version(libio_latest_version)): latest_version = anitya if sv.SpecItem('<' + input_version).match(sv.Version(latest_version)): # User provided version is higher. Do not show the latest version in the UI latest_version = '' except ValueError: pass return latest_version
def select_latest_version(input_version='0.0.0', libio='0.0.0', anitya='0.0.0'): """Return the latest version of packages.""" libio_latest_version = convert_version_to_proper_semantic(libio) anitya_latest_version = convert_version_to_proper_semantic(anitya) input_version = convert_version_to_proper_semantic(input_version) try: latest_version = libio_latest_version return_version = libio if sv.SpecItem('<' + anitya_latest_version).match(sv.Version(libio_latest_version)): latest_version = anitya_latest_version return_version = anitya if sv.SpecItem('<' + input_version).match(sv.Version(latest_version)): # User provided version is higher. Do not show the latest version in the UI return_version = '' except ValueError: # In case of failure let's not show any latest version at all return_version = '' pass return return_version
def parse(self, specs_string): spec_texts = specs_string.split(',') res = [] for spec_text in spec_texts: if '-' not in spec_text and '+' not in spec_text and spec_text != '*': spec_text = spec_text.split('.') while len(spec_text) < 3: spec_text.append('0') spec_text = '.'.join(spec_text) + '-' res.append(semantic_version.SpecItem(spec_text)) return tuple(res)
def select_latest_version(libio, anitya): libio_latest_version = libio if libio else '0.0.0' anitya_latest_version = anitya if anitya else '0.0.0' libio_latest_version = libio_latest_version.replace('.', '-', 3) libio_latest_version = libio_latest_version.replace('-', '.', 2) anitya_latest_version = anitya_latest_version.replace('.', '-', 3) anitya_latest_version = anitya_latest_version.replace('-', '.', 2) try: latest_version = libio if libio else '' if sv.SpecItem('<' + anitya_latest_version).match(sv.Version(libio_latest_version)): latest_version = anitya except ValueError: pass return latest_version
def select_latest_version(libio, anitya): # anitya does not provide latest version anymore, but it's kept for # compatibility libio_latest_version = libio if libio else '0.0.0' anitya_latest_version = anitya if anitya else '0.0.0' libio_latest_version = libio_latest_version.replace('.', '-', 3) libio_latest_version = libio_latest_version.replace('-', '.', 2) anitya_latest_version = anitya_latest_version.replace('.', '-', 3) anitya_latest_version = anitya_latest_version.replace('-', '.', 2) try: latest_version = libio if libio else '' if sv.SpecItem('<' + anitya_latest_version).match( sv.Version(libio_latest_version)): latest_version = anitya except ValueError: pass return latest_version
def filter_versions(epv_list, input_stack): """Filter the EPVs according to following rules. First filter fetches only EPVs that 1. has No CVEs 2. are Present in Graph Apply additional filter based on following. That is sorted based on 3. Latest Version 4. Dependents Count in Github Manifest Data 5. Github Release Date """ # TODO: reduce cyclomatic complexity pkg_dict = defaultdict(dict) new_dict = defaultdict(dict) filtered_comp_list = [] for epv in epv_list: name = epv.get('pkg', {}).get('name', [''])[0] version = epv.get('ver', {}).get('version', [''])[0] # needed for maven version like 1.5.2.RELEASE to be converted to # 1.5.2-RELEASE for semantic version to work' semversion = version.replace('.', '-', 3) semversion = semversion.replace('-', '.', 2) if name and version: # Select Latest Version and add to filter_list if # latest version is > current version latest_version = select_latest_version( epv.get('pkg').get('libio_latest_version', [''])[0], epv.get('pkg').get('latest_version', [''])[0]) if latest_version and latest_version == version: try: if sv.SpecItem('>=' + input_stack.get(name, '0.0.0')).match( sv.Version(semversion)): pkg_dict[name]['latest_version'] = latest_version new_dict[name]['latest_version'] = epv.get('ver') new_dict[name]['pkg'] = epv.get('pkg') filtered_comp_list.append(name) except ValueError: pass # Check for Dependency Count Attribute. Add Max deps count version # if version > current version deps_count = epv.get('ver').get('dependents_count', [-1])[0] if deps_count > 0: if 'deps_count' not in pkg_dict[name] or \ deps_count > pkg_dict[name].get('deps_count', {}).get('deps_count', 0): try: if sv.SpecItem('>=' + input_stack.get(name, '0.0.0')).match( sv.Version(semversion)): pkg_dict[name]['deps_count'] = {"version": version, "deps_count": deps_count} new_dict[name]['deps_count'] = epv.get('ver') new_dict[name]['pkg'] = epv.get('pkg') filtered_comp_list.append(name) except ValueError: pass # Check for github release date. Add version with most recent github release date gh_release_date = epv.get('ver').get('gh_release_date', [0])[0] if gh_release_date > 0.0: if 'gh_release_date' not in pkg_dict[name] or \ gh_release_date > \ pkg_dict[name].get('gh_release_date', {}).get('gh_release_date', 0): try: if sv.SpecItem('>=' + input_stack.get(name, '0.0.0')).match( sv.Version(semversion)): pkg_dict[name]['gh_release_date'] = { "version": version, "gh_release_date": gh_release_date} new_dict[name]['gh_release_date'] = epv.get('ver') new_dict[name]['pkg'] = epv.get('pkg') filtered_comp_list.append(name) except ValueError: pass new_list = [] for package, contents in new_dict.items(): if 'latest_version' in contents: new_list.append({"pkg": contents['pkg'], "ver": contents['latest_version']}) elif 'deps_count' in contents: new_list.append({"pkg": contents['pkg'], "ver": contents['deps_count']}) elif 'gh_release_date' in contents: new_list.append({"pkg": contents['pkg'], "ver": contents['gh_release_date']}) return new_list, filtered_comp_list
def test_simple(self): for valid in self.valid_specs: with self.subTest(spec=valid): spec = semantic_version.SpecItem(valid) normalized = str(spec) self.assertEqual(spec, semantic_version.SpecItem(normalized))