[pkg] make pkginfo's gecode version check a bit less ugly
authorJulien Cristau <julien.cristau@logilab.fr>
Thu, 08 Jan 2015 17:50:00 +0100
changeset 762 5aa92d744e2d
parent 761 d9762b5a4604
child 763 c57010cac86c
[pkg] make pkginfo's gecode version check a bit less ugly Use subprocess instead of os.system.
__pkginfo__.py
--- a/__pkginfo__.py	Thu May 28 01:13:28 2015 +0200
+++ b/__pkginfo__.py	Thu Jan 08 17:50:00 2015 +0100
@@ -36,21 +36,20 @@
 ftp = "ftp://ftp.logilab.org/pub/rql"
 
 
-import os, subprocess, sys
+import os.path as osp, subprocess, sys
 from distutils.core import Extension
 
 include_dirs = []
 
 def gecode_version():
-    import os, subprocess
     version = [3,3,1]
-    if os.path.exists('data/gecode_version.cc'):
+    if osp.exists('data/gecode_version.cc'):
         try:
-            res = os.system("g++ -o gecode_version data/gecode_version.cc")
+            subprocess.check_call(['g++', '-o', 'gecode_version', 'data/gecode_version.cc'])
             p = subprocess.Popen("./gecode_version", stdout=subprocess.PIPE)
-            vers = p.stdout.read().decode('ascii')
+            vers = p.communicate()[0].decode('ascii')
             version = [int(c) for c in vers.strip().split('.')]
-        except OSError:
+        except subprocess.CalledProcessError:
             pass
     return version