pkgcrap/pkgcrap/forge_scan.py

43 lines
1.7 KiB
Python

from pkgcrap.util import conf_file_path
import pkgcrap.parse as parse
from urllib.parse import urlparse
def main(args):
repos = parse.repos()
repos.load()
checked = 0
failed = 0
forges = {}
for repo in repos.repos.values():
repo.load()
print('Scanning', repo.name)
for cat in repo.categories.values():
cat.load()
for pkg in cat.packages.values():
pkg.load()
if len(pkg.ebuilds) == 0 or 'EGIT_REPO_URI' not in pkg.ebuilds[0].vars:
failed += 1
continue
eb = pkg.ebuilds[0]
repo = pkg.ebuilds[0].vars['EGIT_REPO_URI'].replace('${PN}', pkg.name)
if 'HOMEPAGE' in pkg.ebuilds[0].vars:
repo = repo.replace('${HOMEPAGE}', eb.vars['HOMEPAGE'])
if 'EGO_PN' in pkg.ebuilds[0].vars:
repo = repo.replace('${EGO_PN}', eb.vars['EGO_PN'])
if 'MY_REPO_URI' in pkg.ebuilds[0].vars:
repo = repo.replace('${MY_REPO_URI}', eb.vars['MY_REPO_URI'])
forge = urlparse(repo).netloc
if forge == '' or forge.startswith('${'):
failed += 1
continue
if forge not in forges:
forges[forge] = 0
forges[forge] += 1
checked += 1
print('Found git URI in '+str(checked)+' packages')
print('Failed to find git URI in '+str(failed)+' packages')
for forge in dict(reversed(sorted(forges.items(), key=lambda item: item[1]))):
c = forges[forge]
p = float(c)/checked*100
print(forge+': '+str(c)+f' ({p:.2f}%)')