-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
162 lines (119 loc) · 5.02 KB
/
Copy pathmain.py
File metadata and controls
162 lines (119 loc) · 5.02 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/usr/bin/env python3
"""
QoL Alteryx-ODI Tools
Main entry point - Orchestrator
"""
from pathlib import Path
from src.cli import run_cli
from src.core.logger import AppLogger
from src.core.xml_processor import process_template, get_output_filename
from src.gui.main_window import MainWindow
ROOT_DIR = Path(__file__).parent
OUTPUT_DIR = ROOT_DIR / "output"
AppLogger.setup(log_dir=ROOT_DIR / "logs")
logger = AppLogger.get_logger(__name__)
def main() -> None:
"""Ponto de entrada principal da aplicacao."""
app = MainWindow()
def on_execute(filepath: str, operation: str) -> None:
"""Trata a execucao de operacoes."""
app.set_button_state(False)
app.set_progress(0)
try:
input_path = Path(filepath)
if not input_path.exists():
app.log(f"ERRO: Arquivo nao encontrado: {filepath}", "error")
return
if "Processar Template" in operation:
_process_template_operation(app, input_path)
elif "Parsear Workflow" in operation:
_parse_alteryx_operation(app, input_path)
elif "Parsear Package" in operation:
_parse_odi_operation(app, input_path)
elif "Converter Alteryx" in operation:
_convert_alteryx_to_odi(app, input_path)
elif "Converter ODI" in operation:
_convert_odi_to_alteryx(app, input_path)
else:
app.log(f"Operacao: {operation}", "info")
app.set_progress(1.0)
app.log("Operacao concluida", "success")
except Exception as exc:
app.log(f"ERRO: {exc}", "error")
logger.exception("Erro durante execucao")
finally:
app.set_button_state(True)
app.set_on_generate(on_execute)
app.mainloop()
def _process_template_operation(app: MainWindow, input_path: Path) -> None:
"""Processa um template XML com substituicao de datas e servidor."""
year, month = app.get_month_year()
server = app.server_entry.get().strip()
app.log(f"Processando template: {input_path.name}")
app.log(f"Periodo: {month:02d}/{year}")
content, stats = process_template(
input_path, server, year, month, log_fn=app.log
)
OUTPUT_DIR.mkdir(exist_ok=True)
output_base = get_output_filename(input_path.name)
output_path = OUTPUT_DIR / f"{output_base}.yxmd"
with open(output_path, "w", encoding="utf-8-sig") as f:
f.write(content)
app.log(f"Salvo em: {output_path}", "success")
app.log(
f"Resumo: {stats.get('dates', 0)} datas, {stats.get('servers', 0)} servidores",
"info",
)
def _parse_alteryx_operation(app: MainWindow, input_path: Path) -> None:
"""Parseia e exibe metadados de um workflow Alteryx."""
from src.core.alteryx_parser import AlteryxParser
parser = AlteryxParser()
workflow = parser.parse(input_path)
app.log(f"Workflow: {workflow.name}", "info")
app.log(f"Nodes: {workflow.node_count}", "info")
app.log(f"Conexoes: {workflow.connection_count}", "info")
for key, value in workflow.properties.items():
app.log(f" {key}: {value}")
def _parse_odi_operation(app: MainWindow, input_path: Path) -> None:
"""Parseia e exibe metadados de um package ODI."""
from src.core.odi_parser import OdiParser
parser = OdiParser()
package = parser.parse(input_path)
app.log(f"Package: {package.name}", "info")
app.log(f"Steps: {package.step_count}", "info")
app.log(f"Cenarios: {package.scenario_count}", "info")
def _convert_alteryx_to_odi(app: MainWindow, input_path: Path) -> None:
"""Converte workflow Alteryx para ODI."""
from src.core.converter import AlteryxToOdiConverter
converter = AlteryxToOdiConverter()
OUTPUT_DIR.mkdir(exist_ok=True)
output_path = OUTPUT_DIR / f"{input_path.stem}_odi.xml"
result = converter.convert(input_path, output_path)
if result.success:
app.log(f"Convertido: {output_path}", "success")
app.log(f"Stats: {result.stats}", "info")
for warn in result.warnings:
app.log(f"AVISO: {warn}", "warning")
for err in result.errors:
app.log(f"ERRO: {err}", "error")
def _convert_odi_to_alteryx(app: MainWindow, input_path: Path) -> None:
"""Converte package ODI para Alteryx."""
from src.core.converter import OdiToAlteryxConverter
converter = OdiToAlteryxConverter()
OUTPUT_DIR.mkdir(exist_ok=True)
output_path = OUTPUT_DIR / f"{input_path.stem}_alteryx.yxmd"
result = converter.convert(input_path, output_path)
if result.success:
app.log(f"Convertido: {output_path}", "success")
app.log(f"Stats: {result.stats}", "info")
for warn in result.warnings:
app.log(f"AVISO: {warn}", "warning")
for err in result.errors:
app.log(f"ERRO: {err}", "error")
if __name__ == "__main__":
import sys
if len(sys.argv) > 1 and not sys.argv[1].startswith("--gui"):
sys.exit(run_cli())
else:
main()
# "O inicio e a parte mais importante do trabalho." - Platao