Skip to content

Commit

Permalink
Improved Error Logging
Browse files Browse the repository at this point in the history
  • Loading branch information
mjishnu committed Jun 22, 2022
1 parent 01b38e9 commit c510a55
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 26 deletions.
19 changes: 11 additions & 8 deletions maingui.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,10 +127,10 @@ def error_msg(self, text,msg_details,title="Error",critical = False):
self.pushButton.setEnabled(True)
msg.exec()

def show_error_popup(self):
def show_error_popup(self,txt="An Error Has Occured Try Again!"):
msg = QtWidgets.QMessageBox()
msg.setWindowTitle('Error')
msg.setText('An Error Has Occured Try Again! ')
msg.setText(f'{txt} ')
msg.setIcon(QtWidgets.QMessageBox.Icon.Critical)
self.set_bar_0()
self.show_bar(False)
Expand Down Expand Up @@ -207,7 +207,7 @@ def open_Logs(self):
if os.path.exists(path):
os.startfile(path)
else:
self.show_error_popup()
self.show_error_popup(txt="No Logs Found!")

def clear_cache(self):
def remove_file():
Expand Down Expand Up @@ -271,17 +271,16 @@ def post_runner(self, arg):

def parser(self, data_args, progress_current, progress_main, progress):
progress_main.emit(20)

progress_current.emit(10)
data_dict = dict(get_data(data_args))
data_dict = get_data(str(data_args))
progress.emit(40)
parse_data = parse_dict(data_dict)
progress.emit(50)
return parse_data


def installer(self, data, progress_current, progress_main, progress):
main_dict, final_data = data
main_dict, final_data,file_name = data
dwnpath = './Downloads/'

def Handle_Progress():
Expand All @@ -295,7 +294,7 @@ def Handle_Progress():
os.makedirs(dwnpath)

progress_main.emit(40)
path_lst = list()
path_lst = dict()
for f_name in final_data:
# Define the remote file to retrieve
remote_url = main_dict[f_name]
Expand All @@ -306,7 +305,11 @@ def Handle_Progress():
obj.start(blocking=False)
Handle_Progress()
progress_main.emit(2)
path_lst.append(path)
fname_lower = (f_name.split(".")[1].split("_")[0]).lower()
if file_name in fname_lower:
path_lst[path]=1
else:
path_lst[path]=0
progress_main.emit(100)
return install(path_lst)

Expand Down
50 changes: 32 additions & 18 deletions utls.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ def open_browser(arg):

def install(path):
flag = 0
main_prog_error = 0
if type(path)==str:
all_paths = f'Add-AppPackage "{path}"'
output = subprocess.run(
Expand All @@ -23,21 +24,30 @@ def install(path):
detail_msg = f'Command Execution Failed: {output.args[1]}'
detail_msg+='\nThe Installation has failed, try again!'
endresult = (msg,detail_msg,"Error",True)
elif type(path) == list:
elif type(path) == dict:
outputs = list()
for s_path in path:
for s_path in path.keys():
all_paths = f'Add-AppPackage "{s_path}"'
output = subprocess.run(
["C:\\WINDOWS\\system32\\WindowsPowerShell\\v1.0\\powershell.exe", all_paths], capture_output=True)
outputs.append(output.args[1])
if output.returncode != 0:
flag = 1
outputs.append(output.args[1])
msg = 'Failed To Install Dependencies!'
detail_msg = f'Command Execution Failed: {outputs}'
if path[s_path] == 1:
main_prog_error = 1
break
if main_prog_error == 1:
msg = 'Failed To Install The Application!'
detail_msg = f'Command Execution Failed: {outputs}'
detail_msg+='\nThe Installation has failed, try again!'
endresult = (msg,detail_msg,"Error",True)

detail_msg+='\nIn Some cases, the installation of dependencies was only unsuccessful since its already installed in your pc.\n'
detail_msg+='So check wheather the program is installed in start menu if not, try again!'
endresult = (msg,detail_msg,"Warning")
else:
msg = 'Failed To Install Dependencies!'
detail_msg = f'Command Execution Failed: {outputs}'
detail_msg+='\nIn Some cases, the installation of dependencies was only unsuccessful since its already installed in your pc.\n'
detail_msg+='So check wheather the program is installed in start menu if not, try again!'
endresult = (msg,detail_msg,"Warning")

if flag != 0:
return endresult
Expand All @@ -51,20 +61,25 @@ def product_id_getter(wrd):
pattern = re.compile(r".+\/((?:[a-zA-Z]+[0-9]|[0-9]+[a-zA-Z])[a-zA-Z0-9]*)|.+")
matches = pattern.search(str(wrd))
match=matches.group(1)


#getting name from url
pattern_n = re.compile(r".+\/([a-zA-Z-]+)\/|.+")
matches_n = pattern_n.search(str(wrd))
name=matches_n.group(1)

if match == None:
raise Exception(
'No Data Found: --> [You Selected Wrong Page in App Selector, Try Again!]')
else:
return match
return match,name
except AttributeError:
raise Exception(
'No Data Found: --> [You Selected Wrong Page in App Selector, Try Again!]')

#using the api from store.adguard
url = "https://store.rg-adguard.net/api/GetFiles"
data = {"type":"ProductId","url":"product_id_url","ring":"RP","lang":"en-EN"}
data["url"]= product_id_getter(str(arg))
data["url"],file_name= product_id_getter(str(arg))
for i in range(3):
try:
session = HTMLSession()
Expand All @@ -74,15 +89,15 @@ def product_id_getter(wrd):
break
except:
time.sleep(3)
print(f"errorin getting the files from the api retry:{i}")
print(f"error in getting the files from the api retry:{i}")
continue
#parsing the results
main_dict = dict()
for match in matches:
main_dict[match.text] = ' '.join(map(str, match.absolute_links))
if len(main_dict) == 0:
raise Exception("Sorry, Application not found. Please try again!")
return main_dict
return (main_dict,file_name)

def greater_ver(arg, n):
first = arg.split(".")
Expand All @@ -106,10 +121,9 @@ def greater_ver(arg, n):
return n
else:
return n

def parse_dict(args):

main_dict = args
def parse_dict(args):
main_dict,file_name = args
file_name = file_name.split("-")[0]
data = list()
bad_data = list()
data_link = list()
Expand Down Expand Up @@ -228,4 +242,4 @@ def latest_version(lst):
for key, value in repeated_name_dict.items():
final_data.append(final_data_get[(key,value)])
# parsing end ----------------------------------
return (main_dict, final_data)
return (main_dict, final_data,file_name)

0 comments on commit c510a55

Please sign in to comment.