GUI development
This commit is contained in:
56
horsygui.py
56
horsygui.py
@@ -20,6 +20,9 @@ MainWindow.show()
|
||||
|
||||
|
||||
# Functions
|
||||
def refresh_gui():
|
||||
installed_apps()
|
||||
|
||||
def installed_apps():
|
||||
from modules.manager import apps_list
|
||||
ui.installed_table.clear()
|
||||
@@ -30,21 +33,27 @@ def installed_apps():
|
||||
ui.installed_table.setItem(i // 4, i % 4, QtWidgets.QTableWidgetItem(str(apps[i])))
|
||||
|
||||
def update_app():
|
||||
app_name = ui.installed_table.currentItem().text()
|
||||
if app_name == "":
|
||||
try:
|
||||
app_name = ui.installed_table.currentItem().text()
|
||||
if app_name == "":
|
||||
return
|
||||
else:
|
||||
from modules.manager import install
|
||||
install(app_name, True)
|
||||
except:
|
||||
return
|
||||
else:
|
||||
from modules.manager import install
|
||||
install(app_name)
|
||||
|
||||
def uninstall_app():
|
||||
app_name = ui.installed_table.currentItem().text()
|
||||
if app_name == "":
|
||||
try:
|
||||
app_name = ui.installed_table.currentItem().text()
|
||||
if app_name == "":
|
||||
return
|
||||
else:
|
||||
from modules.manager import uninstall
|
||||
uninstall(app_name)
|
||||
installed_apps()
|
||||
except:
|
||||
return
|
||||
else:
|
||||
from modules.manager import uninstall
|
||||
uninstall(app_name)
|
||||
installed_apps()
|
||||
|
||||
def search_gui():
|
||||
from modules.search import search
|
||||
@@ -59,13 +68,38 @@ def search_gui():
|
||||
for i in range(len(found)):
|
||||
ui.search_table.setItem(i // 4, i % 4, QtWidgets.QTableWidgetItem(str(found[i])))
|
||||
|
||||
def install_app():
|
||||
from modules.manager import install
|
||||
try:
|
||||
app_name = ui.search_table.currentItem().text()
|
||||
if app_name == "":
|
||||
return
|
||||
else:
|
||||
install(app_name, True)
|
||||
except:
|
||||
return
|
||||
|
||||
def get_source_gui():
|
||||
from modules.source import get_source
|
||||
try:
|
||||
app_name = ui.search_table.currentItem().text()
|
||||
if app_name == "":
|
||||
return
|
||||
else:
|
||||
get_source(app_name)
|
||||
except:
|
||||
return
|
||||
|
||||
# Run functions on startup
|
||||
installed_apps()
|
||||
|
||||
# Binds
|
||||
ui.tabWidget.currentChanged.connect(refresh_gui)
|
||||
ui.update_button.clicked.connect(update_app)
|
||||
ui.delete_button.clicked.connect(uninstall_app)
|
||||
ui.search_button.clicked.connect(search_gui)
|
||||
ui.install_button.clicked.connect(install_app)
|
||||
ui.source_button.clicked.connect(get_source_gui)
|
||||
|
||||
|
||||
# Handle GUI exiting to exit whole program
|
||||
|
||||
@@ -201,13 +201,7 @@ class Ui_MainWindow(object):
|
||||
self.manage_packages_table.setDragDropOverwriteMode(False)
|
||||
self.manage_packages_table.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection)
|
||||
self.manage_packages_table.setShowGrid(False)
|
||||
self.manage_packages_table.setRowCount(1)
|
||||
self.manage_packages_table.setColumnCount(4)
|
||||
self.manage_packages_table.setObjectName("manage_packages_table")
|
||||
item = QtWidgets.QTableWidgetItem()
|
||||
self.manage_packages_table.setItem(0, 0, item)
|
||||
item = QtWidgets.QTableWidgetItem()
|
||||
self.manage_packages_table.setItem(0, 1, item)
|
||||
self.manage_packages_table.horizontalHeader().setVisible(False)
|
||||
self.manage_packages_table.horizontalHeader().setDefaultSectionSize(203)
|
||||
self.manage_packages_table.horizontalHeader().setHighlightSections(False)
|
||||
@@ -344,13 +338,7 @@ class Ui_MainWindow(object):
|
||||
self.search_table.setDragDropOverwriteMode(False)
|
||||
self.search_table.setSelectionMode(QtWidgets.QAbstractItemView.SingleSelection)
|
||||
self.search_table.setShowGrid(False)
|
||||
self.search_table.setRowCount(1)
|
||||
self.search_table.setColumnCount(4)
|
||||
self.search_table.setObjectName("search_table")
|
||||
item = QtWidgets.QTableWidgetItem()
|
||||
self.search_table.setItem(0, 0, item)
|
||||
item = QtWidgets.QTableWidgetItem()
|
||||
self.search_table.setItem(0, 1, item)
|
||||
self.search_table.horizontalHeader().setVisible(False)
|
||||
self.search_table.horizontalHeader().setDefaultSectionSize(203)
|
||||
self.search_table.horizontalHeader().setHighlightSections(False)
|
||||
|
||||
@@ -32,33 +32,33 @@ def install(package, is_gui=False):
|
||||
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))
|
||||
|
||||
if not is_gui:
|
||||
print(f"Downloading {r['url'].split('/')[-1]}")
|
||||
# if not is_gui:
|
||||
print(f"Downloading {r['url'].split('/')[-1]}")
|
||||
|
||||
chunk_size = 1024
|
||||
file_r = requests.get(r['url'], stream=True)
|
||||
with open('{2}apps/{0}/{1}'.format(r['name'], r['url'].split('/')[-1], horsy_vars.horsypath), "wb") as f:
|
||||
pbar = tqdm(unit="B", unit_scale=True, total=int(file_r.headers['Content-Length']))
|
||||
for chunk in file_r.iter_content(chunk_size=chunk_size):
|
||||
if chunk:
|
||||
pbar.update(len(chunk))
|
||||
f.write(chunk)
|
||||
pbar.close()
|
||||
chunk_size = 1024
|
||||
file_r = requests.get(r['url'], stream=True)
|
||||
with open('{2}apps/{0}/{1}'.format(r['name'], r['url'].split('/')[-1], horsy_vars.horsypath), "wb") as f:
|
||||
pbar = tqdm(unit="B", unit_scale=True, total=int(file_r.headers['Content-Length']))
|
||||
for chunk in file_r.iter_content(chunk_size=chunk_size):
|
||||
if chunk:
|
||||
pbar.update(len(chunk))
|
||||
f.write(chunk)
|
||||
pbar.close()
|
||||
|
||||
print(f"Starting virustotal scan")
|
||||
if not get_key():
|
||||
print(f"[red]Virustotal api key not found[/]")
|
||||
print(f"You can add it by entering [bold]horsy --vt \[your key][/] in terminal")
|
||||
else:
|
||||
print(f"[green]Virustotal api key found[/]")
|
||||
print(f"[italic white]If you want to disable scan, type [/][bold]horsy --vt disable[/]"
|
||||
f"[italic white] in terminal[/]")
|
||||
scan_file('{2}apps/{0}/{1}'.format(r['name'], r['url'].split('/')[-1], horsy_vars.horsypath))
|
||||
print(f"[green]Virustotal scan finished[/]")
|
||||
analysis = get_report('{2}apps/{0}/{1}'.format(r['name'], r['url'].split('/')[-1],
|
||||
horsy_vars.horsypath))
|
||||
print(f"[green]You can see report by opening: [white]{analysis['link']}[/]")
|
||||
print(f"{analysis['detect']['malicious']} antivirus flagged this file as malicious")
|
||||
print(f"Starting virustotal scan")
|
||||
if not get_key():
|
||||
print(f"[red]Virustotal api key not found[/]")
|
||||
print(f"You can add it by entering [bold]horsy --vt \[your key][/] in terminal")
|
||||
else:
|
||||
print(f"[green]Virustotal api key found[/]")
|
||||
print(f"[italic white]If you want to disable scan, type [/][bold]horsy --vt disable[/]"
|
||||
f"[italic white] in terminal[/]")
|
||||
scan_file('{2}apps/{0}/{1}'.format(r['name'], r['url'].split('/')[-1], horsy_vars.horsypath))
|
||||
print(f"[green]Virustotal scan finished[/]")
|
||||
analysis = get_report('{2}apps/{0}/{1}'.format(r['name'], r['url'].split('/')[-1],
|
||||
horsy_vars.horsypath))
|
||||
print(f"[green]You can see report by opening: [white]{analysis['link']}[/]")
|
||||
print(f"{analysis['detect']['malicious']} antivirus flagged this file as malicious")
|
||||
|
||||
print(f"[green][OK] Done[/]")
|
||||
|
||||
@@ -74,36 +74,36 @@ def install(package, is_gui=False):
|
||||
|
||||
if r['download']:
|
||||
print(f"Found dependency")
|
||||
if not is_gui:
|
||||
print(f"Downloading {r['download'].split('/')[-1]}")
|
||||
# if not is_gui:
|
||||
print(f"Downloading {r['download'].split('/')[-1]}")
|
||||
|
||||
chunk_size = 1024
|
||||
file_r = requests.get(r['download'], stream=True)
|
||||
with open('{2}apps/{0}/{1}'.format(r['name'], r['download'].split('/')[-1], horsy_vars.horsypath),
|
||||
"wb") as f:
|
||||
pbar = tqdm(unit="B", unit_scale=True, total=int(file_r.headers['Content-Length']))
|
||||
for chunk in file_r.iter_content(chunk_size=chunk_size):
|
||||
if chunk:
|
||||
pbar.update(len(chunk))
|
||||
f.write(chunk)
|
||||
pbar.close()
|
||||
chunk_size = 1024
|
||||
file_r = requests.get(r['download'], stream=True)
|
||||
with open('{2}apps/{0}/{1}'.format(r['name'], r['download'].split('/')[-1], horsy_vars.horsypath),
|
||||
"wb") as f:
|
||||
pbar = tqdm(unit="B", unit_scale=True, total=int(file_r.headers['Content-Length']))
|
||||
for chunk in file_r.iter_content(chunk_size=chunk_size):
|
||||
if chunk:
|
||||
pbar.update(len(chunk))
|
||||
f.write(chunk)
|
||||
pbar.close()
|
||||
|
||||
print(f"Starting virustotal scan")
|
||||
if not get_key():
|
||||
print(f"[red]Virustotal api key not found[/]")
|
||||
print(f"You can add it by entering [italic white]horsy --vt \[your key][/] in terminal")
|
||||
else:
|
||||
print(f"[green]Virustotal api key found[/]")
|
||||
scan_file('{2}apps/{0}/{1}'.format(r['name'], r['download'].split('/')[-1], horsy_vars.horsypath))
|
||||
print(f"[green]Virustotal scan finished[/]")
|
||||
analysis = get_report('{2}apps/{0}/{1}'.format(r['name'], r['download'].split('/')[-1],
|
||||
horsy_vars.horsypath))
|
||||
print(f"[green]You can see report by opening: [white]{analysis['link']}[/]")
|
||||
print(f"{analysis['detect']['malicious']} antivirus flagged this file as malicious")
|
||||
if analysis['detect']['malicious'] > 0:
|
||||
print(f"[red]Dependency can be malicious. It may run now, if this added to installation "
|
||||
f"config[/]")
|
||||
input("Press enter if you want continue, or ctrl+c to exit")
|
||||
print(f"Starting virustotal scan")
|
||||
if not get_key():
|
||||
print(f"[red]Virustotal api key not found[/]")
|
||||
print(f"You can add it by entering [italic white]horsy --vt \[your key][/] in terminal")
|
||||
else:
|
||||
print(f"[green]Virustotal api key found[/]")
|
||||
scan_file('{2}apps/{0}/{1}'.format(r['name'], r['download'].split('/')[-1], horsy_vars.horsypath))
|
||||
print(f"[green]Virustotal scan finished[/]")
|
||||
analysis = get_report('{2}apps/{0}/{1}'.format(r['name'], r['download'].split('/')[-1],
|
||||
horsy_vars.horsypath))
|
||||
print(f"[green]You can see report by opening: [white]{analysis['link']}[/]")
|
||||
print(f"{analysis['detect']['malicious']} antivirus flagged this file as malicious")
|
||||
if analysis['detect']['malicious'] > 0:
|
||||
print(f"[red]Dependency can be malicious. It may run now, if this added to installation "
|
||||
f"config[/]")
|
||||
input("Press enter if you want continue, or ctrl+c to exit")
|
||||
|
||||
if r['install']:
|
||||
print(f"Found install option")
|
||||
|
||||
Reference in New Issue
Block a user