feat: поддержка .gge, .esw, .xml в пакетном обработчике
Файлы сметных программ (ГРАНД-Смета .gge/.esw) — это XML. Теперь extract_zip, batch_v2, batch_v3 находят и обрабатывают все сметные форматы: .xlsx, .xls, .gge, .esw, .xml GGE/ESW копируются как XML без xlsx-конвертации. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
+25
-4
@@ -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"] = []
|
||||
|
||||
+13
-6
@@ -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"] = []
|
||||
|
||||
Reference in New Issue
Block a user