2019-06-12 05:41:31 +00:00
|
|
|
import os
|
2020-09-22 02:37:31 +00:00
|
|
|
import sys
|
2019-06-12 05:41:31 +00:00
|
|
|
|
2020-09-22 02:37:31 +00:00
|
|
|
from voussoirkit import pathclass
|
2019-06-12 05:41:31 +00:00
|
|
|
|
2020-09-22 02:37:31 +00:00
|
|
|
def windows():
|
|
|
|
paths = os.getenv('PATH').strip(' ;').split(';')
|
|
|
|
paths = (pathclass.Path(p) for p in paths)
|
|
|
|
paths = (p for p in paths if p.is_dir)
|
2019-06-12 05:41:31 +00:00
|
|
|
|
2020-09-22 02:37:31 +00:00
|
|
|
extensions = os.getenv('PATHEXT').split(';')
|
|
|
|
|
|
|
|
files = (file for path in paths for file in path.listdir())
|
|
|
|
executables = (file for file in files if file.extension in extensions)
|
|
|
|
yield from executables
|
|
|
|
|
|
|
|
def linux():
|
|
|
|
paths = os.getenv('PATH').strip(' :').split(':')
|
|
|
|
paths = (pathclass.Path(p) for p in paths)
|
|
|
|
paths = (p for p in paths if p.is_dir)
|
|
|
|
|
|
|
|
files = (file for path in paths for file in path.listdir())
|
|
|
|
executables = (file for file in files if os.access(file.absolute_path, os.X_OK))
|
|
|
|
yield from executables
|
|
|
|
|
|
|
|
def main(argv):
|
|
|
|
if os.name == 'nt':
|
|
|
|
executables = windows()
|
|
|
|
else:
|
|
|
|
executables = linux()
|
|
|
|
|
|
|
|
for executable in executables:
|
|
|
|
print(executable.absolute_path)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
raise SystemExit(main(sys.argv[1:]))
|