versions and updates for apps
better api requests system
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import json
|
||||
import threading
|
||||
from modules.http_status import handle
|
||||
from modules.request import request
|
||||
import requests
|
||||
import modules.vars as horsy_vars
|
||||
import os
|
||||
@@ -9,10 +10,11 @@ from modules.virustotal import get_key, scan_file, get_report
|
||||
from horsygui import UiDownloadWindow, download_ui
|
||||
from modules.gui import cpopup
|
||||
from PyQt5 import QtGui
|
||||
from urllib.parse import unquote
|
||||
|
||||
|
||||
def install(package):
|
||||
r = requests.get(f"{horsy_vars.protocol}{horsy_vars.server_url}/packages/json/{package}")
|
||||
r = request.get(f"{horsy_vars.protocol}{horsy_vars.server_url}/packages/json/{package}")
|
||||
r_code = handle(r.status_code)
|
||||
r = r.text
|
||||
r = json.loads(r)
|
||||
@@ -23,7 +25,7 @@ def install(package):
|
||||
try:
|
||||
UiDownloadWindow.show()
|
||||
download_ui.logs_box.clear()
|
||||
download_ui.logs_box.append(f"Downloading {r['url'].split('/')[-1]}")
|
||||
download_ui.logs_box.append(f"Downloading {unquote(r['url'].split('/')[-1])}")
|
||||
|
||||
def install_this():
|
||||
if not os.path.exists('{1}apps/{0}'.format(r['name'], horsy_vars.horsypath)):
|
||||
@@ -35,7 +37,8 @@ def install(package):
|
||||
file_r = requests.get(r['url'], stream=True)
|
||||
chunk_size = int(int(file_r.headers['Content-Length']) / 100)
|
||||
percent = 0
|
||||
with open('{2}apps/{0}/{1}'.format(r['name'], r['url'].split('/')[-1], horsy_vars.horsypath), "wb") as f:
|
||||
with open('{2}apps/{0}/{1}'.format(r['name'], unquote(r['url'].split('/')[-1]), horsy_vars.horsypath),
|
||||
"wb") as f:
|
||||
for chunk in file_r.iter_content(chunk_size=chunk_size):
|
||||
if chunk:
|
||||
percent += 1
|
||||
@@ -47,15 +50,15 @@ def install(package):
|
||||
threads.append(threading.Thread(target=dl_main_file))
|
||||
|
||||
if r['download']:
|
||||
download_ui.logs_box.append(f"Downloading {r['download'].split('/')[-1]}")
|
||||
download_ui.logs_box.append(f"Downloading {unquote(r['download'].split('/')[-1])}")
|
||||
download_ui.logs_box.moveCursor(QtGui.QTextCursor.End)
|
||||
|
||||
def dl_dep_file():
|
||||
global success
|
||||
file_r = requests.get(r['download'], stream=True)
|
||||
chunk_size = int(int(file_r.headers['Content-Length']) / 100)
|
||||
with open('{2}apps/{0}/{1}'.format(r['name'], r['download'].split('/')[-1], horsy_vars.horsypath),
|
||||
"wb") as f:
|
||||
with open('{2}apps/{0}/{1}'.format(r['name'], unquote(r['download'].split('/')[-1]),
|
||||
horsy_vars.horsypath), "wb") as f:
|
||||
for chunk in file_r.iter_content(chunk_size=chunk_size):
|
||||
if chunk:
|
||||
f.write(chunk)
|
||||
@@ -78,9 +81,9 @@ def install(package):
|
||||
download_ui.logs_box.moveCursor(QtGui.QTextCursor.End)
|
||||
|
||||
if r['url'].split('.')[-1] == 'zip':
|
||||
download_ui.logs_box.append(f"Extracting {r['url'].split('/')[-1]}")
|
||||
download_ui.logs_box.append(f"Extracting {unquote(r['url'].split('/')[-1])}")
|
||||
download_ui.logs_box.moveCursor(QtGui.QTextCursor.End)
|
||||
unzip('{2}apps/{0}/{1}'.format(r['name'], r['url'].split('/')[-1], horsy_vars.horsypath),
|
||||
unzip('{2}apps/{0}/{1}'.format(r['name'], unquote(r['url'].split('/')[-1]), horsy_vars.horsypath),
|
||||
'{1}apps/{0}'.format(r['name'], horsy_vars.horsypath))
|
||||
|
||||
download_ui.logs_box.append("")
|
||||
@@ -95,12 +98,15 @@ def install(package):
|
||||
download_ui.logs_box.append("If you want to disable scan, type horsy --vt disable in terminal")
|
||||
download_ui.logs_box.append("Starting virustotal scan for program")
|
||||
download_ui.logs_box.moveCursor(QtGui.QTextCursor.End)
|
||||
scan_file('{2}apps/{0}/{1}'.format(r['name'], r['url'].split('/')[-1], horsy_vars.horsypath))
|
||||
analysis = get_report('{2}apps/{0}/{1}'.format(r['name'], r['url'].split('/')[-1],
|
||||
scan_file('{2}apps/{0}/{1}'.format(r['name'], unquote(r['url'].split('/')[-1]),
|
||||
horsy_vars.horsypath))
|
||||
analysis = get_report('{2}apps/{0}/{1}'.format(r['name'], unquote(r['url'].split('/')[-1]),
|
||||
horsy_vars.horsypath))
|
||||
download_ui.logs_box.append(f"Scan finished for program \nYou can see report for program by opening: "
|
||||
download_ui.logs_box.append(f"Scan finished for program \nYou can see report for program by "
|
||||
f"opening: "
|
||||
f"{analysis['link']} \n"
|
||||
f"{analysis['detect']['malicious']} antivirus flagged this file as malicious")
|
||||
f"{analysis['detect']['malicious']} antivirus flagged this file as "
|
||||
f"malicious")
|
||||
download_ui.logs_box.moveCursor(QtGui.QTextCursor.End)
|
||||
except:
|
||||
pass
|
||||
@@ -110,11 +116,11 @@ def install(package):
|
||||
download_ui.logs_box.append("")
|
||||
download_ui.logs_box.append("Starting virustotal scan for dependency")
|
||||
download_ui.logs_box.moveCursor(QtGui.QTextCursor.End)
|
||||
scan_file('{2}apps/{0}/{1}'.format(r['name'], r['download'].split('/')[-1],
|
||||
scan_file('{2}apps/{0}/{1}'.format(r['name'], unquote(r['download'].split('/')[-1]),
|
||||
horsy_vars.horsypath))
|
||||
download_ui.logs_box.append(f"Scan finished for dependency")
|
||||
download_ui.logs_box.moveCursor(QtGui.QTextCursor.End)
|
||||
analysis = get_report('{2}apps/{0}/{1}'.format(r['name'], r['download'].split('/')[-1],
|
||||
analysis = get_report('{2}apps/{0}/{1}'.format(r['name'], unquote(r['download'].split('/')[-1]),
|
||||
horsy_vars.horsypath))
|
||||
download_ui.logs_box.append(f"You can see report for dependency by opening: {analysis['link']}")
|
||||
download_ui.logs_box.append(f"{analysis['detect']['malicious']} "
|
||||
@@ -139,7 +145,7 @@ def install(package):
|
||||
download_ui.logs_box.append("Generating launch script")
|
||||
with open('{1}apps/{0}.bat'.format(r['name'], horsy_vars.horsypath), 'w') as f:
|
||||
f.write(f"@ECHO off\n")
|
||||
f.write(f"""{r['run'].replace('$appdir$', f'%horsypath%/apps/{r["name"]}')} %*\n""")
|
||||
f.write(f""""{r['run'].replace('$appdir$', f'%horsypath%/apps/{r["name"]}')}" %*\n""")
|
||||
download_ui.logs_box.append("")
|
||||
download_ui.logs_box.moveCursor(QtGui.QTextCursor.End)
|
||||
|
||||
@@ -149,8 +155,17 @@ def install(package):
|
||||
download_ui.logs_box.moveCursor(QtGui.QTextCursor.End)
|
||||
threading.Thread(target=os.system, args=('{2}apps/{0}/{1}'.format(r['name'], r['install'],
|
||||
horsy_vars.horsypath),)).start()
|
||||
|
||||
# Update versions file
|
||||
with open(horsy_vars.horsypath + 'apps/versions.json', 'r') as f:
|
||||
versions = json.load(f)
|
||||
with open(horsy_vars.horsypath + 'apps/versions.json', 'w') as f:
|
||||
versions[r['name']] = r['version']
|
||||
f.write(json.dumps(versions))
|
||||
|
||||
download_ui.logs_box.append(f"All done!\nYou can run your app by entering {r['name']} in terminal")
|
||||
download_ui.logs_box.moveCursor(QtGui.QTextCursor.End)
|
||||
|
||||
threading.Thread(target=install_this).start()
|
||||
|
||||
except:
|
||||
|
||||
Reference in New Issue
Block a user