def test_get_files_from_source_folder(self): fm = FileManager(None, os.getcwd()) result = fm.get_files_from_source_folder() self.assertEqual(2, len(result))
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()