Browse Source

fixed bug with absolute paths for output files

sx_rewrite
Holger Frey 5 years ago
parent
commit
c8af54984c
  1. 3
      s3printlog/analysis.py
  2. 10
      s3printlog/gui.py
  3. 35
      s3printlog/main.py
  4. 2
      s3printlog/report.py
  5. 2
      test.py

3
s3printlog/analysis.py

@ -5,6 +5,9 @@ import pandas as pd
import seaborn as sns import seaborn as sns
import pathlib import pathlib
from pandas.plotting import register_matplotlib_converters
register_matplotlib_converters()
from .logparser import CheckWhen, CheckResult from .logparser import CheckWhen, CheckResult
# set plotting styles # set plotting styles

10
s3printlog/gui.py

@ -5,7 +5,7 @@ import tkinter.ttk as ttk
from pathlib import Path from pathlib import Path
from tkinter import filedialog 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): if getattr(sys, "frozen", False):
@ -91,7 +91,11 @@ class Application(tk.Frame):
def select_folder(self): def select_folder(self):
self.reset() 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) selection = tk.filedialog.askdirectory(**opts)
if selection: if selection:
self.log_files = get_log_files(selection) self.log_files = get_log_files(selection)
@ -112,7 +116,7 @@ class Application(tk.Frame):
self.status_panel.set_text( self.status_panel.set_text(
"Generating report, PDF should be opened in a couple of seconds" "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) open_with_default_app(report_file)
self.status_panel.set_text("Report Generated.") self.status_panel.set_text("Report Generated.")

35
s3printlog/main.py

@ -28,7 +28,10 @@ class LogFiles(namedtuple("LogFiles", ["folder", "drop_check", "environment"])):
__slots__ = () __slots__ = ()
def __bool__(self): 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): class NoLogFileError(IOError):
@ -49,11 +52,11 @@ def process_drop_checks(log_files):
drop_log_df = parse_log_files(log_files.drop_check) drop_log_df = parse_log_files(log_files.drop_check)
generate_drop_check_chart(drop_log_df) 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) plt.savefig(image_path)
missing_drop_df = find_missing_drops(drop_log_df) 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) missing_drop_df.to_excel(misssing_drop_list_path)
return DropProcessResult( return DropProcessResult(
@ -66,25 +69,25 @@ def process_print_log(log_files):
print_log = parse_print_log(log_files.environment) print_log = parse_print_log(log_files.environment)
generate_environment_graph(print_log.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) plt.savefig(image_path)
return PrintLogResult(ProcessResult(print_log.environment, image_path), print_log.info) 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): def process_log_folder(folder):
with warnings.catch_warnings(): log_files = get_log_files(folder)
warnings.simplefilter("ignore") return process_log_files(log_files)
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,
)
def open_with_default_app(some_path): def open_with_default_app(some_path):

2
s3printlog/report.py

@ -164,7 +164,7 @@ def generate_report(log_files, drops, missing, environment, print_info):
story.append(PageBreak()) story.append(PageBreak())
story.append(graph_flowable("Environment Graphs", environment.file_path)) 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( doc = SimpleDocTemplate(
str(pdf_path), str(pdf_path),
pagesize=A4, pagesize=A4,

2
test.py

@ -3,7 +3,7 @@
from s3printlog import main from s3printlog import main
folder = "example 1" folder = 'C:/Users/Holgi/Developer/python-libraries/s3printlog/example 1'
#folder = "example 2" #folder = "example 2"
print("Generating report, PDF should be opened in a couple of seconds") print("Generating report, PDF should be opened in a couple of seconds")

Loading…
Cancel
Save