Skip to content

Commit 83b1b66

Browse files
committed
✨ allow to set output directory, pass on to get_report
- initialize logging directory at output directory
1 parent a361d99 commit 83b1b66

File tree

2 files changed

+72
-13
lines changed

2 files changed

+72
-13
lines changed

gui/app.py

Lines changed: 62 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,16 +28,21 @@
2828

2929
# from vuegen.__main__ import main
3030
from vuegen.report import ReportType
31+
from vuegen.utils import get_logger
3132

3233
customtkinter.set_appearance_mode("system")
3334
customtkinter.set_default_color_theme("dark-blue")
34-
from tkinter import filedialog
35+
import traceback
36+
from tkinter import filedialog, messagebox
3537

3638
from vuegen import report_generator
3739
from vuegen.utils import print_completion_message
3840

39-
app_path = Path(__file__).absolute()
41+
app_path = Path(__file__).absolute().resolve()
4042
print("app_path:", app_path)
43+
output_dir = (Path.home() / "vuegen_gen" / "reports").resolve()
44+
print("output_dir:", output_dir)
45+
output_dir.mkdir(exist_ok=True, parents=True)
4146

4247
##########################################################################################
4348
# Path to example data dependend on how the GUI is run
@@ -82,20 +87,45 @@
8287
# return inner
8388

8489

85-
def create_run_vuegen(is_dir, config_path, report_type, run_streamlit):
90+
def create_run_vuegen(
91+
is_dir, config_path, report_type, run_streamlit, output_dir_entry
92+
):
8693
def inner():
8794
kwargs = {}
8895
print(f"{is_dir.get() = }")
8996
if is_dir.get():
9097
kwargs["dir_path"] = config_path.get()
98+
report_name = Path(config_path.get()).stem
9199
else:
92100
kwargs["config_path"] = config_path.get()
101+
report_name = Path(config_path.get()).stem
93102
kwargs["report_type"] = report_type.get()
94103
print(f"{run_streamlit.get() = }")
95104
kwargs["streamlit_autorun"] = run_streamlit.get()
105+
kwargs["output_dir"] = output_dir_entry.get()
96106
print("kwargs:")
97107
pprint(kwargs)
98-
report_generator.get_report(**kwargs)
108+
try:
109+
# Define logger suffix based on report type and name
110+
logger_suffix = f"{report_type.get()}_report_{str(report_name)}"
111+
112+
# Initialize logger
113+
kwargs["logger"], log_file = get_logger(
114+
f"{logger_suffix}",
115+
folder=(Path(kwargs["output_dir"]) / "logs").as_posix(),
116+
)
117+
report_generator.get_report(**kwargs)
118+
messagebox.showinfo(
119+
"Success",
120+
"Report generation completed successfully." f"\nLogs at {log_file}",
121+
)
122+
except Exception as e:
123+
stacktrace = traceback.format_exc()
124+
messagebox.showerror(
125+
"Error",
126+
f"An error occurred: {e}\n\n{stacktrace}"
127+
f"\n See logs for more details {log_file}",
128+
)
99129
print_completion_message(report_type.get())
100130

101131
return inner
@@ -115,7 +145,7 @@ def radio_button_callback():
115145

116146
def create_select_directory(string_var):
117147
def select_directory():
118-
directory = filedialog.askdirectory()
148+
directory = filedialog.askdirectory(initialdir=string_var.get())
119149
string_var.set(directory)
120150

121151
return select_directory
@@ -124,7 +154,7 @@ def select_directory():
124154
##########################################################################################
125155
# APP
126156
app = customtkinter.CTk()
127-
app.geometry("600x400")
157+
app.geometry("620x500")
128158
app.title("VueGen GUI")
129159

130160
##########################################################################################
@@ -207,15 +237,39 @@ def select_directory():
207237
)
208238
ctk_radio_st_autorun_0.grid(row=5, column=1, padx=20, pady=20)
209239

240+
##########################################################################################
241+
# output directory selection
242+
# ctk_label_outdir = customtkinter.CTkLabel
243+
output_dir_entry = tk.StringVar(value=str(output_dir))
244+
select_output_dir = create_select_directory(output_dir_entry)
245+
select_output_dir_button = customtkinter.CTkButton(
246+
app, text="Select Output Directory", command=select_output_dir
247+
)
248+
select_output_dir_button.grid(row=6, column=2, columnspan=2, padx=5, pady=10)
249+
250+
ctk_entry_outpath = customtkinter.CTkEntry(
251+
app,
252+
width=400,
253+
textvariable=output_dir_entry,
254+
)
255+
ctk_entry_outpath.grid(row=6, column=0, columnspan=2, padx=10, pady=10)
256+
ctk_label_appath = customtkinter.CTkLabel(
257+
app,
258+
text=f"App path: {app_path}",
259+
)
260+
ctk_label_appath.grid(row=7, column=0, columnspan=2, padx=20, pady=5)
261+
210262
##########################################################################################
211263
# Run VueGen button
212-
run_vuegen = create_run_vuegen(is_dir, config_path, report_type, run_streamlit)
264+
run_vuegen = create_run_vuegen(
265+
is_dir, config_path, report_type, run_streamlit, output_dir_entry
266+
)
213267
run_button = customtkinter.CTkButton(
214268
app,
215269
text="Run VueGen",
216270
command=run_vuegen,
217271
)
218-
run_button.grid(row=6, column=0, columnspan=2, padx=20, pady=20)
272+
run_button.grid(row=8, column=0, columnspan=2, padx=20, pady=20)
219273

220274
##########################################################################################
221275
# Run the app in the mainloop

src/vuegen/report_generator.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22
import shutil
33
import sys
4+
from pathlib import Path
45

56
from .config_manager import ConfigManager
67
from .quarto_reportview import QuartoReportView
@@ -68,12 +69,14 @@ def get_report(
6869

6970
# Create and run ReportView object based on its type
7071
if report_type == ReportType.STREAMLIT:
72+
base_dir = output_dir / "streamlit_report"
73+
sections_dir = base_dir / "sections"
74+
static_files_dir = base_dir / "static"
7175
st_report = StreamlitReportView(
7276
report=report, report_type=report_type, streamlit_autorun=streamlit_autorun
7377
)
74-
st_report.generate_report()
75-
st_report.run_report()
76-
78+
st_report.generate_report(output_dir=sections_dir, static_dir=static_files_dir)
79+
st_report.run_report(output_dir=sections_dir)
7780
else:
7881
# Check if Quarto is installed
7982
if shutil.which("quarto") is None and not hasattr(
@@ -85,6 +88,8 @@ def get_report(
8588
raise RuntimeError(
8689
"Quarto is not installed. Please install Quarto before generating this report type."
8790
)
91+
base_dir = output_dir / "quarto_report"
92+
static_files_dir = base_dir / "static"
8893
quarto_report = QuartoReportView(report=report, report_type=report_type)
89-
quarto_report.generate_report()
90-
quarto_report.run_report()
94+
quarto_report.generate_report(output_dir=base_dir, static_dir=static_files_dir)
95+
quarto_report.run_report(output_dir=base_dir)

0 commit comments

Comments
 (0)