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. 21
      s3printlog/main.py
  4. 2
      s3printlog/report.py
  5. 2
      test.py

3
s3printlog/analysis.py

@ -5,6 +5,9 @@ import pandas as pd @@ -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

10
s3printlog/gui.py

@ -5,7 +5,7 @@ import tkinter.ttk as ttk @@ -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): @@ -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): @@ -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.")

21
s3printlog/main.py

@ -28,7 +28,10 @@ class LogFiles(namedtuple("LogFiles", ["folder", "drop_check", "environment"])): @@ -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): @@ -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,16 +69,12 @@ def process_print_log(log_files): @@ -66,16 +69,12 @@ 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_folder(folder):
with warnings.catch_warnings():
warnings.simplefilter("ignore")
log_files = get_log_files(folder)
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(
@ -86,6 +85,10 @@ def process_log_folder(folder): @@ -86,6 +85,10 @@ def process_log_folder(folder):
print_log_result.info,
)
def process_log_folder(folder):
log_files = get_log_files(folder)
return process_log_files(log_files)
def open_with_default_app(some_path):
if sys.platform.startswith("linux"):

2
s3printlog/report.py

@ -164,7 +164,7 @@ def generate_report(log_files, drops, missing, environment, print_info): @@ -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,

2
test.py

@ -3,7 +3,7 @@ @@ -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")

Loading…
Cancel
Save