From c510a55ce41de271b04c1705be520cb75e3635aa Mon Sep 17 00:00:00 2001 From: m-jishnu Date: Wed, 22 Jun 2022 20:14:10 +0530 Subject: [PATCH] Improved Error Logging --- maingui.py | 19 +++++++++++-------- utls.py | 50 ++++++++++++++++++++++++++++++++------------------ 2 files changed, 43 insertions(+), 26 deletions(-) diff --git a/maingui.py b/maingui.py index 8991215..5c6a33d 100644 --- a/maingui.py +++ b/maingui.py @@ -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) @@ -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(): @@ -271,9 +271,8 @@ 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) @@ -281,7 +280,7 @@ def parser(self, data_args, progress_current, progress_main, progress): 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(): @@ -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] @@ -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) diff --git a/utls.py b/utls.py index de55d81..e42c645 100644 --- a/utls.py +++ b/utls.py @@ -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( @@ -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 @@ -51,12 +61,17 @@ 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!]') @@ -64,7 +79,7 @@ def product_id_getter(wrd): #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() @@ -74,7 +89,7 @@ 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() @@ -82,7 +97,7 @@ def product_id_getter(wrd): 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(".") @@ -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() @@ -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)