Loading generateBaseline/postprocessing.py +74 −25 Original line number Diff line number Diff line Loading @@ -135,14 +135,35 @@ def refresh_docx_fields(input_path: str, image: str = "docx-field-refresh") -> s if not input_path.exists() or input_path.suffix.lower() != ".docx": raise FileNotFoundError(f"Invalid DOCX path: {input_path}") print(f"📄 Input file: {input_path}") print(f"📁 Input parent directory: {input_path.parent}") print(f"📋 Files in input parent directory:") try: for item in sorted(input_path.parent.iterdir()): print(f" - {item.name} ({'dir' if item.is_dir() else 'file'})") except Exception as e: print(f" Error listing directory: {e}") # Create a temporary home directory for LibreOffice to prevent creating files in /root lo_home = "lo_home" lo_home.mkdir(mode=0o755, exist_ok=True) lo_home = Path(tempfile.mkdtemp(prefix="lo_home_")) print(f"🏠 LibreOffice home directory: {lo_home}") print(f"📋 Contents of lo_home (before):") try: items = list(lo_home.iterdir()) if items: for item in sorted(items): print(f" - {item.name} ({'dir' if item.is_dir() else 'file'})") else: print(" (empty)") except Exception as e: print(f" Error listing directory: {e}") # Run LibreOffice container on this specific file # Get the relative path of the copied file within the temp directory try: # Calculate the file path relative to parent for use in container file_path_in_container = f"/data/{input_path.relative_to(input_path.parent)}" print(f"📂 File path in container: {file_path_in_container}") # Run LibreOffice container on this specific file cmd = [ "docker", "run", "--rm", "-v", f"{input_path.parent}:/data", Loading @@ -157,12 +178,40 @@ def refresh_docx_fields(input_path: str, image: str = "docx-field-refresh") -> s "--convert-to", "docx", "--infilter=writer8", "--outdir", "/data", f"/data/{input_path}", # Use the path relative to /data in container file_path_in_container, ] print(f"Running command:\n{' '.join(cmd)}\n") print(f"🚀 Running command:\n{' '.join(cmd)}\n") subprocess.run(cmd, check=True) print(f"📋 Contents of lo_home (after):") try: items = list(lo_home.iterdir()) if items: for item in sorted(items): print(f" - {item.name} ({'dir' if item.is_dir() else 'file'})") if item.is_dir(): try: for subitem in sorted(item.iterdir()): print(f" - {subitem.name} ({'dir' if subitem.is_dir() else 'file'})") except Exception: pass else: print(" (empty)") except Exception as e: print(f" Error listing directory: {e}") print(f"📋 Files in input parent directory (after):") try: for item in sorted(input_path.parent.iterdir()): print(f" - {item.name} ({'dir' if item.is_dir() else 'file'})") except Exception as e: print(f" Error listing directory: {e}") finally: # Clean up the temporary home directory print(f"🧹 Cleaning up lo_home: {lo_home}") shutil.rmtree(lo_home, ignore_errors=True) print(f"✅ Refreshed DOCX updated in place: {input_path}") return str(input_path) Loading Loading
generateBaseline/postprocessing.py +74 −25 Original line number Diff line number Diff line Loading @@ -135,14 +135,35 @@ def refresh_docx_fields(input_path: str, image: str = "docx-field-refresh") -> s if not input_path.exists() or input_path.suffix.lower() != ".docx": raise FileNotFoundError(f"Invalid DOCX path: {input_path}") print(f"📄 Input file: {input_path}") print(f"📁 Input parent directory: {input_path.parent}") print(f"📋 Files in input parent directory:") try: for item in sorted(input_path.parent.iterdir()): print(f" - {item.name} ({'dir' if item.is_dir() else 'file'})") except Exception as e: print(f" Error listing directory: {e}") # Create a temporary home directory for LibreOffice to prevent creating files in /root lo_home = "lo_home" lo_home.mkdir(mode=0o755, exist_ok=True) lo_home = Path(tempfile.mkdtemp(prefix="lo_home_")) print(f"🏠 LibreOffice home directory: {lo_home}") print(f"📋 Contents of lo_home (before):") try: items = list(lo_home.iterdir()) if items: for item in sorted(items): print(f" - {item.name} ({'dir' if item.is_dir() else 'file'})") else: print(" (empty)") except Exception as e: print(f" Error listing directory: {e}") # Run LibreOffice container on this specific file # Get the relative path of the copied file within the temp directory try: # Calculate the file path relative to parent for use in container file_path_in_container = f"/data/{input_path.relative_to(input_path.parent)}" print(f"📂 File path in container: {file_path_in_container}") # Run LibreOffice container on this specific file cmd = [ "docker", "run", "--rm", "-v", f"{input_path.parent}:/data", Loading @@ -157,12 +178,40 @@ def refresh_docx_fields(input_path: str, image: str = "docx-field-refresh") -> s "--convert-to", "docx", "--infilter=writer8", "--outdir", "/data", f"/data/{input_path}", # Use the path relative to /data in container file_path_in_container, ] print(f"Running command:\n{' '.join(cmd)}\n") print(f"🚀 Running command:\n{' '.join(cmd)}\n") subprocess.run(cmd, check=True) print(f"📋 Contents of lo_home (after):") try: items = list(lo_home.iterdir()) if items: for item in sorted(items): print(f" - {item.name} ({'dir' if item.is_dir() else 'file'})") if item.is_dir(): try: for subitem in sorted(item.iterdir()): print(f" - {subitem.name} ({'dir' if subitem.is_dir() else 'file'})") except Exception: pass else: print(" (empty)") except Exception as e: print(f" Error listing directory: {e}") print(f"📋 Files in input parent directory (after):") try: for item in sorted(input_path.parent.iterdir()): print(f" - {item.name} ({'dir' if item.is_dir() else 'file'})") except Exception as e: print(f" Error listing directory: {e}") finally: # Clean up the temporary home directory print(f"🧹 Cleaning up lo_home: {lo_home}") shutil.rmtree(lo_home, ignore_errors=True) print(f"✅ Refreshed DOCX updated in place: {input_path}") return str(input_path) Loading