def get_version(url): data = '\n'.join(get_url_content(url=url)) primary_path = PRIMARY_XML_GZ_REGEX.search(data).groups()[0] xml_url = url.replace(REPOMD_XML_PATH, primary_path) parser = Parser(url=xml_url) major_versions = [package['version'][1]['ver'] for package in parser.getList()] return max(set(major_versions), key=major_versions.count)
def get_branch_version_from_repo(url): page = requests.get(url).text repo_regex = re.compile(r'baseurl=(http.*?)\$basearch') match = repo_regex.search(page) if not match: raise ValueError("url isn't a correct yum repo\n\turl:[{}] ".format(url)) repo_base_url = match.groups()[0] url = "{}x86_64/repodata/repomd.xml".format(repo_base_url) page = requests.get(url).text primary_regex = re.compile(r'="(.*?primary.xml.gz)"') primary_path = primary_regex.search(page).groups()[0] url = "{}x86_64/{}".format(repo_base_url, primary_path) parser = Parser(url=url) major_versions = [package['version'][1]['ver'] for package in parser.getList()] return max(set(major_versions), key=major_versions.count)