commit source fix
This commit is contained in:
parent
9cf2072bb4
commit
2830d617df
1 changed files with 25 additions and 22 deletions
|
|
@ -130,28 +130,27 @@ async def generate_project_source_pdfs(project, output_dir: str = "pdfs") -> lis
|
||||||
log.warning(f"PDF tox non generato per {pdf_name}")
|
log.warning(f"PDF tox non generato per {pdf_name}")
|
||||||
|
|
||||||
# --- COSING PDF ---
|
# --- COSING PDF ---
|
||||||
|
# Un solo PDF per ingrediente (il primo CosingInfo con reference valida).
|
||||||
if ing.cosing_info:
|
if ing.cosing_info:
|
||||||
seen_refs = set()
|
pdf_name = f"{pi.cas}_cosing"
|
||||||
for cosing in ing.cosing_info:
|
pdf_path = os.path.join(output_dir, f"{pdf_name}.pdf")
|
||||||
if not cosing.reference or cosing.reference in seen_refs:
|
|
||||||
continue
|
|
||||||
seen_refs.add(cosing.reference)
|
|
||||||
|
|
||||||
pdf_name = f"{pi.cas}_cosing"
|
if os.path.exists(pdf_path):
|
||||||
pdf_path = os.path.join(output_dir, f"{pdf_name}.pdf")
|
generated.append(pdf_path)
|
||||||
|
else:
|
||||||
if os.path.exists(pdf_path):
|
reference = next(
|
||||||
generated.append(pdf_path)
|
(c.reference for c in ing.cosing_info if c.reference),
|
||||||
continue
|
None
|
||||||
|
)
|
||||||
log.info(f"Download COSING PDF: {pdf_name} (reference={cosing.reference})")
|
if reference:
|
||||||
content = cosing_download(cosing.reference)
|
log.info(f"Download COSING PDF: {pdf_name} (reference={reference})")
|
||||||
if isinstance(content, bytes):
|
content = cosing_download(reference)
|
||||||
with open(pdf_path, 'wb') as f:
|
if isinstance(content, bytes):
|
||||||
f.write(content)
|
with open(pdf_path, 'wb') as f:
|
||||||
generated.append(pdf_path)
|
f.write(content)
|
||||||
else:
|
generated.append(pdf_path)
|
||||||
log.warning(f"COSING PDF non scaricato per {pdf_name}: {content}")
|
else:
|
||||||
|
log.warning(f"COSING PDF non scaricato per {pdf_name}: {content}")
|
||||||
|
|
||||||
log.info(f"Generazione fonti completata: {len(generated)} PDF generati")
|
log.info(f"Generazione fonti completata: {len(generated)} PDF generati")
|
||||||
return generated
|
return generated
|
||||||
|
|
@ -190,10 +189,14 @@ def create_sources_zip(pdf_paths: list, zip_path: str) -> str:
|
||||||
if zip_dir:
|
if zip_dir:
|
||||||
os.makedirs(zip_dir, exist_ok=True)
|
os.makedirs(zip_dir, exist_ok=True)
|
||||||
|
|
||||||
|
seen_names: set[str] = set()
|
||||||
with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zf:
|
with zipfile.ZipFile(zip_path, 'w', zipfile.ZIP_DEFLATED) as zf:
|
||||||
for path in pdf_paths:
|
for path in pdf_paths:
|
||||||
if os.path.exists(path):
|
name = os.path.basename(path)
|
||||||
zf.write(path, os.path.basename(path))
|
if not os.path.exists(path) or name in seen_names:
|
||||||
|
continue
|
||||||
|
seen_names.add(name)
|
||||||
|
zf.write(path, name)
|
||||||
|
|
||||||
log.info(f"ZIP creato: {zip_path} ({len(pdf_paths)} file)")
|
log.info(f"ZIP creato: {zip_path} ({len(pdf_paths)} file)")
|
||||||
return zip_path
|
return zip_path
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue