2020import platform
2121import os
2222from pathlib import Path
23- from typing import Union , Optional , Dict , Any , List
23+ from typing import Union , Optional , Dict , Any
2424
2525
2626class PDFConverter :
@@ -45,33 +45,37 @@ def __init__(self) -> None:
4545 def find_libreoffice_windows () -> Optional [str ]:
4646 """
4747 Find LibreOffice installation on Windows.
48-
48+
4949 Returns:
5050 Path to soffice.exe if found, None otherwise
5151 """
5252 if platform .system () != "Windows" :
5353 return None
54-
54+
5555 # Common LibreOffice installation paths on Windows
5656 possible_paths = [
5757 r"C:\Program Files\LibreOffice\program\soffice.exe" ,
5858 r"C:\Program Files (x86)\LibreOffice\program\soffice.exe" ,
5959 ]
60-
60+
6161 # Also check PROGRAMFILES environment variables
6262 program_files = os .environ .get ("PROGRAMFILES" )
6363 program_files_x86 = os .environ .get ("PROGRAMFILES(X86)" )
64-
64+
6565 if program_files :
66- possible_paths .append (os .path .join (program_files , "LibreOffice" , "program" , "soffice.exe" ))
66+ possible_paths .append (
67+ os .path .join (program_files , "LibreOffice" , "program" , "soffice.exe" )
68+ )
6769 if program_files_x86 :
68- possible_paths .append (os .path .join (program_files_x86 , "LibreOffice" , "program" , "soffice.exe" ))
69-
70+ possible_paths .append (
71+ os .path .join (program_files_x86 , "LibreOffice" , "program" , "soffice.exe" )
72+ )
73+
7074 # Check each path
7175 for path in possible_paths :
7276 if os .path .exists (path ):
7377 return path
74-
78+
7579 return None
7680
7781 @staticmethod
@@ -103,9 +107,10 @@ def convert_office_to_pdf(
103107 else :
104108 # Generate unique folder name with timestamp to avoid conflicts
105109 import time
110+
106111 timestamp = int (time .time ())
107112 folder_name = f"paper_{ timestamp } "
108-
113+
109114 # Save to workspace instead of temp directory
110115 workspace_base = Path (os .getcwd ()) / "deepcode_lab" / "papers"
111116 workspace_base .mkdir (parents = True , exist_ok = True )
@@ -199,7 +204,7 @@ def convert_office_to_pdf(
199204
200205 # Use the working LibreOffice command first, then try alternatives if it fails
201206 commands_to_try = [working_libreoffice_cmd ]
202-
207+
203208 # Add alternative commands based on what was found
204209 if platform .system () == "Windows" and working_libreoffice_cmd :
205210 # If we're using the full Windows path, also try standard commands
@@ -293,7 +298,7 @@ def convert_office_to_pdf(
293298 # Copy PDF to final output directory
294299 final_pdf_path = base_output_dir / f"{ name_without_suff } .pdf"
295300 shutil .copy2 (pdf_path , final_pdf_path )
296-
301+
297302 print (f"✅ PDF saved to: { final_pdf_path } " )
298303 print (f" File size: { final_pdf_path .stat ().st_size } bytes" )
299304 print (f" Parent folder: { base_output_dir } " )
@@ -353,9 +358,10 @@ def convert_text_to_pdf(
353358 else :
354359 # Generate unique folder name with timestamp to avoid conflicts
355360 import time
361+
356362 timestamp = int (time .time ())
357363 folder_name = f"paper_{ timestamp } "
358-
364+
359365 # Save to workspace instead of temp directory
360366 workspace_base = Path (os .getcwd ()) / "deepcode_lab" / "papers"
361367 workspace_base .mkdir (parents = True , exist_ok = True )
@@ -516,7 +522,7 @@ def convert_text_to_pdf(
516522 print (f"✅ PDF saved to: { pdf_path } " )
517523 print (f" File size: { pdf_path .stat ().st_size } bytes" )
518524 print (f" Parent folder: { base_output_dir } " )
519-
525+
520526 return pdf_path
521527
522528 except Exception as e :
@@ -634,11 +640,19 @@ def check_dependencies(self) -> dict:
634640 try :
635641 subprocess .run (["libreoffice" , "--version" ], ** subprocess_kwargs )
636642 results ["libreoffice" ] = True
637- except (subprocess .CalledProcessError , FileNotFoundError , subprocess .TimeoutExpired ):
643+ except (
644+ subprocess .CalledProcessError ,
645+ FileNotFoundError ,
646+ subprocess .TimeoutExpired ,
647+ ):
638648 try :
639649 subprocess .run (["soffice" , "--version" ], ** subprocess_kwargs )
640650 results ["libreoffice" ] = True
641- except (subprocess .CalledProcessError , FileNotFoundError , subprocess .TimeoutExpired ):
651+ except (
652+ subprocess .CalledProcessError ,
653+ FileNotFoundError ,
654+ subprocess .TimeoutExpired ,
655+ ):
642656 pass
643657 except Exception :
644658 # If any unexpected error occurs during LibreOffice check, silently pass
0 commit comments