Final refactor
Dev
This commit is contained in:
@@ -1,4 +1,6 @@
|
|||||||
import json
|
import json
|
||||||
|
import sys
|
||||||
|
|
||||||
import modules.vars as horsy_vars
|
import modules.vars as horsy_vars
|
||||||
import ctypes
|
import ctypes
|
||||||
|
|
||||||
@@ -33,6 +35,22 @@ def get_auth(is_gui=False, login_ui=None, Ui_LoginWindow=None):
|
|||||||
login_ui.login_button.clicked.connect(load_login_now)
|
login_ui.login_button.clicked.connect(load_login_now)
|
||||||
|
|
||||||
|
|
||||||
|
def get_auth_without_login(is_gui=False):
|
||||||
|
with open(horsy_vars.horsypath + 'config.cfg') as f:
|
||||||
|
config = json.load(f)
|
||||||
|
|
||||||
|
try:
|
||||||
|
if config['auth']:
|
||||||
|
return config['auth']
|
||||||
|
else:
|
||||||
|
raise Exception('No auth found')
|
||||||
|
except:
|
||||||
|
ctypes.windll.user32.MessageBoxW(0, "Login not found. Please, use the login button on account tab. "
|
||||||
|
"horsy will close now, but you don't need to restart it later",
|
||||||
|
"No auth", 0)
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
|
||||||
def get_gui_auth(login_ui, Ui_LoginWindow):
|
def get_gui_auth(login_ui, Ui_LoginWindow):
|
||||||
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)
|
||||||
|
|||||||
20
modules/download.py
Normal file
20
modules/download.py
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
import threading
|
||||||
|
from tqdm import tqdm
|
||||||
|
import requests
|
||||||
|
|
||||||
|
|
||||||
|
def dl(urls, save_to):
|
||||||
|
for url in urls:
|
||||||
|
def dl_thread(url_in_thread):
|
||||||
|
with requests.get(url_in_thread, stream=True) as r:
|
||||||
|
with open(save_to, "wb") as f:
|
||||||
|
pbar = tqdm(unit="B", unit_scale=True, total=int(r.headers['Content-Length']),
|
||||||
|
position=urls.index(url_in_thread))
|
||||||
|
for chunk in r.iter_content(chunk_size=1024):
|
||||||
|
if chunk:
|
||||||
|
if pbar.n < pbar.total - 1:
|
||||||
|
pbar.update(len(chunk))
|
||||||
|
f.write(chunk)
|
||||||
|
pbar.clear()
|
||||||
|
|
||||||
|
threading.Thread(target=dl_thread, args=(url,)).start()
|
||||||
@@ -73,7 +73,7 @@ codes = {'CONTINUE': 100,
|
|||||||
406: 'NOT_ACCEPTABLE',
|
406: 'NOT_ACCEPTABLE',
|
||||||
407: 'PROXY_AUTHENTICATION_REQUIRED',
|
407: 'PROXY_AUTHENTICATION_REQUIRED',
|
||||||
408: 'REQUEST_TIMEOUT',
|
408: 'REQUEST_TIMEOUT',
|
||||||
409: 'CONFLICT',
|
409: 'You are trying to create a resource with name that already exists',
|
||||||
410: 'GONE',
|
410: 'GONE',
|
||||||
411: 'LENGTH_REQUIRED',
|
411: 'LENGTH_REQUIRED',
|
||||||
412: 'PRECONDITION_FAILED',
|
412: 'PRECONDITION_FAILED',
|
||||||
|
|||||||
@@ -7,24 +7,17 @@ from tqdm import tqdm
|
|||||||
import os
|
import os
|
||||||
import zipfile
|
import zipfile
|
||||||
from modules.virustotal import get_key, scan_file, get_report
|
from modules.virustotal import get_key, scan_file, get_report
|
||||||
|
from modules.http_status import handle
|
||||||
|
|
||||||
|
|
||||||
def install(package):
|
def install(package):
|
||||||
r = requests.get(f"{horsy_vars.protocol}{horsy_vars.server_url}/packages/json/{package}").text
|
r = requests.get(f"{horsy_vars.protocol}{horsy_vars.server_url}/packages/json/{package}")
|
||||||
if r == "":
|
r_code = handle(r.status_code)
|
||||||
print(f"[red]Package {package} not found[/]")
|
r = r.text
|
||||||
return
|
r = json.loads(r)
|
||||||
try:
|
|
||||||
r = json.loads(r)
|
if r_code[1] not in [403, 401]:
|
||||||
except:
|
print(r_code[0])
|
||||||
print("[red]Error with unsupported message[/]")
|
|
||||||
return
|
|
||||||
try:
|
|
||||||
if r["message"] == "Internal server error":
|
|
||||||
print("[red]Internal server error[/]")
|
|
||||||
return
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
print(f"[green]App {r['name']} found, information loaded[/]")
|
print(f"[green]App {r['name']} found, information loaded[/]")
|
||||||
@@ -32,7 +25,6 @@ def install(package):
|
|||||||
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)):
|
||||||
os.makedirs('{1}apps/{0}'.format(r['name'], horsy_vars.horsypath))
|
os.makedirs('{1}apps/{0}'.format(r['name'], horsy_vars.horsypath))
|
||||||
|
|
||||||
# if not is_gui:
|
|
||||||
print(f"Downloading {r['url'].split('/')[-1]}")
|
print(f"Downloading {r['url'].split('/')[-1]}")
|
||||||
|
|
||||||
chunk_size = 1024
|
chunk_size = 1024
|
||||||
@@ -110,6 +102,7 @@ def install(package):
|
|||||||
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()
|
||||||
|
|
||||||
|
# Launch script
|
||||||
print(f"Generating launch script")
|
print(f"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:
|
||||||
@@ -118,6 +111,7 @@ def install(package):
|
|||||||
f.write(f"cd %horsypath%/apps/{r['name']}\n")
|
f.write(f"cd %horsypath%/apps/{r['name']}\n")
|
||||||
f.write(f"{r['run']} %*\n")
|
f.write(f"{r['run']} %*\n")
|
||||||
|
|
||||||
|
# Done message
|
||||||
print(f"[green][OK] All done![/]")
|
print(f"[green][OK] All done![/]")
|
||||||
print(f"[green]You can run your app by entering [italic white]{r['name']}[/] in terminal[/]")
|
print(f"[green]You can run your app by entering [italic white]{r['name']}[/] in terminal[/]")
|
||||||
|
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ import json
|
|||||||
import time
|
import time
|
||||||
import requests
|
import requests
|
||||||
from rich import print
|
from rich import print
|
||||||
from modules.auth import get_auth, del_auth
|
from modules.auth import get_auth, del_auth, get_auth_without_login
|
||||||
import re
|
import re
|
||||||
import modules.vars as horsy_vars
|
import modules.vars as horsy_vars
|
||||||
import os
|
import os
|
||||||
@@ -94,7 +94,7 @@ def upload(is_gui=False, ui=None, login_ui=None, Ui_LoginWindow=None):
|
|||||||
}
|
}
|
||||||
|
|
||||||
else:
|
else:
|
||||||
auth = get_auth(is_gui, login_ui, Ui_LoginWindow)
|
auth = get_auth_without_login(is_gui)
|
||||||
|
|
||||||
project_name = ui.packagename_box.text()
|
project_name = ui.packagename_box.text()
|
||||||
if not matches(project_name) or len(project_name) > 64 or len(project_name) < 3:
|
if not matches(project_name) or len(project_name) > 64 or len(project_name) < 3:
|
||||||
@@ -153,7 +153,7 @@ def upload(is_gui=False, ui=None, login_ui=None, Ui_LoginWindow=None):
|
|||||||
print(r)
|
print(r)
|
||||||
r = None
|
r = None
|
||||||
|
|
||||||
elif r_code == 200:
|
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['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(
|
||||||
|
|||||||
Reference in New Issue
Block a user