[svn r57551] normalizing py.which cmdline script
--HG-- branch : trunk
This commit is contained in:
		
							parent
							
								
									d7f09cfc0a
								
							
						
					
					
						commit
						b1069dec00
					
				|  | @ -26,8 +26,8 @@ version = "1.0.0a1" | ||||||
| 
 | 
 | ||||||
| initpkg(__name__, | initpkg(__name__, | ||||||
|     description = "pylib and py.test: agile development and test support library", |     description = "pylib and py.test: agile development and test support library", | ||||||
|     revision = int('$LastChangedRevision: 57548 $'.split(':')[1][:-1]), |     revision = int('$LastChangedRevision: 57551 $'.split(':')[1][:-1]), | ||||||
|     lastchangedate = '$LastChangedDate: 2008-08-21 14:12:20 +0200 (Thu, 21 Aug 2008) $', |     lastchangedate = '$LastChangedDate: 2008-08-21 15:25:29 +0200 (Thu, 21 Aug 2008) $', | ||||||
|     version = version,  |     version = version,  | ||||||
|     url = "http://pylib.org",  |     url = "http://pylib.org",  | ||||||
|     download_url = "http://codespeak.net/py/0.9.2/download.html", |     download_url = "http://codespeak.net/py/0.9.2/download.html", | ||||||
|  | @ -59,6 +59,7 @@ initpkg(__name__, | ||||||
|     'cmdline.pylookup'       : ('./cmdline/pylookup.py', 'main',), |     'cmdline.pylookup'       : ('./cmdline/pylookup.py', 'main',), | ||||||
|     'cmdline.pycountloc'     : ('./cmdline/pycountloc.py', 'main',), |     'cmdline.pycountloc'     : ('./cmdline/pycountloc.py', 'main',), | ||||||
|     'cmdline.pycleanup'      : ('./cmdline/pycleanup.py', 'main',), |     'cmdline.pycleanup'      : ('./cmdline/pycleanup.py', 'main',), | ||||||
|  |     'cmdline.pywhich'        : ('./cmdline/pywhich.py', 'main',), | ||||||
| 
 | 
 | ||||||
|     # helpers for use from test functions or collectors |     # helpers for use from test functions or collectors | ||||||
|     'test.__doc__'           : ('./test/__init__.py', '__doc__'), |     'test.__doc__'           : ('./test/__init__.py', '__doc__'), | ||||||
|  |  | ||||||
|  | @ -1,23 +1,3 @@ | ||||||
| #!/usr/bin/env python  | #!/usr/bin/env python | ||||||
| 
 | from _findpy import py | ||||||
| """\ | py.cmdline.pywhich() | ||||||
| py.which [name] |  | ||||||
| 
 |  | ||||||
| print the location of the given python module or package name  |  | ||||||
| """ |  | ||||||
| 
 |  | ||||||
| import sys |  | ||||||
| 
 |  | ||||||
| if __name__ == '__main__': |  | ||||||
|     name = sys.argv[1] |  | ||||||
|     try: |  | ||||||
|         mod = __import__(name) |  | ||||||
|     except ImportError: |  | ||||||
|         print >>sys.stderr, "could not import:", name  |  | ||||||
|     else: |  | ||||||
|         try: |  | ||||||
|             location = mod.__file__  |  | ||||||
|         except AttributeError: |  | ||||||
|             print >>sys.stderr, "module (has no __file__):", mod |  | ||||||
|         else: |  | ||||||
|             print location |  | ||||||
|  | @ -0,0 +1,2 @@ | ||||||
|  | @echo off | ||||||
|  | python "%~dp0\..\py.which" %* | ||||||
|  | @ -0,0 +1,23 @@ | ||||||
|  | #!/usr/bin/env python  | ||||||
|  | 
 | ||||||
|  | """\ | ||||||
|  | py.which [name] | ||||||
|  | 
 | ||||||
|  | print the location of the given python module or package name  | ||||||
|  | """ | ||||||
|  | 
 | ||||||
|  | import sys | ||||||
|  | 
 | ||||||
|  | def main(): | ||||||
|  |     name = sys.argv[1] | ||||||
|  |     try: | ||||||
|  |         mod = __import__(name) | ||||||
|  |     except ImportError: | ||||||
|  |         print >>sys.stderr, "could not import:", name  | ||||||
|  |     else: | ||||||
|  |         try: | ||||||
|  |             location = mod.__file__  | ||||||
|  |         except AttributeError: | ||||||
|  |             print >>sys.stderr, "module (has no __file__):", mod | ||||||
|  |         else: | ||||||
|  |             print location | ||||||
|  | @ -25,8 +25,9 @@ def checkprocess(script): | ||||||
|         else: |         else: | ||||||
|             cmd = "%s" %(script, ) |             cmd = "%s" %(script, ) | ||||||
| 
 | 
 | ||||||
|         if script.basename.startswith("py.lookup"): |         if script.basename.startswith("py.lookup") or \ | ||||||
|             cmd += " hello" |            script.basename.startswith("py.which"): | ||||||
|  |             cmd += " sys" | ||||||
|         print "executing", script |         print "executing", script | ||||||
|         try: |         try: | ||||||
|             py.process.cmdexec(cmd) |             py.process.cmdexec(cmd) | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue