This commit is contained in:
BarsTiger
2022-01-24 12:35:45 +02:00
parent aa2a77eea3
commit 92ba77350f
2 changed files with 42 additions and 9 deletions

View File

@@ -1,10 +1,13 @@
import argparse import argparse
import os import os
import sys
import modules.tui as tui import modules.tui as tui
from modules.console import cls from modules.console import cls
from modules.manager import install, uninstall from modules.manager import install, uninstall
from modules.virustotal import add_to_cfg from modules.virustotal import add_to_cfg
from modules.uploader import upload from modules.uploader import upload
from modules.source import get_source
# Getting the arguments # Getting the arguments
parser = argparse.ArgumentParser(description='horsy - the best package manager') parser = argparse.ArgumentParser(description='horsy - the best package manager')
@@ -20,18 +23,9 @@ args = parser.parse_args()
option = args.option option = args.option
app = args.app 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 # Checking directories and files
if not os.path.exists('apps'): if not os.path.exists('apps'):
os.makedirs('apps') os.makedirs('apps')
if not os.path.exists('sources'):
os.makedirs('sources')
if not os.path.isfile('config.cfg'): if not os.path.isfile('config.cfg'):
with open('config.cfg', 'w') as f: with open('config.cfg', 'w') as f:
f.write('{}') f.write('{}')
@@ -51,6 +45,14 @@ print('''
''') ''')
isNoArgs = False 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 # Checking if arguments are empty to use in-app CLI
if not args.option: if not args.option:
option = ['install', 'uninstall', 'source', 'update', 'list', 'upload', 'search'][ option = ['install', 'uninstall', 'source', 'update', 'list', 'upload', 'search'][
@@ -72,5 +74,8 @@ if option in ['install', 'i']:
if option in ['uninstall', 'un']: if option in ['uninstall', 'un']:
uninstall(app) uninstall(app)
if option in ['source', 's']:
get_source(app)
if isNoArgs: if isNoArgs:
input('[EXIT] Press enter to exit horsy...') input('[EXIT] Press enter to exit horsy...')

28
modules/source.py Normal file
View File

@@ -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[/]")