diff --git a/horsy.py b/horsy.py index 831ebce..d7e3f7c 100644 --- a/horsy.py +++ b/horsy.py @@ -1,10 +1,13 @@ import argparse import os +import sys + import modules.tui as tui from modules.console import cls from modules.manager import install, uninstall from modules.virustotal import add_to_cfg from modules.uploader import upload +from modules.source import get_source # Getting the arguments parser = argparse.ArgumentParser(description='horsy - the best package manager') @@ -20,18 +23,9 @@ args = parser.parse_args() option = args.option app = args.app -# Checking if the user has a new VT key -if args.vt_key: - if args.vt_key != 'disable': - add_to_cfg(args.vt_key) - else: - add_to_cfg(None) - # Checking directories and files if not os.path.exists('apps'): os.makedirs('apps') -if not os.path.exists('sources'): - os.makedirs('sources') if not os.path.isfile('config.cfg'): with open('config.cfg', 'w') as f: f.write('{}') @@ -51,6 +45,14 @@ print(''' ''') isNoArgs = False +# Checking if the user has a new VT key +if args.vt_key: + if args.vt_key != 'disable': + add_to_cfg(args.vt_key) + else: + add_to_cfg(None) + sys.exit() + # Checking if arguments are empty to use in-app CLI if not args.option: option = ['install', 'uninstall', 'source', 'update', 'list', 'upload', 'search'][ @@ -72,5 +74,8 @@ if option in ['install', 'i']: if option in ['uninstall', 'un']: uninstall(app) +if option in ['source', 's']: + get_source(app) + if isNoArgs: input('[EXIT] Press enter to exit horsy...') diff --git a/modules/source.py b/modules/source.py new file mode 100644 index 0000000..1ffda24 --- /dev/null +++ b/modules/source.py @@ -0,0 +1,28 @@ +import requests +import json +import webbrowser +import modules.vars as horsy_vars +from rich import print + + +def get_source(package): + r = requests.get(f"{horsy_vars.protocol}{horsy_vars.server_url}/packages/json/{package}").text + try: + r = json.loads(r) + except: + print("[red]Error with unsupported message[/]") + return + try: + if r["message"] == "not found": + print("[red]Package not found[/]") + return + if r["message"] == "Internal server error": + print("[red]Internal server error[/]") + return + except: + pass + + try: + webbrowser.open(r["sourceUrl"]) + except: + print("[red]No source code available for this app[/]")