-
Notifications
You must be signed in to change notification settings - Fork 1
/
allexecutables.py
39 lines (29 loc) · 1.06 KB
/
allexecutables.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import os
import sys
from voussoirkit import pathclass
from voussoirkit import pipeable
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)
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:
pipeable.stdout(executable.absolute_path)
return 0
if __name__ == '__main__':
raise SystemExit(main(sys.argv[1:]))