Rewrite allexecutables.py for windows and linux.
This commit is contained in:
parent
81d0761292
commit
3564918a49
1 changed files with 32 additions and 11 deletions
|
@ -1,15 +1,36 @@
|
||||||
import os
|
import os
|
||||||
|
import sys
|
||||||
|
|
||||||
paths = os.getenv('PATH').split(';')
|
from voussoirkit import pathclass
|
||||||
paths = [p for p in paths if os.path.exists(p)]
|
|
||||||
|
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(';')
|
extensions = os.getenv('PATHEXT').split(';')
|
||||||
extensions = [e.lower() for e in extensions]
|
|
||||||
print('Extensions according to PATHEXT:', extensions)
|
|
||||||
|
|
||||||
for path in paths:
|
files = (file for path in paths for file in path.listdir())
|
||||||
print(path)
|
executables = (file for file in files if file.extension in extensions)
|
||||||
files = os.listdir(path)
|
yield from executables
|
||||||
files = [f for f in files if any(f.lower().endswith(e) for e in extensions)]
|
|
||||||
files = [' ' + f for f in files]
|
def linux():
|
||||||
print('\n'.join(files))
|
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:]))
|
||||||
|
|
Loading…
Reference in a new issue