PageRenderTime 6ms CodeModel.GetById 1ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/tests/regressiontests/i18n/commands/tests.py

https://code.google.com/p/mango-py/
Python | 43 lines | 40 code | 1 blank | 2 comment | 6 complexity | 3933cbb4d2902b3644f28575708627ab MD5 | raw file
 1import os
 2import re
 3from subprocess import Popen, PIPE
 4
 5def find_command(cmd, path=None, pathext=None):
 6    if path is None:
 7        path = os.environ.get('PATH', []).split(os.pathsep)
 8    if isinstance(path, basestring):
 9        path = [path]
10    # check if there are funny path extensions for executables, e.g. Windows
11    if pathext is None:
12        pathext = os.environ.get('PATHEXT', '.COM;.EXE;.BAT;.CMD').split(os.pathsep)
13    # don't use extensions if the command ends with one of them
14    for ext in pathext:
15        if cmd.endswith(ext):
16            pathext = ['']
17            break
18    # check if we find the command on PATH
19    for p in path:
20        f = os.path.join(p, cmd)
21        if os.path.isfile(f):
22            return f
23        for ext in pathext:
24            fext = f + ext
25            if os.path.isfile(fext):
26                return fext
27    return None
28
29# checks if it can find xgettext on the PATH and
30# imports the extraction tests if yes
31xgettext_cmd = find_command('xgettext')
32if xgettext_cmd:
33    p = Popen('%s --version' % xgettext_cmd, shell=True, stdout=PIPE, stderr=PIPE, close_fds=os.name != 'nt', universal_newlines=True)
34    output = p.communicate()[0]
35    match = re.search(r'(?P<major>\d+)\.(?P<minor>\d+)', output)
36    if match:
37        xversion = (int(match.group('major')), int(match.group('minor')))
38        if xversion >= (0, 15):
39            from extraction import *
40    del p
41
42if find_command('msgfmt'):
43    from compilation import *