diff --git a/batch.py b/batch.py index 0f2d356..6c55624 100644 --- a/batch.py +++ b/batch.py @@ -135,9 +135,12 @@ def extract_zip(zip_path: str, dest_dir: str) -> list[str]: if basename.startswith('._') or '__MACOSX' in info.filename: continue z.extract(info, dest_dir) + # Collect all supported smeta file types + SMETA_EXTENSIONS = {'.xlsx', '.xls', '.gge', '.esw', '.xml'} files = [] - for f in Path(dest_dir).rglob('*.xlsx'): - if not f.name.startswith('~$') and not f.name.startswith('._'): + for f in Path(dest_dir).rglob('*'): + if f.is_file() and f.suffix.lower() in SMETA_EXTENSIONS \ + and not f.name.startswith('~$') and not f.name.startswith('._'): files.append(str(f)) return sorted(files) diff --git a/batch_v2.py b/batch_v2.py index 1b5257d..80536b6 100644 --- a/batch_v2.py +++ b/batch_v2.py @@ -78,10 +78,23 @@ def convert_all_to_csv(source_dir: str, csv_dir: str) -> dict: all_csv = [] total_bytes = 0 - xlsx_files = sorted(Path(source_dir).rglob("*.xlsx")) - xlsx_files = [f for f in xlsx_files if not f.name.startswith("~$")] + SMETA_EXT = {'.xlsx', '.xls', '.gge', '.esw', '.xml'} + xlsx_files = sorted( + f for f in Path(source_dir).rglob("*") + if f.is_file() and f.suffix.lower() in SMETA_EXT + and not f.name.startswith("~$") and not f.name.startswith("._") + ) for xlsx in xlsx_files: + # .gge/.esw are XML — copy as-is (no xlsx conversion needed) + if xlsx.suffix.lower() in ('.gge', '.esw', '.xml'): + dst = Path(csv_dir) / f"{xlsx.stem}.xml" + import shutil + shutil.copy2(str(xlsx), str(dst)) + size = dst.stat().st_size + all_csv.append({"path": str(dst), "name": dst.name, "bytes": size}) + total_bytes += size + continue csvs = convert_xlsx_to_csv(str(xlsx), csv_dir) for c in csvs: size = Path(c).stat().st_size @@ -102,8 +115,11 @@ def select_samples(source_dir: str, csv_info: dict) -> list[str]: Strategy: pick files of different sizes and from different subdirs. Returns list of xlsx file paths (originals, not CSV). """ + SMETA_EXT = {'.xlsx', '.xls', '.gge', '.esw', '.xml'} xlsx_files = sorted( - [f for f in Path(source_dir).rglob("*.xlsx") if not f.name.startswith("~$")], + [f for f in Path(source_dir).rglob("*") + if f.is_file() and f.suffix.lower() in SMETA_EXT + and not f.name.startswith("~$") and not f.name.startswith("._")], key=lambda f: f.stat().st_size, ) if len(xlsx_files) <= MAX_SAMPLE_FILES: @@ -387,7 +403,12 @@ def run_batch_v2(job_id: str, script: str, source_dir: str, target_file: str): job["status"] = "running" job["started_at"] = time.time() - source_files = [str(f) for f in Path(source_dir).rglob("*.xlsx") if not f.name.startswith("~$")] + SMETA_EXT = {'.xlsx', '.xls', '.gge', '.esw', '.xml'} + source_files = [ + str(f) for f in Path(source_dir).rglob("*") + if f.is_file() and f.suffix.lower() in SMETA_EXT + and not f.name.startswith("~$") and not f.name.startswith("._") + ] job["total_files"] = len(source_files) job["processed"] = 0 job["errors"] = [] diff --git a/batch_v3.py b/batch_v3.py index 95ddd61..b558279 100644 --- a/batch_v3.py +++ b/batch_v3.py @@ -69,12 +69,14 @@ def verify_script( Returns {"ok": True/False, "processed": int, "errors": [...], "error": str}. """ job_dir = Path(job_dir) - # Select 2 sample xlsx files - all_xlsx = sorted( - f for f in Path(source_dir).rglob("*.xlsx") - if not f.name.startswith("~$") and not f.name.startswith("._") + SMETA_EXT = {'.xlsx', '.xls', '.gge', '.esw', '.xml'} + # Select 2 sample files + all_files = sorted( + f for f in Path(source_dir).rglob("*") + if f.is_file() and f.suffix.lower() in SMETA_EXT + and not f.name.startswith("~$") and not f.name.startswith("._") ) - samples = [str(f) for f in all_xlsx[:2]] + samples = [str(f) for f in all_files[:2]] if not samples: return {"ok": False, "error": "No xlsx files found in source", "processed": 0, "errors": []} @@ -319,7 +321,12 @@ def run_batch_v3(job_id: str, script: str, source_dir: str, target_file: str): job["status"] = "running" job["started_at"] = time.time() - source_files = [str(f) for f in Path(source_dir).rglob("*.xlsx") if not f.name.startswith("~$")] + SMETA_EXT = {'.xlsx', '.xls', '.gge', '.esw', '.xml'} + source_files = [ + str(f) for f in Path(source_dir).rglob("*") + if f.is_file() and f.suffix.lower() in SMETA_EXT + and not f.name.startswith("~$") and not f.name.startswith("._") + ] job["total_files"] = len(source_files) job["processed"] = 0 job["errors"] = []