Funktionierender Prototyp des Serious Games zur Vermittlung von Wissen zu Software-Engineering-Arbeitsmodellen.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

procutils.py 1.3KB

1 year ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. # Copyright (c) Twisted Matrix Laboratories.
  2. # See LICENSE for details.
  3. """
  4. Utilities for dealing with processes.
  5. """
  6. import os
  7. def which(name, flags=os.X_OK):
  8. """
  9. Search PATH for executable files with the given name.
  10. On newer versions of MS-Windows, the PATHEXT environment variable will be
  11. set to the list of file extensions for files considered executable. This
  12. will normally include things like ".EXE". This function will also find files
  13. with the given name ending with any of these extensions.
  14. On MS-Windows the only flag that has any meaning is os.F_OK. Any other
  15. flags will be ignored.
  16. @type name: C{str}
  17. @param name: The name for which to search.
  18. @type flags: C{int}
  19. @param flags: Arguments to L{os.access}.
  20. @rtype: C{list}
  21. @return: A list of the full paths to files found, in the order in which they
  22. were found.
  23. """
  24. result = []
  25. exts = list(filter(None, os.environ.get("PATHEXT", "").split(os.pathsep)))
  26. path = os.environ.get("PATH", None)
  27. if path is None:
  28. return []
  29. for p in os.environ.get("PATH", "").split(os.pathsep):
  30. p = os.path.join(p, name)
  31. if os.access(p, flags):
  32. result.append(p)
  33. for e in exts:
  34. pext = p + e
  35. if os.access(pext, flags):
  36. result.append(pext)
  37. return result