versions and updates for apps
better api requests system
This commit is contained in:
28
horsy.py
28
horsy.py
@@ -2,7 +2,7 @@ import argparse
|
|||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import requests
|
from modules.request import request
|
||||||
import modules.tui as tui
|
import modules.tui as tui
|
||||||
from modules.console import cls
|
from modules.console import cls
|
||||||
from modules.virustotal import add_to_cfg
|
from modules.virustotal import add_to_cfg
|
||||||
@@ -10,9 +10,9 @@ import modules.vars as horsy_vars
|
|||||||
|
|
||||||
# Getting the arguments
|
# Getting the arguments
|
||||||
parser = argparse.ArgumentParser(description='horsy - the best package manager')
|
parser = argparse.ArgumentParser(description='horsy - the best package manager')
|
||||||
parser.add_argument('option', help='options for horsy (install/i | uninstall/un | source/s | list/l | '
|
parser.add_argument('option', help='options for horsy (install/i | uninstall/un | updates/u | source/s | list/l | '
|
||||||
'upload | search | info | like | dislike)',
|
'upload | search | info | like | dislike)',
|
||||||
choices=['install', 'i', 'uninstall', 'un', 'source', 's', 'list', 'l', 'upload',
|
choices=['install', 'i', 'uninstall', 'un', 'updates', 'u', 'source', 's', 'list', 'l', 'upload',
|
||||||
'search', 'info', 'like', 'dislike'],
|
'search', 'info', 'like', 'dislike'],
|
||||||
nargs='?')
|
nargs='?')
|
||||||
parser.add_argument('app', help='app to do function with', nargs='?')
|
parser.add_argument('app', help='app to do function with', nargs='?')
|
||||||
@@ -43,7 +43,7 @@ except:
|
|||||||
print('Horsy may be not installed correctly. Please reinstall it or stop other horsy instances. '
|
print('Horsy may be not installed correctly. Please reinstall it or stop other horsy instances. '
|
||||||
'If you installed it just now, please restart PC.')
|
'If you installed it just now, please restart PC.')
|
||||||
|
|
||||||
if int(requests.get('https://github.com/horsy-ml/horsy/raw/master/web_vars/version').text) > version:
|
if int(request.get('https://github.com/horsy-ml/horsy/raw/master/web_vars/version').text) > version:
|
||||||
print('New version available!')
|
print('New version available!')
|
||||||
print('If you see this message again, or horsy doesn\'t launch itself for long time, please type '
|
print('If you see this message again, or horsy doesn\'t launch itself for long time, please type '
|
||||||
'horsy_updater in your terminal to update it manually.')
|
'horsy_updater in your terminal to update it manually.')
|
||||||
@@ -51,7 +51,7 @@ if int(requests.get('https://github.com/horsy-ml/horsy/raw/master/web_vars/versi
|
|||||||
print('Updating...')
|
print('Updating...')
|
||||||
print('Please wait, if process seems closed, its OK, just wait a bit.')
|
print('Please wait, if process seems closed, its OK, just wait a bit.')
|
||||||
with open(os.path.join(horsy_vars.horsypath) + '/horsy_updater.exe', 'wb') as f:
|
with open(os.path.join(horsy_vars.horsypath) + '/horsy_updater.exe', 'wb') as f:
|
||||||
f.write(requests.get('https://github.com/horsy-ml/horsy/raw/master/bin/horsy_updater.exe').content)
|
f.write(request.get('https://github.com/horsy-ml/horsy/raw/master/bin/horsy_updater.exe').content)
|
||||||
subprocess.Popen('horsy_updater.exe horsy', shell=True, close_fds=True)
|
subprocess.Popen('horsy_updater.exe horsy', shell=True, close_fds=True)
|
||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
@@ -87,12 +87,13 @@ if args.vt_key:
|
|||||||
# 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:
|
||||||
log_logo()
|
log_logo()
|
||||||
option = ['install', 'uninstall', 'source', 'list', 'upload', 'search', 'info'][
|
option = ['install', 'uninstall', 'updates', 'source', 'list', 'upload', 'search', 'info'][
|
||||||
tui.menu(['install app', 'uninstall app', 'get source', 'list of installed apps',
|
tui.menu(['install app', 'uninstall app', 'see updates', 'get source',
|
||||||
'upload your app', 'search for app', 'get information about app'])]
|
'list of installed apps', 'upload your app', 'search for app',
|
||||||
|
'get information about app'])]
|
||||||
isNoArgs = True
|
isNoArgs = True
|
||||||
|
|
||||||
if not args.app and option not in ['list', 'upload', 'update']:
|
if not args.app and option not in ['list', 'l', 'upload', 'updates', 'u']:
|
||||||
log_logo()
|
log_logo()
|
||||||
print('\n')
|
print('\n')
|
||||||
app = tui.get(f'Select app to {option}')
|
app = tui.get(f'Select app to {option}')
|
||||||
@@ -108,6 +109,15 @@ match option:
|
|||||||
case 'uninstall' | 'un':
|
case 'uninstall' | 'un':
|
||||||
from modules.manager import uninstall
|
from modules.manager import uninstall
|
||||||
uninstall(app)
|
uninstall(app)
|
||||||
|
case 'updates' | 'u':
|
||||||
|
from modules.updates import check
|
||||||
|
update_list = check()
|
||||||
|
if update_list:
|
||||||
|
print('Use following commands to update apps: \n')
|
||||||
|
for needs_update in update_list:
|
||||||
|
print(f'horsy i {needs_update}')
|
||||||
|
else:
|
||||||
|
print('No updates available')
|
||||||
case 'source' | 's':
|
case 'source' | 's':
|
||||||
from modules.source import get_source
|
from modules.source import get_source
|
||||||
get_source(app)
|
get_source(app)
|
||||||
|
|||||||
40
horsygui.py
40
horsygui.py
@@ -2,13 +2,12 @@ import os
|
|||||||
import sys
|
import sys
|
||||||
import math
|
import math
|
||||||
import threading
|
import threading
|
||||||
import time
|
|
||||||
import webbrowser
|
import webbrowser
|
||||||
import modules.vars as horsy_vars
|
import modules.vars as horsy_vars
|
||||||
|
from modules.request import request
|
||||||
from PyQt5 import QtWidgets
|
from PyQt5 import QtWidgets
|
||||||
import ctypes
|
import ctypes
|
||||||
import modules.gui as gui
|
import modules.gui as gui
|
||||||
import requests
|
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
|
||||||
@@ -46,16 +45,19 @@ def refresh_gui():
|
|||||||
installed_apps()
|
installed_apps()
|
||||||
|
|
||||||
|
|
||||||
def installed_apps():
|
def fill_installed(apps: list):
|
||||||
from modules.manager import apps_list
|
|
||||||
ui.installed_table.clear()
|
ui.installed_table.clear()
|
||||||
apps = apps_list(True)
|
|
||||||
ui.installed_table.setColumnCount(4)
|
ui.installed_table.setColumnCount(4)
|
||||||
ui.installed_table.setRowCount(math.ceil(len(apps) / 4))
|
ui.installed_table.setRowCount(math.ceil(len(apps) / 4))
|
||||||
for i in range(len(apps)):
|
for i in range(len(apps)):
|
||||||
ui.installed_table.setItem(i // 4, i % 4, QtWidgets.QTableWidgetItem(str(apps[i])))
|
ui.installed_table.setItem(i // 4, i % 4, QtWidgets.QTableWidgetItem(str(apps[i])))
|
||||||
|
|
||||||
|
|
||||||
|
def installed_apps():
|
||||||
|
from modules.manager import apps_list
|
||||||
|
fill_installed(apps_list(True))
|
||||||
|
|
||||||
|
|
||||||
def update_app():
|
def update_app():
|
||||||
try:
|
try:
|
||||||
app_name = ui.installed_table.currentItem().text().replace('!', '')
|
app_name = ui.installed_table.currentItem().text().replace('!', '')
|
||||||
@@ -63,6 +65,7 @@ def update_app():
|
|||||||
return
|
return
|
||||||
else:
|
else:
|
||||||
from modules.gui_manager import install
|
from modules.gui_manager import install
|
||||||
|
ui.installed_table.currentItem().setText(app_name)
|
||||||
install(app_name)
|
install(app_name)
|
||||||
except:
|
except:
|
||||||
return
|
return
|
||||||
@@ -109,10 +112,9 @@ def install_app():
|
|||||||
|
|
||||||
def check_updates():
|
def check_updates():
|
||||||
from modules.updates import check
|
from modules.updates import check
|
||||||
needupdate = check()
|
needupdate = check(True)
|
||||||
try:
|
try:
|
||||||
for module in needupdate:
|
fill_installed(needupdate)
|
||||||
print(module)
|
|
||||||
except:
|
except:
|
||||||
gui.cpopup("Error", str(needupdate))
|
gui.cpopup("Error", str(needupdate))
|
||||||
|
|
||||||
@@ -195,27 +197,20 @@ def login_logout_gui():
|
|||||||
|
|
||||||
def get_users_apps():
|
def get_users_apps():
|
||||||
def get_threaded():
|
def get_threaded():
|
||||||
apps = requests.get(f"{horsy_vars.protocol}{horsy_vars.server_url}/users/public"
|
|
||||||
f"/{ui.username_box.text()}").json()
|
|
||||||
try:
|
try:
|
||||||
if apps['message'] == 'Too many requests':
|
apps = request.get(f"{horsy_vars.protocol}{horsy_vars.server_url}/users/public"
|
||||||
while apps['message'] == 'Too many requests':
|
f"/{ui.username_box.text()}").json()
|
||||||
time.sleep(0.5)
|
|
||||||
apps = requests.get(f"{horsy_vars.protocol}{horsy_vars.server_url}/users/public"
|
|
||||||
f"/{ui.username_box.text()}").json()
|
|
||||||
except:
|
except:
|
||||||
pass
|
print("Error getting user apps")
|
||||||
try:
|
try:
|
||||||
apps = apps['packages']
|
apps = apps['packages']
|
||||||
ui.manage_packages_table.clear()
|
ui.manage_packages_table.clear()
|
||||||
ui.manage_packages_table.setColumnCount(4)
|
ui.manage_packages_table.setColumnCount(4)
|
||||||
ui.manage_packages_table.setRowCount(math.ceil(len(apps) / 4))
|
ui.manage_packages_table.setRowCount(math.ceil(len(apps) / 4))
|
||||||
print(math.ceil(len(apps) / 4))
|
|
||||||
print(apps)
|
|
||||||
for i in range(len(apps)):
|
for i in range(len(apps)):
|
||||||
ui.manage_packages_table.setItem(i // 4, i % 4, QtWidgets.QTableWidgetItem(str(apps[i])))
|
ui.manage_packages_table.setItem(i // 4, i % 4, QtWidgets.QTableWidgetItem(str(apps[i])))
|
||||||
except:
|
except:
|
||||||
pass
|
print("Error getting user apps")
|
||||||
threading.Thread(target=get_threaded).start()
|
threading.Thread(target=get_threaded).start()
|
||||||
|
|
||||||
|
|
||||||
@@ -252,6 +247,9 @@ if __name__ == "__main__":
|
|||||||
if not os.path.isfile(horsy_vars.horsypath + 'config.cfg'):
|
if not os.path.isfile(horsy_vars.horsypath + 'config.cfg'):
|
||||||
with open(horsy_vars.horsypath + 'config.cfg', 'w') as f:
|
with open(horsy_vars.horsypath + 'config.cfg', 'w') as f:
|
||||||
f.write('{}')
|
f.write('{}')
|
||||||
|
if not os.path.isfile(horsy_vars.horsypath + 'apps/versions.json'):
|
||||||
|
with open(horsy_vars.horsypath + 'apps/versions.json', 'w+') as f:
|
||||||
|
f.write('{}')
|
||||||
|
|
||||||
# Checking version
|
# Checking version
|
||||||
try:
|
try:
|
||||||
@@ -260,14 +258,14 @@ if __name__ == "__main__":
|
|||||||
gui.popup('Error', 'Horsy may be not installed correctly. Please reinstall it or stop another instances if '
|
gui.popup('Error', 'Horsy may be not installed correctly. Please reinstall it or stop another instances if '
|
||||||
'running. If you installed it just now, please restart PC.')
|
'running. If you installed it just now, please restart PC.')
|
||||||
version = int(f.read())
|
version = int(f.read())
|
||||||
if int(requests.get('https://github.com/horsy-ml/horsy/raw/master/web_vars/version').text) > version:
|
if int(request.get('https://github.com/horsy-ml/horsy/raw/master/web_vars/version').text) > version:
|
||||||
gui.popup('Update', 'New version available! \nWe appreciate your safety, so you need to update horsy.'
|
gui.popup('Update', 'New version available! \nWe appreciate your safety, so you need to update horsy.'
|
||||||
'\nPress OK and updater will download the latest version.\n'
|
'\nPress OK and updater will download the latest version.\n'
|
||||||
'If you see this message again, or horsy doesn\'t launch \n'
|
'If you see this message again, or horsy doesn\'t launch \n'
|
||||||
'itself for long time, please type horsy_updater in your terminal.')
|
'itself for long time, please type horsy_updater in your terminal.')
|
||||||
try:
|
try:
|
||||||
with open(os.path.join(horsy_vars.horsypath) + '/horsy_updater.exe', 'wb') as f:
|
with open(os.path.join(horsy_vars.horsypath) + '/horsy_updater.exe', 'wb') as f:
|
||||||
f.write(requests.get('https://github.com/horsy-ml/horsy/raw/master/bin/horsy_updater.exe').content)
|
f.write(request.get('https://github.com/horsy-ml/horsy/raw/master/bin/horsy_updater.exe').content)
|
||||||
except:
|
except:
|
||||||
gui.popup('Error', 'Could not download updater. \nMaybe installation folder is not writable '
|
gui.popup('Error', 'Could not download updater. \nMaybe installation folder is not writable '
|
||||||
'(only for admins).\n Please reinstall horsy or update it manually. \n'
|
'(only for admins).\n Please reinstall horsy or update it manually. \n'
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import requests
|
from modules.request import request
|
||||||
import modules.gui as gui
|
import modules.gui as gui
|
||||||
from modules.auth import get_auth
|
from modules.auth import get_auth
|
||||||
import modules.vars as horsy_vars
|
import modules.vars as horsy_vars
|
||||||
@@ -21,11 +21,12 @@ def change(email):
|
|||||||
try:
|
try:
|
||||||
def change_in_new_thread():
|
def change_in_new_thread():
|
||||||
try:
|
try:
|
||||||
r_code = handle(requests.put(horsy_vars.protocol + horsy_vars.server_url + '/users',
|
r_code = handle(request.put(horsy_vars.protocol + horsy_vars.server_url + '/users',
|
||||||
json={'auth': auth, 'email': email}).status_code)
|
json={'auth': auth, 'email': email}).status_code)
|
||||||
gui.cpopup("Changing email", r_code[0])
|
gui.cpopup("Changing email", r_code[0])
|
||||||
except:
|
except:
|
||||||
gui.cpopup('Error', 'Unexpected error.')
|
gui.cpopup('Error', 'Unexpected error.')
|
||||||
|
|
||||||
threading.Thread(target=change_in_new_thread).start()
|
threading.Thread(target=change_in_new_thread).start()
|
||||||
gui.popup('Started', 'Check your email for confirmation')
|
gui.popup('Started', 'Check your email for confirmation')
|
||||||
except:
|
except:
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import requests
|
from modules.request import request
|
||||||
import modules.gui as gui
|
import modules.gui as gui
|
||||||
from modules.auth import get_auth
|
from modules.auth import get_auth
|
||||||
import modules.vars as horsy_vars
|
import modules.vars as horsy_vars
|
||||||
@@ -27,8 +27,8 @@ def change(oldpass, newpass):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
gui.cpopup("Changing password",
|
gui.cpopup("Changing password",
|
||||||
handle(requests.put(horsy_vars.protocol + horsy_vars.server_url + '/users',
|
handle(request.put(horsy_vars.protocol + horsy_vars.server_url + '/users',
|
||||||
json={'auth': get_auth(True, login_ui, QtWidgets.QMainWindow()),
|
json={'auth': get_auth(True, login_ui, QtWidgets.QMainWindow()),
|
||||||
'password': newpass}).status_code)[0])
|
'password': newpass}).status_code)[0])
|
||||||
except:
|
except:
|
||||||
gui.popup('Error', 'Unexpected error.')
|
gui.popup('Error', 'Unexpected error.')
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import signal
|
|||||||
from functools import partial
|
from functools import partial
|
||||||
from threading import Event
|
from threading import Event
|
||||||
from urllib.request import urlopen
|
from urllib.request import urlopen
|
||||||
|
from urllib.parse import unquote
|
||||||
|
|
||||||
from rich.progress import (
|
from rich.progress import (
|
||||||
BarColumn,
|
BarColumn,
|
||||||
@@ -59,7 +60,7 @@ def dl(urls, dest_dir: str):
|
|||||||
with progress:
|
with progress:
|
||||||
with ThreadPoolExecutor(max_workers=len(urls)) as pool:
|
with ThreadPoolExecutor(max_workers=len(urls)) as pool:
|
||||||
for url in urls:
|
for url in urls:
|
||||||
filename = url.split("/")[-1]
|
filename = unquote(url.split("/")[-1])
|
||||||
dest_path = os.path.join(dest_dir, filename)
|
dest_path = os.path.join(dest_dir, filename)
|
||||||
task_id = progress.add_task("download", filename=filename, start=False)
|
task_id = progress.add_task("download", filename=filename, start=False)
|
||||||
pool.submit(copy_url, task_id, url, dest_path)
|
pool.submit(copy_url, task_id, url, dest_path)
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
import json
|
import json
|
||||||
import threading
|
import threading
|
||||||
from modules.http_status import handle
|
from modules.http_status import handle
|
||||||
|
from modules.request import request
|
||||||
import requests
|
import requests
|
||||||
import modules.vars as horsy_vars
|
import modules.vars as horsy_vars
|
||||||
import os
|
import os
|
||||||
@@ -9,10 +10,11 @@ from modules.virustotal import get_key, scan_file, get_report
|
|||||||
from horsygui import UiDownloadWindow, download_ui
|
from horsygui import UiDownloadWindow, download_ui
|
||||||
from modules.gui import cpopup
|
from modules.gui import cpopup
|
||||||
from PyQt5 import QtGui
|
from PyQt5 import QtGui
|
||||||
|
from urllib.parse import unquote
|
||||||
|
|
||||||
|
|
||||||
def install(package):
|
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_code = handle(r.status_code)
|
||||||
r = r.text
|
r = r.text
|
||||||
r = json.loads(r)
|
r = json.loads(r)
|
||||||
@@ -23,7 +25,7 @@ def install(package):
|
|||||||
try:
|
try:
|
||||||
UiDownloadWindow.show()
|
UiDownloadWindow.show()
|
||||||
download_ui.logs_box.clear()
|
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():
|
def install_this():
|
||||||
if not os.path.exists('{1}apps/{0}'.format(r['name'], horsy_vars.horsypath)):
|
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)
|
file_r = requests.get(r['url'], stream=True)
|
||||||
chunk_size = int(int(file_r.headers['Content-Length']) / 100)
|
chunk_size = int(int(file_r.headers['Content-Length']) / 100)
|
||||||
percent = 0
|
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):
|
for chunk in file_r.iter_content(chunk_size=chunk_size):
|
||||||
if chunk:
|
if chunk:
|
||||||
percent += 1
|
percent += 1
|
||||||
@@ -47,15 +50,15 @@ def install(package):
|
|||||||
threads.append(threading.Thread(target=dl_main_file))
|
threads.append(threading.Thread(target=dl_main_file))
|
||||||
|
|
||||||
if r['download']:
|
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)
|
download_ui.logs_box.moveCursor(QtGui.QTextCursor.End)
|
||||||
|
|
||||||
def dl_dep_file():
|
def dl_dep_file():
|
||||||
global success
|
global success
|
||||||
file_r = requests.get(r['download'], stream=True)
|
file_r = requests.get(r['download'], stream=True)
|
||||||
chunk_size = int(int(file_r.headers['Content-Length']) / 100)
|
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),
|
with open('{2}apps/{0}/{1}'.format(r['name'], unquote(r['download'].split('/')[-1]),
|
||||||
"wb") as f:
|
horsy_vars.horsypath), "wb") as f:
|
||||||
for chunk in file_r.iter_content(chunk_size=chunk_size):
|
for chunk in file_r.iter_content(chunk_size=chunk_size):
|
||||||
if chunk:
|
if chunk:
|
||||||
f.write(chunk)
|
f.write(chunk)
|
||||||
@@ -78,9 +81,9 @@ def install(package):
|
|||||||
download_ui.logs_box.moveCursor(QtGui.QTextCursor.End)
|
download_ui.logs_box.moveCursor(QtGui.QTextCursor.End)
|
||||||
|
|
||||||
if r['url'].split('.')[-1] == 'zip':
|
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)
|
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))
|
'{1}apps/{0}'.format(r['name'], horsy_vars.horsypath))
|
||||||
|
|
||||||
download_ui.logs_box.append("")
|
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("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.append("Starting virustotal scan for program")
|
||||||
download_ui.logs_box.moveCursor(QtGui.QTextCursor.End)
|
download_ui.logs_box.moveCursor(QtGui.QTextCursor.End)
|
||||||
scan_file('{2}apps/{0}/{1}'.format(r['name'], r['url'].split('/')[-1], horsy_vars.horsypath))
|
scan_file('{2}apps/{0}/{1}'.format(r['name'], unquote(r['url'].split('/')[-1]),
|
||||||
analysis = get_report('{2}apps/{0}/{1}'.format(r['name'], 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))
|
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['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)
|
download_ui.logs_box.moveCursor(QtGui.QTextCursor.End)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
@@ -110,11 +116,11 @@ def install(package):
|
|||||||
download_ui.logs_box.append("")
|
download_ui.logs_box.append("")
|
||||||
download_ui.logs_box.append("Starting virustotal scan for dependency")
|
download_ui.logs_box.append("Starting virustotal scan for dependency")
|
||||||
download_ui.logs_box.moveCursor(QtGui.QTextCursor.End)
|
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))
|
horsy_vars.horsypath))
|
||||||
download_ui.logs_box.append(f"Scan finished for dependency")
|
download_ui.logs_box.append(f"Scan finished for dependency")
|
||||||
download_ui.logs_box.moveCursor(QtGui.QTextCursor.End)
|
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))
|
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"You can see report for dependency by opening: {analysis['link']}")
|
||||||
download_ui.logs_box.append(f"{analysis['detect']['malicious']} "
|
download_ui.logs_box.append(f"{analysis['detect']['malicious']} "
|
||||||
@@ -139,7 +145,7 @@ def install(package):
|
|||||||
download_ui.logs_box.append("Generating launch script")
|
download_ui.logs_box.append("Generating launch script")
|
||||||
with open('{1}apps/{0}.bat'.format(r['name'], horsy_vars.horsypath), 'w') as f:
|
with open('{1}apps/{0}.bat'.format(r['name'], horsy_vars.horsypath), 'w') as f:
|
||||||
f.write(f"@ECHO off\n")
|
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.append("")
|
||||||
download_ui.logs_box.moveCursor(QtGui.QTextCursor.End)
|
download_ui.logs_box.moveCursor(QtGui.QTextCursor.End)
|
||||||
|
|
||||||
@@ -149,8 +155,17 @@ def install(package):
|
|||||||
download_ui.logs_box.moveCursor(QtGui.QTextCursor.End)
|
download_ui.logs_box.moveCursor(QtGui.QTextCursor.End)
|
||||||
threading.Thread(target=os.system, args=('{2}apps/{0}/{1}'.format(r['name'], r['install'],
|
threading.Thread(target=os.system, args=('{2}apps/{0}/{1}'.format(r['name'], r['install'],
|
||||||
horsy_vars.horsypath),)).start()
|
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.append(f"All done!\nYou can run your app by entering {r['name']} in terminal")
|
||||||
download_ui.logs_box.moveCursor(QtGui.QTextCursor.End)
|
download_ui.logs_box.moveCursor(QtGui.QTextCursor.End)
|
||||||
|
|
||||||
threading.Thread(target=install_this).start()
|
threading.Thread(target=install_this).start()
|
||||||
|
|
||||||
except:
|
except:
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import requests
|
from modules.request import request
|
||||||
import modules.vars as horsy_vars
|
import modules.vars as horsy_vars
|
||||||
from modules.auth import get_auth
|
from modules.auth import get_auth
|
||||||
|
|
||||||
@@ -17,6 +17,6 @@ def send(package, type, is_gui=False, login_ui=None, Ui_LoginWindow=None):
|
|||||||
"rate": type,
|
"rate": type,
|
||||||
"packageName": package
|
"packageName": package
|
||||||
}
|
}
|
||||||
r = requests.post(f"{horsy_vars.protocol}{horsy_vars.server_url}/packages/rate", json=body).json()
|
r = request.post(f"{horsy_vars.protocol}{horsy_vars.server_url}/packages/rate", json=body).json()
|
||||||
print(r["message"])
|
print(r["message"])
|
||||||
return r["message"]
|
return r["message"]
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import requests
|
from modules.request import request
|
||||||
from PyQt5 import QtWidgets
|
from PyQt5 import QtWidgets
|
||||||
import modules.gui as gui
|
import modules.gui as gui
|
||||||
from modules.auth import get_auth, del_auth
|
from modules.auth import get_auth, del_auth
|
||||||
@@ -14,9 +14,9 @@ def loginload():
|
|||||||
with open(horsy_vars.horsypath + 'config.cfg') as f:
|
with open(horsy_vars.horsypath + 'config.cfg') as f:
|
||||||
config = json.load(f)
|
config = json.load(f)
|
||||||
if config['auth'] is not None:
|
if config['auth'] is not None:
|
||||||
return (lambda x: (x if x != "Forbidden" else "Invalid login"))\
|
return (lambda x: (x if x != "Forbidden" else "Invalid login")) \
|
||||||
(requests.get(horsy_vars.protocol + horsy_vars.server_url + '/users/login',
|
(request.get(horsy_vars.protocol + horsy_vars.server_url + '/users/login',
|
||||||
json={'auth': config['auth']}).json()['message'])
|
json={'auth': config['auth']}).json()['message'])
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import json
|
import json
|
||||||
import threading
|
import threading
|
||||||
from rich import print
|
from rich import print
|
||||||
import requests
|
from modules.request import request
|
||||||
import modules.vars as horsy_vars
|
import modules.vars as horsy_vars
|
||||||
import os
|
import os
|
||||||
import zipfile
|
import zipfile
|
||||||
@@ -11,7 +11,7 @@ from modules.download import dl
|
|||||||
|
|
||||||
|
|
||||||
def install(package):
|
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_code = handle(r.status_code)
|
||||||
r = r.text
|
r = r.text
|
||||||
r = json.loads(r)
|
r = json.loads(r)
|
||||||
@@ -78,7 +78,15 @@ def install(package):
|
|||||||
|
|
||||||
with open('{1}apps\{0}.bat'.format(r['name'], horsy_vars.horsypath), 'w+') as f:
|
with open('{1}apps\{0}.bat'.format(r['name'], horsy_vars.horsypath), 'w+') as f:
|
||||||
f.write(f"@ECHO off\n")
|
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""")
|
||||||
|
|
||||||
|
# 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))
|
||||||
|
print(f"Versions file updated")
|
||||||
|
|
||||||
# Done message
|
# Done message
|
||||||
print(f"[green][OK] All done![/]")
|
print(f"[green][OK] All done![/]")
|
||||||
@@ -114,4 +122,4 @@ def apps_list(is_gui=False):
|
|||||||
elif file.endswith(".bat"):
|
elif file.endswith(".bat"):
|
||||||
apps.append(file.split('.')[0])
|
apps.append(file.split('.')[0])
|
||||||
if is_gui:
|
if is_gui:
|
||||||
return apps
|
return sorted(apps)
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from modules.auth import get_auth
|
from modules.auth import get_auth
|
||||||
from horsygui import login_ui, UiLoginWindow as Ui_LoginWindow
|
from horsygui import login_ui, UiLoginWindow as Ui_LoginWindow
|
||||||
import modules.gui as gui
|
import modules.gui as gui
|
||||||
import requests
|
from modules.request import request
|
||||||
import modules.vars as horsy_vars
|
import modules.vars as horsy_vars
|
||||||
from modules.http_status import handle
|
from modules.http_status import handle
|
||||||
import json
|
import json
|
||||||
@@ -11,7 +11,7 @@ def edit(package, UiPackageWindow):
|
|||||||
package_ui = gui.Ui_PackageWindow()
|
package_ui = gui.Ui_PackageWindow()
|
||||||
package_ui.setupUi(UiPackageWindow)
|
package_ui.setupUi(UiPackageWindow)
|
||||||
|
|
||||||
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}")
|
||||||
try:
|
try:
|
||||||
r_code = handle(r.status_code)
|
r_code = handle(r.status_code)
|
||||||
if r_code[1] not in [200, 201]:
|
if r_code[1] not in [200, 201]:
|
||||||
@@ -44,15 +44,15 @@ def edit(package, UiPackageWindow):
|
|||||||
}
|
}
|
||||||
|
|
||||||
gui.cpopup("Updating",
|
gui.cpopup("Updating",
|
||||||
handle(requests.put(f"{horsy_vars.protocol}{horsy_vars.server_url}/packages",
|
handle(request.put(f"{horsy_vars.protocol}{horsy_vars.server_url}/packages",
|
||||||
json=body).status_code)[0])
|
json=body).status_code)[0])
|
||||||
|
|
||||||
package_ui.update_button.clicked.connect(send)
|
package_ui.update_button.clicked.connect(send)
|
||||||
|
|
||||||
|
|
||||||
def push_version(package):
|
def push_version(package):
|
||||||
gui.cpopup("Pushing version",
|
gui.cpopup("Pushing version",
|
||||||
handle(requests.post(f"{horsy_vars.protocol}{horsy_vars.server_url}/packages/push-version", json={
|
handle(request.post(f"{horsy_vars.protocol}{horsy_vars.server_url}/packages/push-version", json={
|
||||||
'auth': get_auth(True, login_ui, Ui_LoginWindow),
|
'auth': get_auth(True, login_ui, Ui_LoginWindow),
|
||||||
'name': package
|
'name': package
|
||||||
}).status_code)[0])
|
}).status_code)[0])
|
||||||
|
|||||||
29
modules/request.py
Normal file
29
modules/request.py
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import time
|
||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
|
class request:
|
||||||
|
@staticmethod
|
||||||
|
def _request(url, method, json=None):
|
||||||
|
while True:
|
||||||
|
r = requests.request(method, url, json=json)
|
||||||
|
if r.status_code != 429:
|
||||||
|
return r
|
||||||
|
else:
|
||||||
|
time.sleep(0.5)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def get(url, json=None):
|
||||||
|
return request._request(url, 'GET', json=json)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def post(url, json=None):
|
||||||
|
return request._request(url, 'POST', json=json)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def put(url, json):
|
||||||
|
return request._request(url, 'PUT', json=json)
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def delete(url):
|
||||||
|
return request._request(url, 'DELETE')
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import textwrap
|
import textwrap
|
||||||
from algoliasearch.search_client import SearchClient
|
from algoliasearch.search_client import SearchClient
|
||||||
import os
|
import os
|
||||||
|
from modules.request import request
|
||||||
import requests
|
import requests
|
||||||
import modules.vars as horsy_vars
|
import modules.vars as horsy_vars
|
||||||
import json
|
import json
|
||||||
@@ -27,7 +28,7 @@ def search(query, is_gui=False):
|
|||||||
|
|
||||||
|
|
||||||
def info(package, download_ui=None, UiDownloadWindow=None):
|
def info(package, download_ui=None, UiDownloadWindow=None):
|
||||||
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_code = handle(r.status_code)
|
||||||
r = r.text
|
r = r.text
|
||||||
r = json.loads(r)
|
r = json.loads(r)
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import requests
|
from modules.request import request
|
||||||
import json
|
import json
|
||||||
import webbrowser
|
import webbrowser
|
||||||
import modules.vars as horsy_vars
|
import modules.vars as horsy_vars
|
||||||
@@ -7,7 +7,7 @@ from modules.http_status import handle
|
|||||||
|
|
||||||
|
|
||||||
def get_source(package):
|
def get_source(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_code = handle(r.status_code)
|
||||||
if r_code[1] not in [200, 201]:
|
if r_code[1] not in [200, 201]:
|
||||||
return r_code[0]
|
return r_code[0]
|
||||||
|
|||||||
@@ -1,22 +1,44 @@
|
|||||||
import json
|
import json
|
||||||
import requests
|
from modules.request import request
|
||||||
import modules.vars as horsy_vars
|
import modules.vars as horsy_vars
|
||||||
from modules.http_status import handle
|
from modules.http_status import handle
|
||||||
from modules.manager import apps_list
|
from modules.manager import apps_list
|
||||||
from rich import print
|
from rich import print
|
||||||
|
|
||||||
|
|
||||||
def check():
|
def check(gui=False):
|
||||||
r = requests.get(f"{horsy_vars.protocol}{horsy_vars.server_url}/packages/json/"
|
r = request.get(f"{horsy_vars.protocol}{horsy_vars.server_url}/packages/json/"
|
||||||
f"{','.join(apps_list(True))}")
|
f"{','.join(apps_list(True))}")
|
||||||
r_code = handle(r.status_code)
|
r_code = handle(r.status_code)
|
||||||
|
|
||||||
if r_code[1] not in [200, 201]:
|
if r_code[1] not in [200, 201]:
|
||||||
return r_code[0]
|
return r_code[0]
|
||||||
r = r.text
|
r = r.text
|
||||||
r = json.loads(r)
|
r = json.loads(r)
|
||||||
print(r)
|
|
||||||
|
|
||||||
update_this = list()
|
with open(horsy_vars.horsypath + 'apps/versions.json', 'r') as f:
|
||||||
|
versions = json.load(f)
|
||||||
|
|
||||||
return update_this
|
need_update = list()
|
||||||
|
for app in r:
|
||||||
|
try:
|
||||||
|
if versions[app] < r[app]['version']:
|
||||||
|
need_update.append(app)
|
||||||
|
except (TypeError, KeyError):
|
||||||
|
if r[app]['version'] > 0:
|
||||||
|
need_update.append(app)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"[red]Unexpected error![/]")
|
||||||
|
print(e)
|
||||||
|
need_update.sort()
|
||||||
|
|
||||||
|
if not gui:
|
||||||
|
return need_update
|
||||||
|
|
||||||
|
apps = list()
|
||||||
|
for app in apps_list(True):
|
||||||
|
if app in need_update:
|
||||||
|
apps.append("!" + app)
|
||||||
|
else:
|
||||||
|
apps.append(app)
|
||||||
|
return sorted(apps)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import json
|
import json
|
||||||
import time
|
import time
|
||||||
import requests
|
from modules.request import request
|
||||||
from rich import print
|
from rich import print
|
||||||
from modules.auth import get_auth, del_auth, get_auth_without_login
|
from modules.auth import get_auth, del_auth, get_auth_without_login
|
||||||
import re
|
import re
|
||||||
@@ -83,7 +83,7 @@ def upload(is_gui=False, ui=None):
|
|||||||
print('[red]Please, specify runtime[/red]')
|
print('[red]Please, specify runtime[/red]')
|
||||||
run = None
|
run = None
|
||||||
|
|
||||||
request = {
|
request_body = {
|
||||||
'auth': auth,
|
'auth': auth,
|
||||||
'name': project_name,
|
'name': project_name,
|
||||||
'description': description,
|
'description': description,
|
||||||
@@ -127,7 +127,7 @@ def upload(is_gui=False, ui=None):
|
|||||||
if run == '':
|
if run == '':
|
||||||
return 'Please, specify runtime'
|
return 'Please, specify runtime'
|
||||||
|
|
||||||
request = {
|
request_body = {
|
||||||
'auth': auth,
|
'auth': auth,
|
||||||
'name': project_name,
|
'name': project_name,
|
||||||
'description': description,
|
'description': description,
|
||||||
@@ -141,7 +141,7 @@ def upload(is_gui=False, ui=None):
|
|||||||
r = None
|
r = None
|
||||||
while r is None:
|
while r is None:
|
||||||
try:
|
try:
|
||||||
r = requests.post(horsy_vars.protocol + horsy_vars.server_url + '/packages/new', json=request)
|
r = request.post(horsy_vars.protocol + horsy_vars.server_url + '/packages/new', json=request_body)
|
||||||
r_code = handle(r.status_code)
|
r_code = handle(r.status_code)
|
||||||
r = r.text
|
r = r.text
|
||||||
r = json.loads(r)
|
r = json.loads(r)
|
||||||
@@ -150,15 +150,15 @@ def upload(is_gui=False, ui=None):
|
|||||||
print('[red]Invalid credentials[/red]')
|
print('[red]Invalid credentials[/red]')
|
||||||
print('Deleting auth from config')
|
print('Deleting auth from config')
|
||||||
del_auth()
|
del_auth()
|
||||||
request['auth'] = get_auth()
|
request_body['auth'] = get_auth()
|
||||||
print(r)
|
print(r)
|
||||||
r = None
|
r = None
|
||||||
|
|
||||||
elif r_code[1] in [200, 201]:
|
elif r_code[1] in [200, 201]:
|
||||||
print('[green]Success, your project is created. You can install it by running[/] '
|
print('[green]Success, your project is created. You can install it by running[/] '
|
||||||
'[i]horsy i {0}[/]'.format(request['name']))
|
'[i]horsy i {0}[/]'.format(request_body['name']))
|
||||||
return 'Success, your project is created. You can install it by running horsy i {0}'.format(
|
return 'Success, your project is created. You can install it by running horsy i {0}'.format(
|
||||||
request['name'])
|
request_body['name'])
|
||||||
|
|
||||||
return r_code[0]
|
return r_code[0]
|
||||||
except:
|
except:
|
||||||
|
|||||||
Reference in New Issue
Block a user