Compare commits
14 Commits
2d90ec53b2
...
cursor/dat
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
7cc3a350cd | ||
| 34a68b4e22 | |||
| 61f1a737a4 | |||
| f0a004b637 | |||
| 7e305f18be | |||
| 6b2d13272f | |||
| 8f5d0d24c9 | |||
| 911e6f3612 | |||
| 0fc5eecfb4 | |||
| b389a13add | |||
| 5fb66a2794 | |||
| 9e317e41df | |||
| d5f1a563e2 | |||
| a9f1e90fc1 |
0
desktop/setup_linux.sh
Normal file → Executable file
0
desktop/setup_linux.sh
Normal file → Executable file
50
src/xlsx_clean/app_logging.py
Normal file
50
src/xlsx_clean/app_logging.py
Normal file
@@ -0,0 +1,50 @@
|
||||
"""Append-only file logging for QC datasheet creation."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import logging
|
||||
import os
|
||||
import sys
|
||||
from pathlib import Path
|
||||
|
||||
_LOGGER_NAME = "xlsx_clean.create"
|
||||
_configured = False
|
||||
|
||||
|
||||
def default_log_path() -> Path:
|
||||
"""Resolve the log file path.
|
||||
|
||||
Order:
|
||||
1. ``XLSX_CLEAN_LOG`` env var (file path)
|
||||
2. Next to the frozen executable (PyInstaller)
|
||||
3. ``~/.xlsx-clean/xlsx-clean.log``
|
||||
"""
|
||||
env = os.environ.get("XLSX_CLEAN_LOG")
|
||||
if env:
|
||||
return Path(env)
|
||||
|
||||
if getattr(sys, "frozen", False):
|
||||
return Path(sys.executable).resolve().parent / "xlsx-clean.log"
|
||||
|
||||
return Path.home() / ".xlsx-clean" / "xlsx-clean.log"
|
||||
|
||||
|
||||
def get_logger() -> logging.Logger:
|
||||
"""Return a logger that appends timestamped lines to the log file."""
|
||||
global _configured
|
||||
logger = logging.getLogger(_LOGGER_NAME)
|
||||
if not _configured:
|
||||
log_path = default_log_path()
|
||||
log_path.parent.mkdir(parents=True, exist_ok=True)
|
||||
handler = logging.FileHandler(log_path, encoding="utf-8")
|
||||
handler.setFormatter(
|
||||
logging.Formatter(
|
||||
fmt="%(asctime)s %(levelname)s %(message)s",
|
||||
datefmt="%Y-%m-%d %H:%M:%S",
|
||||
)
|
||||
)
|
||||
logger.addHandler(handler)
|
||||
logger.setLevel(logging.INFO)
|
||||
logger.propagate = False
|
||||
_configured = True
|
||||
return logger
|
||||
@@ -13,6 +13,7 @@ import pandas
|
||||
from beaupy import prompt, select
|
||||
from rich.console import Console
|
||||
|
||||
from xlsx_clean.app_logging import get_logger
|
||||
from xlsx_clean.paths import (
|
||||
default_backend,
|
||||
get_opencloud_root,
|
||||
@@ -89,19 +90,32 @@ def create_datasheet(
|
||||
|
||||
Shared by the CLI and the NiceGUI web UI.
|
||||
"""
|
||||
log = get_logger()
|
||||
ctx = f"set={selected_set!r} ink={selected_dir!r} serial={batch_serial!r}"
|
||||
|
||||
if not selected_set:
|
||||
return CreateResult(ok=False, message="Select a set.")
|
||||
message = "Select a set."
|
||||
log.error("Create failed: %s (%s)", message, ctx)
|
||||
return CreateResult(ok=False, message=message)
|
||||
if not selected_dir:
|
||||
return CreateResult(ok=False, message="Select an ink color.")
|
||||
message = "Select an ink color."
|
||||
log.error("Create failed: %s (%s)", message, ctx)
|
||||
return CreateResult(ok=False, message=message)
|
||||
if not batch_serial or not str(batch_serial).strip():
|
||||
return CreateResult(ok=False, message="Enter a serial.")
|
||||
message = "Enter a serial."
|
||||
log.error("Create failed: %s (%s)", message, ctx)
|
||||
return CreateResult(ok=False, message=message)
|
||||
|
||||
batch_serial = str(batch_serial).strip()
|
||||
ctx = f"set={selected_set!r} ink={selected_dir!r} serial={batch_serial!r}"
|
||||
try:
|
||||
resolved_backend = resolve_backend(backend)
|
||||
except (ValueError, RuntimeError) as exc:
|
||||
log.error("Create failed: %s (%s)", exc, ctx)
|
||||
return CreateResult(ok=False, message=str(exc))
|
||||
|
||||
ctx = f"{ctx} backend={resolved_backend}"
|
||||
|
||||
if path_df is None or addin_paths is None:
|
||||
content, loaded_df = load_config()
|
||||
if path_df is None:
|
||||
@@ -114,10 +128,9 @@ def create_datasheet(
|
||||
& (path_df["dir"].str.endswith(selected_dir))
|
||||
]
|
||||
if matches.empty:
|
||||
return CreateResult(
|
||||
ok=False,
|
||||
message=f"No config row for set={selected_set!r} ink={selected_dir!r}.",
|
||||
)
|
||||
message = f"No config row for set={selected_set!r} ink={selected_dir!r}."
|
||||
log.error("Create failed: %s (%s)", message, ctx)
|
||||
return CreateResult(ok=False, message=message)
|
||||
|
||||
row = matches.iloc[0]
|
||||
path_ = Path(row["dir"])
|
||||
@@ -125,9 +138,11 @@ def create_datasheet(
|
||||
search_pattern = pattern.replace("[SERIAL]", "*")
|
||||
files = [str(x) for x in path_.glob(search_pattern) if x.is_file()]
|
||||
if not files:
|
||||
message = f"No workbooks matching {search_pattern!r} in {path_}"
|
||||
log.error("Create failed: %s (%s)", message, ctx)
|
||||
return CreateResult(
|
||||
ok=False,
|
||||
message=f"No workbooks matching {search_pattern!r} in {path_}",
|
||||
message=message,
|
||||
backend=resolved_backend,
|
||||
)
|
||||
|
||||
@@ -137,10 +152,18 @@ def create_datasheet(
|
||||
template = Path(ref_workbook_name)
|
||||
|
||||
if new_workbook_name.is_file():
|
||||
message = f"Destination already exists, skipped: {new_workbook_name}"
|
||||
log.info(
|
||||
"Create skipped: %s (template=%s destination=%s %s)",
|
||||
message,
|
||||
template,
|
||||
new_workbook_name,
|
||||
ctx,
|
||||
)
|
||||
return CreateResult(
|
||||
ok=True,
|
||||
skipped=True,
|
||||
message=f"Destination already exists, skipped: {new_workbook_name}",
|
||||
message=message,
|
||||
template=template,
|
||||
destination=new_workbook_name,
|
||||
backend=resolved_backend,
|
||||
@@ -180,17 +203,33 @@ def create_datasheet(
|
||||
notes_value=NEW_VALUE,
|
||||
)
|
||||
except Exception as exc: # noqa: BLE001 - surface to CLI/UI
|
||||
message = f"Failed to create workbook: {exc}"
|
||||
log.exception(
|
||||
"Create failed: %s (template=%s destination=%s %s)",
|
||||
message,
|
||||
template,
|
||||
new_workbook_name,
|
||||
ctx,
|
||||
)
|
||||
return CreateResult(
|
||||
ok=False,
|
||||
message=f"Failed to create workbook: {exc}",
|
||||
message=message,
|
||||
template=template,
|
||||
destination=new_workbook_name,
|
||||
backend=resolved_backend,
|
||||
)
|
||||
|
||||
message = f"Wrote {new_workbook_name}"
|
||||
log.info(
|
||||
"Create succeeded: %s (template=%s destination=%s %s)",
|
||||
message,
|
||||
template,
|
||||
new_workbook_name,
|
||||
ctx,
|
||||
)
|
||||
return CreateResult(
|
||||
ok=True,
|
||||
message=f"Wrote {new_workbook_name}",
|
||||
message=message,
|
||||
template=template,
|
||||
destination=new_workbook_name,
|
||||
backend=resolved_backend,
|
||||
|
||||
@@ -7,7 +7,7 @@ dir,pattern,set_name,cells_to_clear,serial_cell,notes_cell
|
||||
"D:\OpenCloud\Kimia Razi\Production\QC Datasheet\1403\KRYL1400T Yellow","KRYL1400T Yellow [SERIAL].xlsx","Kimia Razi","Batch!F2:F3,Batch!G12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D19:J22,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D7:D8,Milling!D11","Batch!D3","Batch!D25"
|
||||
"D:\OpenCloud\Kimia Razi\Production\QC Datasheet\1403\KRYL1401T Yellow","KRYL1401T Yellow [SERIAL].xlsx","Kimia Razi","Batch!F2:F3,Batch!E12:G12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D20:J23,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11","Batch!D3","Batch!D25"
|
||||
"D:\OpenCloud\Kimia Razi\Production\QC Datasheet\1403\KRBG1600T Beige","KRBG1600T Beige [SERIAL].xlsx","Kimia Razi","Batch!F2:F3,Batch!G12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D19:J22,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D7:D8,Milling!D11","Batch!D3","Batch!D25"
|
||||
"D:\OpenCloud\Kimia Razi\Production\QC Datasheet\1403\KRPK1500T Pink","KRPK1500T Pink [SERIAL].xlsx","Kimia Razi","Batch!F2:F3,Batch!F12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D19:J22,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D7:D8,Milling!D11","Batch!D3","Batch!D25"
|
||||
"D:\OpenCloud\Kimia Razi\Production\QC Datasheet\1403\KRPK1500T Pink","KRPK1500T Pink [SERIAL].xlsx","Kimia Razi","Batch!F2:F3,Batch!G12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D19:J22,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D7:D8,Milling!D11","Batch!D3","Batch!D25"
|
||||
"D:\OpenCloud\Kimia Razi\Production\QC Datasheet\1403\KRHN1700T Honey","KRHN1700T Honey [SERIAL].xlsx","Kimia Razi","Batch!F2:F3,Batch!G12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D19:J22,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D7:D8,Milling!D11","Batch!D3","Batch!D25"
|
||||
"D:\OpenCloud\inco\Quality control data sheet\2025\ICJ108 Beige","ICJ_108 op. [SERIAL].xlsx","inco","Batch!F2:F3,Batch!E12:F12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D20:J23,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11,Mix!B3:D11","Batch!D3","Batch!D25"
|
||||
"D:\OpenCloud\inco\Quality control data sheet\2026\ICJ610 Black","ICJ_610 op. [SERIAL].xlsx","inco","Batch!F2:F3,Batch!E12:F12,Batch!O9:Q10,Batch!O12:Q12,Batch!N10,Batch!N13,Batch!D20:J23,'KW'!C3:C4,Milling!G5:K8,Milling!G11:K11,Milling!D6:D8,Milling!D11,Mix!B3:D11","Batch!D3","Batch!D25"
|
||||
|
||||
|
Reference in New Issue
Block a user