comparison python/lsex.py @ 0:f3ab51c79813

adding configuration from https://svn.openplans.org/svn/config_jhammel/
author k0s <k0scist@gmail.com>
date Thu, 15 Oct 2009 11:41:26 -0400
parents
children 71576cdc28ab
comparison
equal deleted inserted replaced
-1:000000000000 0:f3ab51c79813
1 #!/usr/bin/env python
2 import os
3
4 # make sure duplicate path elements aren't printed twice
5 def ordered_set(alist):
6 seen = set()
7 new = []
8 for item in alist:
9 if item in seen:
10 continue
11 seen.add(item)
12 new.append(item)
13 return new
14
15 def lsex(path=None):
16 """
17 list executable files on the path
18 o path: list of directories to search. if not specified, use system path
19 """
20
21 if path is None:
22 # use system path
23 path = ordered_set(os.environ['PATH'].split(':'))
24
25 executables = []
26
27 # add the executable files to the list
28 for i in path:
29 if not os.path.isdir(i):
30 continue
31 files = [ os.path.join(i,j) for j in os.listdir(i) ]
32 files = filter(lambda x: os.access(x, os.X_OK), files)
33 files.sort() # just to make the output pretty
34 executables.extend(files)
35 return executables
36
37 if __name__ == '__main__':
38 for i in lsex():
39 print i