def ping(evaluator): """Tests the connection, used for when id is explicitly asked by the user""" if evaluator.environment["GOST_address"]: conn_conf.test_connection(evaluator.environment["GOST_address"][:-5], verbose=True) else: evaluator.environment["non_critical_failures"].append("GOST address undefined, ping not possible")
def ping_connection(self, gost_address, b=FALSE): if b: if conn_conf.test_connection(gost_address): gui_ut.messagebox.showinfo( "OK", "Server is reachable at " + gost_address) else: gui_ut.messagebox.showinfo( "Error", "Address" + gost_address + "is not valid!") else: if conn_conf.test_connection(gost_address): gui_ut.messagebox.showinfo( "OK", "Server is reachable at " + gost_address) else: gui_ut.messagebox.showinfo( "Error", "Address" + gost_address + "is not valid!")
def user_defined_address(evaluator, verbose=True): """If the user has defined a GOST address, checks if it is possible to reach it. If it possible, sets the GOST address to the new address, otherwise asks the user if he wants to select a different address or wants to keep the non working address""" working_conn = conn_conf.test_connection((evaluator.args.GOSTaddress)[:-5]) if working_conn: valid_conn = conn_conf.set_GOST_address(evaluator.args.GOSTaddress) evaluator.environment["GOST_address"] = valid_conn else: warning_message = f"The selected GOST address is not working, " \ f"do you want to set it as your address or want to change it?\n" \ f"'y' to set the currently provided address\n'ch' to set a new address\n" \ f"'n' to mantain the old address:\n" # creation of warning message proceed = input(warning_message) if proceed == "y": valid_conn = conn_conf.set_GOST_address(evaluator.args.GOSTaddress) evaluator.environment["GOST_address"] = valid_conn elif proceed == "ch": new_address = input("Insert new address:\n") evaluator.args.GOSTaddress = new_address user_defined_address(evaluator) else: evaluator.environment["GOST_address"] = conn_conf.set_GOST_address() if not evaluator.environment["GOST_address"]: evaluator.environment["critical_failures"].append("error: GOST address not defined")
def connection_test(evaluator): """Tests the connection on the currently defined GOST address""" if not conn_conf.test_connection(evaluator.environment.GOST_address, False): print("Network error, failed connection") evaluator.environment["critical_failure"].append("failed connection " "to " + evaluator.environment["GOST_address"][:-5]) else: print(f"current GOST address: {evaluator.environment.GOST_address}\n'--address <ip:port>' to change")
def try_port(self=None, port=None, address=None, b=None, take=None): if not address: address = conn_conf.get_address_from_file() x = address.split(":") y = x[2].split("/") if take: return y[0] y[0] = port first = "/".join(y) x[2] = first complete = ":".join(x) if conn_conf.test_connection(complete): conn_conf.set_GOST_address(complete) if b: self.main_view.model.GOST_address = complete self.change_address_description.configure( text="Insert a new address\n" f"format: http://x.x.x.x:port_number/v1.0\n{complete}") self.new_address.delete(0, "end") self.new_address.insert(0, self.main_view.model.GOST_address) self.main_view.address_preview.configure( text=f"Current GOST address: " + self.main_view.model.GOST_address + "\nclick here to change address") elif not b: self.model.GOST_address = complete indexes_to_delete = [] for index, val in enumerate(self.view_elements): if "name" in val: if val["name"] in [ "address_preview", "new_port_entry", "Confirm changes", "new_port_button", "Insert a new port number", "address_preview", "confirm_port_button", "confirm_address_button", "old_port_button" ]: indexes_to_delete.append(index) for i in sorted(indexes_to_delete, reverse=True): self.view_elements[i]["item"].grid_forget() del self.view_elements[i] self.port_button = gui_ut.Button( self.top_bar, text="Change port number", command=lambda: change_port_number(self), bg=gui_ut.change_address_color) self.port_button.grid(row=0, column=4) self.address_preview.configure( text=f"Current GOST address: {self.model.GOST_address} " f"\nclick here to change address") else: self.confirm_port_button.configure( text="To change port, insert a new port\nand click here") else: gui_ut.messagebox.showinfo("Error", "invalid Port number") self.address_preview.configure(text="Invalid port, insert a new port")
def change_address(self): new_address = self.new_address.get() working_conn = conn_conf.test_connection(new_address) if working_conn: self.main_view.model.GOST_address = new_address conn_conf.set_GOST_address(new_address) # saving the new address works self.main_view.address_preview.configure( text=f"Current GOST address: {self.main_view.model.GOST_address} " f"\nclick here to change address") self.confirm_address_button.configure( text="To change address, insert a new address\nand click here") if bool(self.main_view.confirm_address_button): self.main_view.confirm_address_button.grid_forget() self.main_view.new_address_entry.grid_forget() else: self.confirm_address_button.configure( text="Invalid address, insert a new address\nand click here")
def try_address(self): new_address = self.new_address_entry.get( ) # checking if the new address works working_conn = conn_conf.test_connection(new_address) if working_conn: self.model.GOST_address = new_address conn_conf.set_GOST_address(new_address) # saving the new address works self.address_preview.configure( text=f"Current GOST address: {self.model.GOST_address} " f"\nclick here to change address") indexes_to_delete = [] for index, val in enumerate(self.view_elements): if "name" in val: if val["name"] in [ "new_address_entry", "new_address_button", "keep_old_address_button", "confirm_address_button", "confirm_port_button", "new_port_entry", "new_port_button", "old_port_button" ]: indexes_to_delete.append(index) for i in sorted(indexes_to_delete, reverse=True): self.view_elements[i]["item"].grid_forget() del self.view_elements[i] self.port_button = gui_ut.Button( self.top_bar, text="Change port number", command=lambda: change_port_number(self), bg=gui_ut.change_address_color) self.port_button.grid(row=0, column=4) gui_ut.populate(self.view_elements, self.main_area) else: gui_ut.messagebox.showinfo("Error", "invalid GOST address") self.address_preview.configure( text="Invalid address, insert a new address")