Ejemplo n.º 1
0
def get_version(module, release, index):
    if common.GitService(module['git']['service']) == common.GitService.GitHub:
        return release.tag_name
    elif common.GitService(module['git']['service']) == common.GitService.GitLab:
        return release.name
    else:
        matched_item = None
        for item in release['rss']['channel']['item']:
            if re.search(module['git']['asset_patterns'][index], item['title']):
                matched_item = item
                break

        if matched_item is None:
            return "Latest"

        match = re.search(
            module['git']['version_pattern'], matched_item['title'])
        if match is None:
            return "Latest"

        groups = match.groups()
        if len(groups) == 0:
            return "Latest"

        return groups[0]
Ejemplo n.º 2
0
def download_asset(module, release, index):
    pattern = module['git']['asset_patterns'][index]

    if common.GitService(module['git']['service']) == common.GitService.GitHub:
        if release is None:
            return None

        matched_asset = None
        for asset in release.get_assets():
            if re.search(pattern, asset.name):
                matched_asset = asset
                break

        if matched_asset is None:
            print(
                f'[Error] Unable to find asset that match pattern: "{pattern}"')
            return None

        download_path = common.generate_temp_path()
        urllib.request.urlretrieve(
            matched_asset.browser_download_url, download_path)

        return download_path
    elif common.GitService(module['git']['service']) == common.GitService.GitLab:
        group = module['git']['group']

        match = re.search(pattern, release.release['description'])
        if match is None:
            return None

        groups = match.groups()
        if len(groups) <= group:
            return None

        download_path = common.generate_temp_path()

        opener = urllib.request.URLopener()
        opener.addheader(
            'User-Agent', 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2)     AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.106 Safari/537.36')
        opener.retrieve(
            f'https://gitlab.com/{module["git"]["org_name"]}/{module["git"]["repo_name"]}{groups[group]}', download_path)

        return download_path
    else:
        matched_item = None
        for item in release['rss']['channel']['item']:
            if re.search(pattern, item['title']):
                matched_item = item
                break

        if matched_item is None:
            print(
                f'[Error] Unable to find asset that match pattern: "{pattern}"')
            return None

        download_path = common.generate_temp_path()
        urllib.request.urlretrieve(matched_item['link'], download_path)

        return download_path
Ejemplo n.º 3
0
def download_asset(module, release, index):
    pattern = module['git']['asset_patterns'][index]

    if common.GitService(module['git']['service']) == common.GitService.GitHub:
        if release is None:
            return None

        matched_asset = None
        for asset in release.get_assets():
            if re.search(pattern, asset.name):
                matched_asset = asset
                break

        if matched_asset is None:
            print(
                f'[Error] Unable to find asset that match pattern: "{pattern}"'
            )
            return None

        download_path = common.generate_temp_path()
        urllib.request.urlretrieve(matched_asset.browser_download_url,
                                   download_path)

        return download_path
    elif common.GitService(
            module['git']['service']) == common.GitService.GitLab:
        group = module['git']['group']

        match = re.search(pattern, release.release['description'])
        if match is None:
            return None

        groups = match.groups()
        if len(groups) <= group:
            return None

        download_path = common.generate_temp_path()
        urllib.request.urlretrieve(
            f'https://gitlab.com/{module["git"]["org_name"]}/{module["git"]["repo_name"]}{groups[group]}',
            download_path)

        return download_path
    else:
        matched_item = None
        for item in release['rss']['channel']['item']:
            if re.search(pattern, item['title']):
                matched_item = item
                break

        if matched_item is None:
            print(
                f'[Error] Unable to find asset that match pattern: "{pattern}"'
            )
            return None

        download_path = common.generate_temp_path()
        urllib.request.urlretrieve(matched_item['link'], download_path)

        return download_path
Ejemplo n.º 4
0
def get_latest_release(module, include_prereleases=True):
    if common.GitService(module['git']['service']) == common.GitService.GitHub:
        try:
            repo = gh.get_repo(
                f'{module["git"]["org_name"]}/{module["git"]["repo_name"]}')
        except:
            print(
                f'[Error] Unable to find repo: {module["git"]["org_name"]}/{module["git"]["repo_name"]}'
            )
            return None

        releases = repo.get_releases()
        if releases.totalCount == 0:
            print(
                f'[Error] Unable to find any releases for repo: {module["git"]["org_name"]}/{module["git"]["repo_name"]}'
            )
            return None

        if include_prereleases:
            return releases[0]

        for release in releases:
            if not release.prerelease:
                return release

        return None
    elif common.GitService(
            module['git']['service']) == common.GitService.GitLab:
        try:
            project = gl.projects.get(
                f'{module["git"]["org_name"]}/{module["git"]["repo_name"]}')
        except:
            print(
                f'[Error] Unable to find repo: {module["git"]["org_name"]}/{module["git"]["repo_name"]}'
            )
            return None

        tags = project.tags.list()
        for tag in tags:
            if tag.release is not None:
                return tag

        print(
            f'[Error] Unable to find any releases for repo: {module["git"]["org_name"]}/{module["git"]["repo_name"]}'
        )
        return None
    else:
        releases = None
        with urllib.request.urlopen(
                f'https://sourceforge.net/projects/{module["git"]["repo_name"]}/rss?path=/'
        ) as fd:
            releases = xmltodict.parse(fd.read().decode('utf-8'))

        return releases
Ejemplo n.º 5
0
def get_latest_release(module):
    if common.GitService(module['git']['service']) == common.GitService.GitHub:
        try:
            repo = gh.get_repo(f'{module["git"]["org_name"]}/{module["git"]["repo_name"]}')
        except:
            print(f'[Error] Unable to find repo: {module["git"]["org_name"]}/{module["git"]["repo_name"]}')
            return None
        
        releases = repo.get_releases()
        if releases.totalCount == 0:
            print(f'[Error] Unable to find any releases for repo: {module["git"]["org_name"]}/{module["git"]["repo_name"]}')
            return None
        
        return releases[0]
    else:
        try:
            project = gl.projects.get(f'{module["git"]["org_name"]}/{module["git"]["repo_name"]}')
        except:
            print(f'[Error] Unable to find repo: {module["git"]["org_name"]}/{module["git"]["repo_name"]}')
            return None

        tags = project.tags.list()
        for tag in tags:
            if tag.release is not None:
                return tag

        print(f'[Error] Unable to find any releases for repo: {module["git"]["org_name"]}/{module["git"]["repo_name"]}')
        return None