From c8af54984cb76c1372ef6636364860846287aa58 Mon Sep 17 00:00:00 2001 From: Holger Frey Date: Thu, 27 Jun 2019 18:06:29 +0200 Subject: [PATCH] fixed bug with absolute paths for output files --- s3printlog/analysis.py | 3 +++ s3printlog/gui.py | 10 +++++++--- s3printlog/main.py | 35 +++++++++++++++++++---------------- s3printlog/report.py | 2 +- test.py | 2 +- 5 files changed, 31 insertions(+), 21 deletions(-) diff --git a/s3printlog/analysis.py b/s3printlog/analysis.py index db45ae5..9436384 100644 --- a/s3printlog/analysis.py +++ b/s3printlog/analysis.py @@ -5,6 +5,9 @@ import pandas as pd import seaborn as sns import pathlib +from pandas.plotting import register_matplotlib_converters +register_matplotlib_converters() + from .logparser import CheckWhen, CheckResult # set plotting styles diff --git a/s3printlog/gui.py b/s3printlog/gui.py index 538ffe6..fbdb499 100644 --- a/s3printlog/gui.py +++ b/s3printlog/gui.py @@ -5,7 +5,7 @@ import tkinter.ttk as ttk from pathlib import Path from tkinter import filedialog -from .main import get_log_files, process_log_folder, open_with_default_app +from .main import get_log_files, process_log_files, open_with_default_app if getattr(sys, "frozen", False): @@ -91,7 +91,11 @@ class Application(tk.Frame): def select_folder(self): self.reset() - opts = {"initialdir": "~/Desktop", "mustexist": True} + if self.log_files is not None: + initial_dir = self.log_files.folder.parent + else: + initial_dir = "~/Desktop" + opts = {"initialdir": initial_dir, "mustexist": True} selection = tk.filedialog.askdirectory(**opts) if selection: self.log_files = get_log_files(selection) @@ -112,7 +116,7 @@ class Application(tk.Frame): self.status_panel.set_text( "Generating report, PDF should be opened in a couple of seconds" ) - report_file = process_log_folder(self.log_files) + report_file = process_log_files(self.log_files) open_with_default_app(report_file) self.status_panel.set_text("Report Generated.") diff --git a/s3printlog/main.py b/s3printlog/main.py index b9983d8..24ad756 100644 --- a/s3printlog/main.py +++ b/s3printlog/main.py @@ -28,7 +28,10 @@ class LogFiles(namedtuple("LogFiles", ["folder", "drop_check", "environment"])): __slots__ = () def __bool__(self): - return self.drop_check and self.environment + if self.drop_check and self.environment: + return True + else: + return False class NoLogFileError(IOError): @@ -49,11 +52,11 @@ def process_drop_checks(log_files): drop_log_df = parse_log_files(log_files.drop_check) generate_drop_check_chart(drop_log_df) - image_path = log_files.folder / f"{log_files.folder}_drop_check.png" + image_path = log_files.folder / f"{log_files.folder.name}_drop_check.png" plt.savefig(image_path) missing_drop_df = find_missing_drops(drop_log_df) - misssing_drop_list_path = log_files.folder / f"{log_files.folder}_missed_spots.xlsx" + misssing_drop_list_path = log_files.folder / f"{log_files.folder.name}_missed_spots.xlsx" missing_drop_df.to_excel(misssing_drop_list_path) return DropProcessResult( @@ -66,25 +69,25 @@ def process_print_log(log_files): print_log = parse_print_log(log_files.environment) generate_environment_graph(print_log.environment) - image_path = log_files.folder / f"{log_files.folder}_environment.png" + image_path = log_files.folder / f"{log_files.folder.name}_environment.png" plt.savefig(image_path) return PrintLogResult(ProcessResult(print_log.environment, image_path), print_log.info) +def process_log_files(log_files): + drop_check_result = process_drop_checks(log_files) + print_log_result = process_print_log(log_files) + return generate_report( + log_files, + drop_check_result.drops, + drop_check_result.missing, + print_log_result.environment, + print_log_result.info, + ) def process_log_folder(folder): - with warnings.catch_warnings(): - warnings.simplefilter("ignore") - log_files = get_log_files(folder) - drop_check_result = process_drop_checks(log_files) - print_log_result = process_print_log(log_files) - return generate_report( - log_files, - drop_check_result.drops, - drop_check_result.missing, - print_log_result.environment, - print_log_result.info, - ) + log_files = get_log_files(folder) + return process_log_files(log_files) def open_with_default_app(some_path): diff --git a/s3printlog/report.py b/s3printlog/report.py index 76f6443..254153f 100644 --- a/s3printlog/report.py +++ b/s3printlog/report.py @@ -164,7 +164,7 @@ def generate_report(log_files, drops, missing, environment, print_info): story.append(PageBreak()) story.append(graph_flowable("Environment Graphs", environment.file_path)) - pdf_path = log_files.folder / f"{log_files.folder}_report.pdf" + pdf_path = log_files.folder / f"{log_files.folder.name}_report.pdf" doc = SimpleDocTemplate( str(pdf_path), pagesize=A4, diff --git a/test.py b/test.py index 70e9d46..795c948 100644 --- a/test.py +++ b/test.py @@ -3,7 +3,7 @@ from s3printlog import main -folder = "example 1" +folder = 'C:/Users/Holgi/Developer/python-libraries/s3printlog/example 1' #folder = "example 2" print("Generating report, PDF should be opened in a couple of seconds")