def execute(self, command_args): if len(command_args) > 1: console_out( "\nError in executing command: {} To many arguments".format(command_to_plain_string(command_args)) ) else: return console_out(get_supported_db())
def execute(self, command_args): try: repo_name = command_args[1] values_to_update = {key: value for key, value in [arg.split("=") for arg in command_args[2:]]} except IndexError: console_out("Error: Update command requires 1 argument: ") return Repository.update_by_name(repo_name, values_to_update)
def execute(self, command_args): if len(command_args) > 1: console_out( "\nError in executing command: {} To many arguments".format(command_to_plain_string(command_args)) ) else: Repository.read_all() result = repository_formatter(Repository.read_all()) console_out(result)
def execute(self, command_args): if len(command_args) > 2: sys.stdout.write( "\nError in executing command: {} To many arguments".format(command_to_plain_string(command_args)) ) else: try: repo_name = command_args[1] Repository.remove_by_name(repo_name) console_info("Deleted repository: {}".format(repo_name)) except RepositoryException: console_out("Can't find repository: {}".format(repo_name))
def execute(self, command_args): try: repo = Repository() repo.name = command_args[1] repo.host = command_args[2] repo.port = command_args[3] repo.username = command_args[4] repo.database_driver = command_args[5] repo.database_name = command_args[6] repo.scripts_path = command_args[7] validate_repository(repo) if has_errors(repo): return console_out(errors_parser(repo)) except IndexError: console_error( "In executing command: {} Not all arguments have been passed.".format( command_to_plain_string(command_args) ) ) try: Repository.create(repo) except IntegrityError: console_error("Repository {} already exists.".format(repo.name)) return console_info("Repository {} created successfully.".format(repo.name))
def execute(self, command_args): if len(command_args) != 3: sys.stdout.write( 'Error in executing command: "{}", Init command requires 2 arguments: "REPOSITORY_NAME", ' '"PASSWORD_TO_DATABASE"'.format(command_to_plain_string(command_args).strip()) ) else: repo_name = command_args[1] db_password = command_args[2] repository = Repository.read_by_name(repo_name) host = repository.host port = repository.port database_driver = repository.database_driver database_name = repository.database_name username = repository.username driver_resolver = DBResolver() driver_resolver.resolve_db_driver(database_driver) if host != "localhost": host = host + ":" + port try: connection = driver_resolver.connect_to_db( dbname=database_name, user=username, host=host, password=db_password ) except OperationalError: sys.stdout.write("Error: Can't connect to database: {} on host: {}".format(database_name, host)) return cursor = connection.cursor() try: cursor.execute(driver_resolver.get_init_query()) connection.commit() except ProgrammingError: console_out("Info: Migration table already exists") connection.close()
def execute(self, command_args): if len(command_args) > 2: console_error("In executing command: {} To many arguments.".format(command_to_plain_string(command_args))) else: return console_out(get_available_commands())
def execute(self, command_args): repo_name = command_args[1] db_password = command_args[2] repo = Repository.read_by_name(repo_name) scripts_path = repo.scripts_path host = repo.host port = repo.port database_driver = repo.database_driver database_name = repo.database_name username = repo.username driver_resolver = DBResolver() driver_resolver.resolve_db_driver(database_driver) if host != "localhost": host = host + ":" + port try: connection = driver_resolver.connect_to_db( dbname=database_name, user=username, host=host, password=db_password ) except OperationalError: console_out("\nError: Can't connect to database: {} on host: {}".format(database_name, host)) return except DatabaseDriverNotResolved: console_out( "\nError: Database driver not resolved. Can't connect to database: {} on host: {}".format( database_name, host ) ) return cursor = connection.cursor() fm = FileManager(connection, scripts_path) fm.get_files_in_db() files_that_miss = fm.get_files_that_miss() try: fm.get_files_from_source_folder() except WrongFileNameException as ex: console_out(ex.msg) return files_to_execute = fm.get_files_to_execute() if files_that_miss: console_out("\nWarning: There are missing files: " + data_to_plain_string(files_that_miss)) if files_to_execute is None: console_out("\nInfo: There are no files to execute.") return console_out("\nInfo: Executing files: " + data_to_plain_string(files_to_execute)) gen = fm.read_files(files_to_execute) while True: try: cursor.execute(next(gen)) except StopIteration: break for file in files_to_execute: cursor.execute( 'INSERT INTO db_interceptor_migrations ("file_name","applied") VALUES (\'' + str(file) + "','" + datetime.now().strftime("%Y/%m/%d %H:%M:%S") + "')" ) connection.commit() connection.close()