New handling system everywhere
This commit is contained in:
@@ -1,6 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
import modules.vars as horsy_vars
|
import modules.vars as horsy_vars
|
||||||
import ctypes
|
import ctypes
|
||||||
|
|
||||||
@@ -35,7 +34,7 @@ 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):
|
def get_auth_without_login():
|
||||||
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)
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
import requests
|
import requests
|
||||||
import modules.gui as gui
|
import modules.gui as gui
|
||||||
from modules.auth import del_auth, get_auth
|
from modules.auth import get_auth
|
||||||
import modules.vars as horsy_vars
|
import modules.vars as horsy_vars
|
||||||
import json
|
|
||||||
import threading
|
import threading
|
||||||
from PyQt5 import QtWidgets
|
from PyQt5 import QtWidgets
|
||||||
|
from modules.http_status import handle
|
||||||
|
|
||||||
|
|
||||||
def change(email):
|
def change(email):
|
||||||
@@ -21,34 +21,10 @@ def change(email):
|
|||||||
try:
|
try:
|
||||||
def change_in_new_thread():
|
def change_in_new_thread():
|
||||||
try:
|
try:
|
||||||
r = requests.put(horsy_vars.protocol + horsy_vars.server_url + '/users',
|
r_code = handle(requests.put(horsy_vars.protocol + horsy_vars.server_url + '/users',
|
||||||
json={'auth': auth, 'email': email})
|
json={'auth': auth, 'email': email}).status_code)
|
||||||
try:
|
if r_code[1] not in [200, 201]:
|
||||||
r = r.json()
|
gui.cpopup("Error", r_code[1])
|
||||||
except:
|
|
||||||
if r.text == '':
|
|
||||||
gui.cpopup('Success', 'Success, your email has been changed')
|
|
||||||
with open(horsy_vars.horsypath + 'config.cfg') as f:
|
|
||||||
config = json.load(f)
|
|
||||||
config['auth'] = {'email': email, 'password': config['auth']['password']}
|
|
||||||
with open(horsy_vars.horsypath + 'config.cfg', 'w') as f:
|
|
||||||
json.dump(config, f)
|
|
||||||
try:
|
|
||||||
if r['message'] == 'Unauthorized':
|
|
||||||
gui.cpopup('Error', 'Invalid credentials \nDeleting auth from config')
|
|
||||||
del_auth()
|
|
||||||
|
|
||||||
elif r['message'] == 'Internal server error':
|
|
||||||
gui.cpopup('Error', 'Internal server error')
|
|
||||||
return 'Internal server error'
|
|
||||||
|
|
||||||
else:
|
|
||||||
print('Unknown error, please try again')
|
|
||||||
print('Server response:')
|
|
||||||
print(r.text)
|
|
||||||
return 'Unknown error, please try again, \n Server response: \n' + str(r.text)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
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()
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
import requests
|
import requests
|
||||||
import modules.gui as gui
|
import modules.gui as gui
|
||||||
from modules.auth import del_auth, get_auth
|
from modules.auth import get_auth
|
||||||
import modules.vars as horsy_vars
|
import modules.vars as horsy_vars
|
||||||
import json
|
from modules.http_status import handle
|
||||||
from PyQt5 import QtWidgets
|
from PyQt5 import QtWidgets
|
||||||
|
|
||||||
|
|
||||||
@@ -26,34 +26,9 @@ def change(oldpass, newpass):
|
|||||||
return
|
return
|
||||||
|
|
||||||
try:
|
try:
|
||||||
r = requests.put(horsy_vars.protocol + horsy_vars.server_url + '/users',
|
gui.cpopup("Changing password",
|
||||||
json={'auth': get_auth(True, login_ui, QtWidgets.QMainWindow()),
|
handle(requests.put(horsy_vars.protocol + horsy_vars.server_url + '/users',
|
||||||
'password': newpass})
|
json={'auth': get_auth(True, login_ui, QtWidgets.QMainWindow()),
|
||||||
try:
|
'password': newpass}).status_code)[1])
|
||||||
r = r.json()
|
|
||||||
except:
|
|
||||||
if r.text == '':
|
|
||||||
gui.popup('Success', 'Success, your password has been changed')
|
|
||||||
with open(horsy_vars.horsypath + 'config.cfg') as f:
|
|
||||||
config = json.load(f)
|
|
||||||
config['auth'] = {'email': config['auth']['email'], 'password': newpass}
|
|
||||||
with open(horsy_vars.horsypath + 'config.cfg', 'w') as f:
|
|
||||||
json.dump(config, f)
|
|
||||||
try:
|
|
||||||
if r['message'] == 'Unauthorized':
|
|
||||||
gui.popup('Error', 'Invalid credentials \nDeleting auth from config')
|
|
||||||
del_auth()
|
|
||||||
|
|
||||||
elif r['message'] == 'Internal server error':
|
|
||||||
gui.popup('Error', 'Internal server error')
|
|
||||||
return 'Internal server error'
|
|
||||||
|
|
||||||
else:
|
|
||||||
print('Unknown error, please try again')
|
|
||||||
print('Server response:')
|
|
||||||
print(r)
|
|
||||||
return 'Unknown error, please try again, \n Server response: \n' + str(r)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
except:
|
except:
|
||||||
gui.popup('Error', 'Unexpected error.')
|
gui.popup('Error', 'Unexpected error.')
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
import time
|
|
||||||
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
|
import requests
|
||||||
import modules.vars as horsy_vars
|
import modules.vars as horsy_vars
|
||||||
import modules.http_status as status
|
from modules.http_status import handle
|
||||||
import json
|
import json
|
||||||
|
|
||||||
|
|
||||||
@@ -12,33 +11,13 @@ 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}").text
|
r = requests.get(f"{horsy_vars.protocol}{horsy_vars.server_url}/packages/json/{package}")
|
||||||
if r == "":
|
|
||||||
gui.cpopup("Installation", f"Package {package} not found")
|
|
||||||
return f"Package {package} not found"
|
|
||||||
try:
|
try:
|
||||||
|
r_code = handle(r.status_code)
|
||||||
|
if r_code[1] not in [200, 201]:
|
||||||
|
gui.cpopup("Error", r_code[1])
|
||||||
|
r = r.text
|
||||||
r = json.loads(r)
|
r = json.loads(r)
|
||||||
except:
|
|
||||||
print("[red]Error with unsupported message[/]")
|
|
||||||
gui.cpopup("Error", "Error with unsupported message")
|
|
||||||
return "Error with unsupported message"
|
|
||||||
try:
|
|
||||||
if r["message"] == "Internal server error":
|
|
||||||
print("Internal server error")
|
|
||||||
gui.cpopup("Error", "Internal server error")
|
|
||||||
return "Internal server error"
|
|
||||||
if r["message"] == "Too many requests":
|
|
||||||
try:
|
|
||||||
if r['message'] == 'Too many requests':
|
|
||||||
while r['message'] == 'Too many requests':
|
|
||||||
time.sleep(0.5)
|
|
||||||
r = requests.get(f"{horsy_vars.protocol}{horsy_vars.server_url}/packages/json/{package}").text
|
|
||||||
try:
|
|
||||||
r = json.loads(r)
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -64,20 +43,6 @@ def edit(package, UiPackageWindow):
|
|||||||
'run': (lambda x: x if x != '' else None)(package_ui.main_exe_box.text())
|
'run': (lambda x: x if x != '' else None)(package_ui.main_exe_box.text())
|
||||||
}
|
}
|
||||||
|
|
||||||
r = requests.put(f"{horsy_vars.protocol}{horsy_vars.server_url}/packages", json=body)
|
handle(requests.put(f"{horsy_vars.protocol}{horsy_vars.server_url}/packages", json=body).status_code)
|
||||||
if r.status_code == status.OK:
|
|
||||||
gui.cpopup('Success', 'Success, package edited')
|
|
||||||
elif r.status_code == status.UNAUTHORIZED:
|
|
||||||
gui.cpopup('Error', 'Unauthorized')
|
|
||||||
elif r.status_code == status.NOT_FOUND:
|
|
||||||
gui.cpopup('Error', 'Package not found or its not yours')
|
|
||||||
elif r.status_code == status.BAD_REQUEST:
|
|
||||||
gui.cpopup('Error', 'Bad request')
|
|
||||||
elif r.status_code == status.INTERNAL_SERVER_ERROR:
|
|
||||||
gui.cpopup('Error', 'Internal server error')
|
|
||||||
elif r.status_code == status.TOO_MANY_REQUESTS:
|
|
||||||
gui.cpopup('Error', 'Too many requests')
|
|
||||||
else:
|
|
||||||
gui.cpopup('Error', 'Unknown error')
|
|
||||||
|
|
||||||
package_ui.update_button.clicked.connect(send)
|
package_ui.update_button.clicked.connect(send)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import requests
|
|||||||
import modules.vars as horsy_vars
|
import modules.vars as horsy_vars
|
||||||
import json
|
import json
|
||||||
from rich import print
|
from rich import print
|
||||||
|
from modules.http_status import handle
|
||||||
|
|
||||||
client = SearchClient.create(
|
client = SearchClient.create(
|
||||||
requests.get('https://raw.githubusercontent.com/horsy-ml/horsy/master/web_vars/search_app').json()['APP_ID'],
|
requests.get('https://raw.githubusercontent.com/horsy-ml/horsy/master/web_vars/search_app').json()['APP_ID'],
|
||||||
@@ -26,21 +27,10 @@ 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}").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 f"Package {package} not found"
|
r = json.loads(r)
|
||||||
try:
|
|
||||||
r = json.loads(r)
|
|
||||||
except:
|
|
||||||
print("[red]Error with unsupported message[/]")
|
|
||||||
return "Error with unsupported message"
|
|
||||||
try:
|
|
||||||
if r["message"] == "Internal server error":
|
|
||||||
print("[red]Internal server error[/]")
|
|
||||||
return "Internal server error"
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
print(f"[bold]{r['name']}{'✅' if r['verified'] else ''} by {r['authorName']}[/]")
|
print(f"[bold]{r['name']}{'✅' if r['verified'] else ''} by {r['authorName']}[/]")
|
||||||
print(f"{r['description']}")
|
print(f"{r['description']}")
|
||||||
@@ -71,4 +61,3 @@ def info(package, download_ui=None, UiDownloadWindow=None):
|
|||||||
"We don't call you to trust this app, use it at your own risk \n"
|
"We don't call you to trust this app, use it at your own risk \n"
|
||||||
"but we recommend you more to install verified packages")
|
"but we recommend you more to install verified packages")
|
||||||
return None
|
return None
|
||||||
|
|
||||||
|
|||||||
@@ -3,24 +3,16 @@ import json
|
|||||||
import webbrowser
|
import webbrowser
|
||||||
import modules.vars as horsy_vars
|
import modules.vars as horsy_vars
|
||||||
from rich import print
|
from rich import print
|
||||||
|
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}").text
|
r = requests.get(f"{horsy_vars.protocol}{horsy_vars.server_url}/packages/json/{package}")
|
||||||
try:
|
r_code = handle(r.status_code)
|
||||||
r = json.loads(r)
|
if r_code[1] not in [200, 201]:
|
||||||
except:
|
return r_code[1]
|
||||||
print("[red]Error with unsupported message[/]")
|
r = r.text
|
||||||
return "Error with unsupported message"
|
r = json.loads(r)
|
||||||
try:
|
|
||||||
if r["message"] == "not found":
|
|
||||||
print("[red]Package not found[/]")
|
|
||||||
return "Package not found"
|
|
||||||
if r["message"] == "Internal server error":
|
|
||||||
print("[red]Internal server error[/]")
|
|
||||||
return "Internal server error"
|
|
||||||
except:
|
|
||||||
pass
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
webbrowser.open(r["sourceUrl"])
|
webbrowser.open(r["sourceUrl"])
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import threading
|
import threading
|
||||||
import subprocess
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
|
|
||||||
def run_threaded(func, *args):
|
def run_threaded(func, *args):
|
||||||
try:
|
try:
|
||||||
threading.Thread(target=func, args=args).start()
|
threading.Thread(target=func, args=args).start()
|
||||||
|
|||||||
@@ -95,7 +95,7 @@ def upload(is_gui=False, ui=None):
|
|||||||
}
|
}
|
||||||
|
|
||||||
else:
|
else:
|
||||||
auth = get_auth_without_login(is_gui)
|
auth = get_auth_without_login()
|
||||||
|
|
||||||
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:
|
||||||
|
|||||||
Reference in New Issue
Block a user