2010-02-16 12:13:23 +00:00
|
|
|
import os
|
2010-02-22 20:25:43 +00:00
|
|
|
import re
|
|
|
|
from subprocess import Popen, PIPE
|
2010-02-16 12:13:23 +00:00
|
|
|
|
2012-07-20 12:22:00 +00:00
|
|
|
from django.utils import six
|
|
|
|
|
2011-10-18 20:35:42 +00:00
|
|
|
can_run_extraction_tests = False
|
|
|
|
can_run_compilation_tests = False
|
|
|
|
|
2010-02-21 23:45:04 +00:00
|
|
|
def find_command(cmd, path=None, pathext=None):
|
|
|
|
if path is None:
|
|
|
|
path = os.environ.get('PATH', []).split(os.pathsep)
|
2012-07-20 12:22:00 +00:00
|
|
|
if isinstance(path, six.string_types):
|
2010-02-21 23:45:04 +00:00
|
|
|
path = [path]
|
|
|
|
# check if there are funny path extensions for executables, e.g. Windows
|
|
|
|
if pathext is None:
|
|
|
|
pathext = os.environ.get('PATHEXT', '.COM;.EXE;.BAT;.CMD').split(os.pathsep)
|
|
|
|
# don't use extensions if the command ends with one of them
|
|
|
|
for ext in pathext:
|
|
|
|
if cmd.endswith(ext):
|
|
|
|
pathext = ['']
|
|
|
|
break
|
|
|
|
# check if we find the command on PATH
|
|
|
|
for p in path:
|
|
|
|
f = os.path.join(p, cmd)
|
|
|
|
if os.path.isfile(f):
|
|
|
|
return f
|
|
|
|
for ext in pathext:
|
|
|
|
fext = f + ext
|
|
|
|
if os.path.isfile(fext):
|
|
|
|
return fext
|
|
|
|
return None
|
|
|
|
|
|
|
|
# checks if it can find xgettext on the PATH and
|
|
|
|
# imports the extraction tests if yes
|
2010-02-22 20:25:43 +00:00
|
|
|
xgettext_cmd = find_command('xgettext')
|
|
|
|
if xgettext_cmd:
|
|
|
|
p = Popen('%s --version' % xgettext_cmd, shell=True, stdout=PIPE, stderr=PIPE, close_fds=os.name != 'nt', universal_newlines=True)
|
|
|
|
output = p.communicate()[0]
|
|
|
|
match = re.search(r'(?P<major>\d+)\.(?P<minor>\d+)', output)
|
|
|
|
if match:
|
|
|
|
xversion = (int(match.group('major')), int(match.group('minor')))
|
2010-02-22 20:27:58 +00:00
|
|
|
if xversion >= (0, 15):
|
2011-10-18 20:35:42 +00:00
|
|
|
can_run_extraction_tests = True
|
2010-03-29 07:24:45 +00:00
|
|
|
del p
|
2010-10-10 16:38:28 +00:00
|
|
|
|
|
|
|
if find_command('msgfmt'):
|
2011-10-18 20:35:42 +00:00
|
|
|
can_run_compilation_tests = True
|