parts/django/tests/regressiontests/makemessages/tests.py
changeset 307 c6bca38c1cbf
equal deleted inserted replaced
306:5ff1fc726848 307:c6bca38c1cbf
       
     1 import os
       
     2 import re
       
     3 from subprocess import Popen, PIPE
       
     4 
       
     5 def 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
       
    31 xgettext_cmd = find_command('xgettext')
       
    32 if 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