You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tika.apache.org by dm...@apache.org on 2017/12/01 02:34:42 UTC

[tika] branch master updated: TIKA-2385: Updated check for Python dependencies to use temporary script instead of -c switch

This is an automated email from the ASF dual-hosted git repository.

dmeikle pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/tika.git


The following commit(s) were added to refs/heads/master by this push:
     new aff782d  TIKA-2385: Updated check for Python dependencies to use temporary script instead of -c switch
aff782d is described below

commit aff782d5e88a3616055451de9526c0a40774bf87
Author: David Meikle <da...@logicalspark.com>
AuthorDate: Fri Dec 1 02:34:33 2017 +0000

    TIKA-2385: Updated check for Python dependencies to use temporary script instead of -c switch
---
 .../apache/tika/parser/ocr/TesseractOCRParser.java | 23 +++++++++++++++-------
 1 file changed, 16 insertions(+), 7 deletions(-)

diff --git a/tika-parsers/src/main/java/org/apache/tika/parser/ocr/TesseractOCRParser.java b/tika-parsers/src/main/java/org/apache/tika/parser/ocr/TesseractOCRParser.java
index b2ce47f..4d6abc4 100644
--- a/tika-parsers/src/main/java/org/apache/tika/parser/ocr/TesseractOCRParser.java
+++ b/tika-parsers/src/main/java/org/apache/tika/parser/ocr/TesseractOCRParser.java
@@ -23,10 +23,12 @@ import javax.xml.parsers.SAXParser;
 import java.awt.Image;
 import java.awt.image.BufferedImage;
 import java.io.BufferedReader;
+import java.io.BufferedWriter;
 import java.io.ByteArrayOutputStream;
 import java.io.File;
 import java.io.FileInputStream;
 import java.io.FileOutputStream;
+import java.io.FileWriter;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
@@ -170,18 +172,25 @@ public class TesseractOCRParser extends AbstractParser implements Initializable
     }
 
     static boolean hasPython() {
-        // check if python is installed, it has the required dependencies for the rotation program to run
+        // check if python is installed and it has the required dependencies for the rotation program to run
         boolean hasPython = false;
 
         try {
-            String[] commands = {"python", "-c", "\"import numpy, matplotlib, skimage;\"" };
-
-            Process proc = Runtime.getRuntime().exec(commands);
-            BufferedReader stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream(), "UTF-8"));
-            if(stdInput.read() != -1) {
+            TemporaryResources tmp = new TemporaryResources();
+            File importCheck = tmp.createTemporaryFile();
+            String prg = "import numpy, mathplotlib, skimage";
+            BufferedWriter out = new BufferedWriter(new FileWriter(importCheck));
+            out.write(prg);
+            out.close();
+
+            Process p = Runtime.getRuntime().exec("python " + importCheck.getAbsolutePath());
+            if (p.waitFor() == 0) {
                 hasPython = true;
             }
-        } catch (IOException e) {
+
+            tmp.close();
+
+        } catch (Exception e) {
 
         }
 

-- 
To stop receiving notification emails like this one, please contact
['"commits@tika.apache.org" <co...@tika.apache.org>'].