def delete_connection(self): # Instance the Connection Model connection = Connection() connection.id = self.id_connection # Delete the tunnels connection.delete_tunnels() # Delete the connection if connection.delete() is False: MessageBox("Fail to delete the connection, please try again") else: # Call the callback self.refresh_callback() # Close the Window self.window.destroy()
def on_btn_edit_clicked(self, btn): # Get the ID of selected Connection tree = self.builder.get_object("connections_tree") # Get the selection (model, treeiter) = tree.get_selection().get_selected_rows() # Get the connection ID if model is not None and len(treeiter) > 0: # Get the ID connection_id = model[treeiter][1] # Load the Connection connection = Connection() connection.id = connection_id connection.load() connection.load_tunnels() # Open the Window with the connection ConnectionWindow(self.refresh_connections_list, connection)
def save_connection(self): # Get all object that need be validated name = self.builder.get_object("txt_name") host = self.builder.get_object("txt_host") port = self.builder.get_object("txt_port") user = self.builder.get_object("txt_user") switch_key = self.builder.get_object("switch_use_key") password = self.builder.get_object("txt_password") file_chooser = self.builder.get_object("filechooser_key") # Create a new Connection if self.connection is None: self.connection = Connection() self.connection.name = name.get_text() self.connection.host = host.get_text() self.connection.port = port.get_text() self.connection.user = user.get_text() self.connection.use_key = switch_key.get_active() self.connection.key_path = file_chooser.get_filename() self.connection.password = password.get_text() # Save the connection saved = self.connection.save() # Delete the Tunnels self.connection.delete_tunnels() # Now saved the tunnels for tunnel in self.tunnels.get_tunnels(): # Set the ID connection tunnel.id_connection = self.connection.id # Save the Tunnel tunnel.save() # return if is saved or not return saved
def on_btn_connect_clicked(self, btn): # Get the selected ID tree = self.builder.get_object("connections_tree") # Get the selection (model, treeiter) = tree.get_selection().get_selected_rows() # Get the connection ID if model is not None and len(treeiter) > 0: # Get the ID connection_id = model[treeiter][1] # Load the Model connection = Connection() connection.id = connection_id connection.load() # Get the SSH Command command = connection.generate_ssh_command() # Open the Shell shell = Shell(command, connection.name) shell.run()
def load_connections(self): # Reset the List self.connections = [] # Create the SQL sql = "select * from connections order by name" # Execute the sql results = self.dbconnection.select_query(sql) # Create a model for every connection for row in results: # Create new Connection connection = Connection() connection.id = row['id_connection'] connection.name = row['name'] connection.host = row['host'] connection.user = row['user'] connection.port = row['port'] connection.use_key = True if row['use_key'] == 1 else False connection.key_path = row['key_path'] # Add to the list self.connections.append(connection)
def __init__(self): self.db = Connection()
def connect(self, fromVar, toVar): """ Connect fromVar to toVar, add all modules of toVar-module-instrument to instrument of fromVar-module and sort modules list in the correct order for csound code generation. @type fromVar: model.var.OutVar @param fromVar: Startpoint of connection. @type toVar: model.var.InVar @param toVar: Endpoint of connection. @raise ConnectionError: If connection from module to itself. @rtype : model.Connection.connection @return: New connection. """ if fromVar.module == toVar.module: raise ConnectionError, "Can\'t connect module with itself" if fromVar.type == "a" and toVar.type == "i": raise ConnectionError, \ "Can\'t connect audio rate output to initialisation rate input" if fromVar.type == "i" and toVar.type == "a": raise ConnectionError, \ "Can\'t connect initialisation rate output to audio rate input" if toVar.connection: raise ConnectionError, "There's already a connection to this input " newConnection = Connection(fromVar, toVar) targetInstr = fromVar.module.instrument leftInstr = toVar.module.instrument targetInstr.connections.append(newConnection) toVar.connection = newConnection # Append all modules and connections of leftInstr to # targetInstr and remove leftInstr from workspace if targetInstr != leftInstr: for m in leftInstr.modules: m.instrument = targetInstr targetInstr.modules.append(m) for c in leftInstr.connections: targetInstr.connections.append(c) self.instruments.remove(leftInstr) else: if targetInstr.modules.index(fromVar.module) \ > targetInstr.modules.index(toVar.module): # Place toVar module behind fromVar module and close # the gap fromIdx = targetInstr.modules.index(fromVar.module) toIdx = targetInstr.modules.index(toVar.module) targetInstr.modules \ = targetInstr.modules[:toIdx] \ + targetInstr.modules[(toIdx+1):fromIdx] \ + [targetInstr.modules[fromIdx], \ targetInstr.modules[toIdx]] \ + targetInstr.modules[(fromIdx+1):] self.setChanged() arg = ['connect', newConnection] self.notifyObservers(arg) return newConnection
def __init__(self): # Create a instance of the connection class to acces the database self.db = Connection()
def main(): """Program file for product substitution program, by 'Pur Beurre'.""" try: parser = argparse.ArgumentParser(description="Launch the program !") parser.add_argument("-v", "--verbose", action="store_true", help="add output verbosity") parser.add_argument("--install_database", action="store_true", help="install database") args = parser.parse_args() verbose = args.verbose if args.verbose: print("Running '{}'".format(__file__)) if args.install_database: # Ask informations for sql server connection # and save them in 'conn_params.json'. Run = Ui() host, user, password = Run.connection_params() Json().save_connection_params(host, user, password) print("Installing...") # Server sql connection. Log = Connection(host, user, password) # Read sql. Sql = SqlRead(verbose) sql_readed = Sql.read_sql(SQL_FILE) # Write database name in 'database_name.json'. Sql.database_name(sql_readed) # Create database. Create(Log, sql_readed).create_db(verbose) # Retrieves the maximum number of characters for the fields. Fields_charmax = Fetch(Log).characters_max() # Retrives datas from Api and reject unsuitable datas. Api_data = ApiRequests().api_get_data(Fields_charmax, verbose) # Insertion in database. Insert(Log, verbose).insert_data(Api_data) print("Database installed.") else: try: with open("model/conn_params.json"): pass with open("model/database_name.json"): pass except IOError: print( "\nInformations de connection manquantes.\n", "Veuillez utiliser l'option : --install_database\n", ) exit() # Load connection parameters from json. host, user, password = Json().read_connection_params() # Server connection. Log = Connection(host, user, password) # Database connection. Log_db = Log.database_log() # Booleans for loops. Loop = False log_choice = False # User account. user_name = False Run = Ui() while log_choice is False: log_choice = Run.log_menu() # User log. if log_choice == 1: logged = False while logged is False: user_name = Run.log_user() if isinstance(user_name, str): try: request_lists = RequestsLists().user_id(user_name) user_id = Orm(Log_db).simple_request( request_lists)[0] logged = True except IndexError: print("\n- Ce nom d'utilisateur n'existe pas.") else: print("\n- Veuillez saisir un nom d'utilisateur.") # User create account. elif log_choice == 2: while user_name is False: user_name = Run.create_user() try: request_lists = RequestsLists().user_id(user_name) user = Orm(Log_db).simple_request(request_lists) user_name = False print("\nCe nom d'utilisateur existe déjà.") except IndexError: insert_lists = RequestsLists().user_insert(user_name) Insert(Log_db, verbose).insert_user(insert_lists) request_lists = RequestsLists().user_id(user_name) user_id = Orm(Log_db).simple_request(request_lists)[0] while Loop is False: # Booleans for loops. menu_choice = False category = False product_id = False substitute_id = False save_choice = False # Display menu. while menu_choice is False: menu_choice = Run.menu() # Launch search for substitute. if menu_choice == 1: # Display categories while category is False: category = Run.categories() # Display products. while product_id is False: product_id = Run.products(Log, category) # Display substitute while substitute_id is False: substitute_id = Run.substitute(Log, product_id, category) # Save result, leave or loop. while save_choice is False: save_choice = Run.save_menu(Log) if save_choice == 1: insert_lists = RequestsLists().save_search( product_id, substitute_id, user_id) Insert(Log_db, verbose).insert_save(insert_lists) print("\nRecherche sauvegardée.") elif save_choice == 2: pass elif save_choice == 3: exit(Ui().bye_message(user_name)) # Display saved searches. elif menu_choice == 2: Run.saves_display(Log_db, user_id) # Quit. elif menu_choice == 3: exit(Ui().bye_message(user_name)) except KeyboardInterrupt: Ui().bye_message(user_name)