common.py 923 B

12345678910111213141516171819202122232425262728
  1. import os
  2. import subprocess
  3. import settings
  4. def winepath(windowspath):
  5. """Convert a Windows path to a Unix path."""
  6. return subprocess.check_output(["winepath", "-u", windowspath])[:-1]
  7. def search_startswith(a, elems):
  8. """Search for the first element of the array a that startswith any of the
  9. members of elems, and return it. Return None if no match was found."""
  10. for e in elems:
  11. if a.startswith(e):
  12. return e
  13. return None
  14. def popen_faketime(*args, **kwargs):
  15. """Does subprocess.Popen after setting faketime environment variables."""
  16. ld_preload = os.getenv("LD_PRELOAD")
  17. if ld_preload:
  18. # ld.so(8): "The items of [LD_PRELOAD] can be separated by spaces or colons."
  19. ld_preload += ":"
  20. ld_preload += settings.LD_PRELOAD
  21. os.putenv("LD_PRELOAD", ld_preload)
  22. os.putenv("FAKETIME", settings.FAKETIME)
  23. return subprocess.Popen(*args, **kwargs)