]> git.lyx.org Git - lyx.git/blobdiff - lib/scripts/clean_dvi.py
Update Python scripts to Python 3+
[lyx.git] / lib / scripts / clean_dvi.py
index 3cd67da7bd17e9c1fdebb1d7d8252fe5b0340ee7..4f7d73dc67457c6cafe7b22bd3f3cd520f93e62a 100644 (file)
@@ -1,10 +1,8 @@
-#! /usr/bin/env python -tt
-
 '''
 file clean_dvi.py
 This file is part of LyX, the document processor.
 Licence details can be found in the file COPYING
-or at http://www.lyx.org/about/licence.php3
+or at http://www.lyx.org/about/licence.php
 
 author Angus Leeming
 Full author contact details are available in the file CREDITS
@@ -28,7 +26,7 @@ It requires dv2dt and dt2dv from the DTL dviware package
 http://www.ctan.org/tex-archive/dviware/dtl/
 '''
 
-import os, re, sys
+import os, re, subprocess, sys
 
 def usage(prog_name):
     return 'Usage: %s in.dvi out.dvi\n' \
@@ -79,9 +77,16 @@ def main(argv):
         error('Unable to read "%s"\n' % infile)
 
     # Convert the input .dvi file to .dtl format.
+    if os.name == 'nt':
+        unix = False
+    else:
+        unix = True
     dv2dt_call = 'dv2dt "%s"' % infile
-    dv2dt_stdin, dv2dt_stdout, dv2dt_stderr = \
-        os.popen3(dv2dt_call, 't')
+    dv2dt_pipe = subprocess.Popen(dv2dt_call, universal_newlines=True, \
+        stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, \
+        shell=unix, close_fds=unix)
+    (dv2dt_stdin, dv2dt_stdout, dv2dt_stderr) = \
+        (dv2dt_pipe.stdin, dv2dt_pipe.stdout, dv2dt_pipe.stderr)
 
     dv2dt_stdin.close()
     dv2dt_data   = dv2dt_stdout.read()
@@ -89,7 +94,7 @@ def main(argv):
 
     if dv2dt_status != None or len(dv2dt_data) == 0:
         dv2dt_err = dv2dt_stderr.read()
-        error("Failed: %s\n%s\n" % ( dv2dt_call, dv2dt_err) )
+        error(f"Failed: {dv2dt_call}\n{dv2dt_err}\n" )
 
     # Manipulate the .dtl file.
     dtl_data = manipulated_dtl(dv2dt_data)