Add a command to open package websites

This commit is contained in:
Ryan Fox 2023-07-06 18:21:22 -07:00
parent b498049703
commit 0995cbe960
Signed by: flewkey
GPG Key ID: 94F56ADFD848851E
2 changed files with 45 additions and 0 deletions

View File

@ -3,12 +3,14 @@ from pkgcrap.list_update import main as update
from pkgcrap.list_update import maintlist as maintlist
from pkgcrap.outdated_check import main as outdated
from pkgcrap.forge_scan import main as forgescan
from pkgcrap.website import main as website
options = {
'update': update,
'outdated': outdated,
'maintlist': maintlist,
'forgescan': forgescan,
'site': website,
}
def main():

43
pkgcrap/website.py Normal file
View File

@ -0,0 +1,43 @@
import webbrowser
import pkgcrap.parse as parse
def repo2site(repo):
return repo[:-4] if repo.endswith('.git') else repo
def stripslash(url):
return url[:-1] if url.endswith('/') else url
def main(args):
pkg = parse.package.from_path('.')
pkg.load()
sites = list()
if len(pkg.ebuilds) > 0:
if 'HOMEPAGE' in pkg.ebuilds[0].vars:
sites.append(stripslash(pkg.ebuilds[0].vars['HOMEPAGE']))
if 'EGIT_REPO_URI' in pkg.ebuilds[0].vars:
sites.append(repo2site(pkg.ebuilds[0].vars['EGIT_REPO_URI']))
for remote in pkg.metadata.remotes:
if remote[0] == 'github':
sites.append('https://github.com/'+remote[1])
if remote[0] == 'gitlab':
sites.append('https://gitlab.com/'+remote[1])
if remote[0] == 'pypi':
sites.append('https://pypi.org/project/'+remote[1]+'/')
sites = sorted(list(set(sites)))
match len(sites):
case 0:
print('No sites found :-(')
exit(1)
case 1:
print('Opening '+sites[0])
webbrowser.open(sites[0])
case _:
print('Sites:')
for i in range(len(sites)):
print(str(i+1)+') '+sites[i])
pick = input('Pick one: ')
pick = sites[int(pick)-1]
print('Opening '+pick)
webbrowser.open(pick)