[pkg] make pkginfo's gecode version check a bit less ugly

Use subprocess instead of os.system.

authorJulien Cristau <julien.cristau@logilab.fr>
changeset5aa92d744e2d
branchdefault
phasepublic
hiddenno
parent revision#d9762b5a4604 [pkg] Use setuptools
child revision#c57010cac86c [rqlhelper] use threading.Lock as context manager
files modified by this revision
__pkginfo__.py
# HG changeset patch
# User Julien Cristau <julien.cristau@logilab.fr>
# Date 1420735800 -3600
# Thu Jan 08 17:50:00 2015 +0100
# Node ID 5aa92d744e2d3998e06046c0c8913477d5648b0e
# Parent d9762b5a4604f3616c7f8501a29fd0878e8e1a88
[pkg] make pkginfo's gecode version check a bit less ugly

Use subprocess instead of os.system.

diff --git a/__pkginfo__.py b/__pkginfo__.py
@@ -34,25 +34,24 @@
1  """
2  web = "http://www.logilab.org/project/rql"
3  ftp = "ftp://ftp.logilab.org/pub/rql"
4 
5 
6 -import os, subprocess, sys
7 +import os.path as osp, subprocess, sys
8  from distutils.core import Extension
9 
10  include_dirs = []
11 
12  def gecode_version():
13 -    import os, subprocess
14      version = [3,3,1]
15 -    if os.path.exists('data/gecode_version.cc'):
16 +    if osp.exists('data/gecode_version.cc'):
17          try:
18 -            res = os.system("g++ -o gecode_version data/gecode_version.cc")
19 +            subprocess.check_call(['g++', '-o', 'gecode_version', 'data/gecode_version.cc'])
20              p = subprocess.Popen("./gecode_version", stdout=subprocess.PIPE)
21 -            vers = p.stdout.read().decode('ascii')
22 +            vers = p.communicate()[0].decode('ascii')
23              version = [int(c) for c in vers.strip().split('.')]
24 -        except OSError:
25 +        except subprocess.CalledProcessError:
26              pass
27      return version
28 
29  def encode_version(a,b,c):
30      return ((a<<16)+(b<<8)+c)