[ocrfeeder] Replace use of deprecated os.popen



commit ee7506905fac7331f00e009ccad0031a298b5c1d
Author: Joaquim Rocha <me joaquimrocha com>
Date:   Sat Mar 7 21:49:04 2020 +0100

    Replace use of deprecated os.popen
    
    os.popen has been deprecated since Python 2.6, and was never changed
    since OCRFeeder's first version.
    These changes replace the use of os.popen (when converting a PDF to an
    image) by the use of subprocess.run.
    
    See for more references:
    https://docs.python.org/2/library/os.html#os.popen
    https://docs.python.org/3/library/subprocess.html#replacing-os-popen-os-popen2-os-popen3
    
    This commit is based on a similar fix proposed by @scx (thank you!):
    https://gitlab.gnome.org/GNOME/ocrfeeder/-/merge_requests/7

 src/ocrfeeder/util/lib.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
---
diff --git a/src/ocrfeeder/util/lib.py b/src/ocrfeeder/util/lib.py
index ff9b314..bf3c0aa 100644
--- a/src/ocrfeeder/util/lib.py
+++ b/src/ocrfeeder/util/lib.py
@@ -18,6 +18,7 @@
 ###########################################################################
 
 import os
+import subprocess
 import mimetypes
 from PIL import Image
 import tempfile
@@ -54,7 +55,7 @@ def convertPdfToImages(pdf_file, temp_dir = '/tmp'):
                'file_name': file_name,
                'pdf_file': pdf_file,
                'resolution': resolution}
-    os.popen(command)
+    process = subprocess.run(command, shell=True)
     return dir_name
 
 def getImagesFromFolder(folder):


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]