changeset 69:71576cdc28ab

add option to pritn set of names
author Jeff Hammel <jhammel@mozilla.com>
date Wed, 12 May 2010 13:23:08 -0700
parents 3c1f9b412675
children a9110cc98d94
files python/lsex.py
diffstat 1 files changed, 18 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/python/lsex.py	Tue May 04 08:38:42 2010 -0700
+++ b/python/lsex.py	Wed May 12 13:23:08 2010 -0700
@@ -1,5 +1,7 @@
 #!/usr/bin/env python
 import os
+import sys
+from optparse import OptionParser
 
 # make sure duplicate path elements aren't printed twice
 def ordered_set(alist):
@@ -15,7 +17,7 @@
 def lsex(path=None):
     """
     list executable files on the path
-    o path: list of directories to search.  if not specified, use system path
+    - path: list of directories to search.  if not specified, use system path
     """
 
     if path is None:
@@ -34,6 +36,21 @@
         executables.extend(files)
     return executables
 
+def executable_names(path=None):
+    executables = lsex(path)
+    executables = set([os.path.basename(i) for i in executables])
+    return executables
+
 if __name__ == '__main__':
+    parser = OptionParser()
+    parser.add_option('--names', action='store_true', default=False,
+                      help="list only the set of names")
+
+    options, args = parser.parse_args()
+    if options.names:
+        for i in sorted(executable_names()):
+            print i
+        sys.exit(0)
+    
     for i in lsex():
         print i