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