# # @SEMANTICS: runner, configuration, cli, main # @PURPOSE: Этот модуль является CLI-точкой входа для запуска процесса меппинга метаданных датасетов. # @DEPENDS_ON: dataset_mapper -> Использует DatasetMapper для выполнения основной логики. # @DEPENDS_ON: superset_tool.utils -> Для инициализации клиентов и логирования. # import argparse from superset_tool.utils.init_clients import setup_clients from superset_tool.utils.logger import SupersetLogger from dataset_mapper import DatasetMapper # # --- Начало кода модуля --- # # @PURPOSE: Парсит аргументы командной строки и запускает процесс меппинга. # @RELATION: CREATES_INSTANCE_OF -> DatasetMapper # @RELATION: CALLS -> setup_clients # @RELATION: CALLS -> DatasetMapper.run_mapping def main(): parser = argparse.ArgumentParser(description="Map dataset verbose names in Superset.") parser.add_argument('--source', type=str, required=True, choices=['postgres', 'excel', 'both'], help='The source for the mapping.') parser.add_argument('--dataset-id', type=int, required=True, help='The ID of the dataset to update.') parser.add_argument('--table-name', type=str, help='The table name for PostgreSQL source.') parser.add_argument('--table-schema', type=str, help='The table schema for PostgreSQL source.') parser.add_argument('--excel-path', type=str, help='The path to the Excel file.') parser.add_argument('--env', type=str, default='dev', help='The Superset environment to use.') args = parser.parse_args() logger = SupersetLogger(name="dataset_mapper_main") # [AI_NOTE]: Конфигурация БД должна быть вынесена во внешний файл или переменные окружения. POSTGRES_CONFIG = { 'dbname': 'dwh', 'user': 'your_user', 'password': 'your_password', 'host': 'your_host', 'port': 'your_port' } logger.info("[main][Enter] Starting dataset mapper CLI.") try: clients = setup_clients(logger) superset_client = clients.get(args.env) if not superset_client: logger.error(f"[main][Failure] Superset client for '{args.env}' environment not found.") return mapper = DatasetMapper(logger) mapper.run_mapping( superset_client=superset_client, dataset_id=args.dataset_id, source=args.source, postgres_config=POSTGRES_CONFIG if args.source in ['postgres', 'both'] else None, excel_path=args.excel_path if args.source in ['excel', 'both'] else None, table_name=args.table_name if args.source in ['postgres', 'both'] else None, table_schema=args.table_schema if args.source in ['postgres', 'both'] else None ) logger.info("[main][Exit] Dataset mapper process finished.") except Exception as main_exc: logger.error("[main][Failure] An unexpected error occurred: %s", main_exc, exc_info=True) # if __name__ == '__main__': main() # --- Конец кода модуля --- #