3
- Figure out the script story on the various platforms. On Windows, look into
4
the launcher thing that effbot has. Unix, don't install the script my
5
default. They can always do "python -m which ..." with Python >= 2.4.
6
Suggest an alias that some folks might want to use for that.
13
- test with other versions of Python
14
- get the PATHEXT attached extension to reflect the actual canonical
15
case of file matches on Windows, currently the extension from PATHEXT
17
- What to do with Change 145624 by shanec. It is a bit of a
18
bastardization. Maybe allow this with a special option to allow the change
21
> Change 145624 by shanec@shanec-ocelotl on 2005/05/24 16:51:55
23
> make which work better on OSX
24
> - add support for searching /Applications and /Network/Applications
25
> - add support for .app bundles
29
> ... //depot/main/Apps/Komodo-devel/src/python-sitelib/which.py#7 edit
33
> ==== //depot/main/Apps/Komodo-devel/src/python-sitelib/which.py#7 (text) ====
35
> @@ -126,10 +126,11 @@
36
> sys.stderr.write("duplicate: %s (%s)\n" % potential)
39
> - if not stat.S_ISREG(os.stat(potential[0]).st_mode):
40
> + darwinApp = sys.platform == 'darwin' and potential[0][-4:]=='.app'
41
> + if not darwinApp and not stat.S_ISREG(os.stat(potential[0]).st_mode):
43
> sys.stderr.write("not a regular file: %s (%s)\n" % potential)
44
> - elif not os.access(potential[0], os.X_OK):
45
> + elif not darwinApp and not os.access(potential[0], os.X_OK):
47
> sys.stderr.write("no executable access: %s (%s)\n"\
50
> path = os.environ.get("PATH", "").split(os.pathsep)
51
> if sys.platform.startswith("win"):
52
> path.insert(0, os.curdir) # implied by Windows shell
53
> + if sys.platform == 'darwin':
54
> + path.insert(0, '/Network/Applications')
55
> + path.insert(0, '/Applications')
60
> exts = ['.COM', '.EXE', '.BAT']
61
> elif not isinstance(exts, list):
62
> raise TypeError("'exts' argument must be a list or None")
63
> + elif sys.platform == 'darwin':
67
> if exts is not None:
68
> raise WhichError("'exts' argument is not supported on "\
70
> for ext in ['']+exts:
71
> absName = os.path.abspath(
72
> os.path.normpath(os.path.join(dirName, command+ext)))
73
> - if os.path.isfile(absName):
74
> + if os.path.isfile(absName) or (sys.platform == 'darwin' and \
75
> + absName[-4:]=='.app' and os.path.isdir(absName)):
77
> fromWhere = "from given path element %d" % i
78
> elif not sys.platform.startswith("win"):
80
Here is a start with slight improvements:
83
> ===================================================================
84
> --- which.py (revision 270)
85
> +++ which.py (working copy)
86
> @@ -126,9 +126,18 @@
87
> sys.stderr.write("duplicate: %s (%s)\n" % potential)
90
> - if not stat.S_ISREG(os.stat(potential[0]).st_mode):
91
> + st_mode = os.stat(potential[0]).st_mode
92
> + isMacAppBundle = sys.platform == "darwin" \
93
> + and potential[0].endswith(".app") \
94
> + and stat.S_ISDIR(st_mode)
95
> + if not isMacAppBundle and not stat.S_ISREG(st_mode):
97
> - sys.stderr.write("not a regular file: %s (%s)\n" % potential)
98
> + if sys.platform == "darwin":
99
> + sys.stderr.write("not a regular file or .app bundle: "
100
> + "%s (%s)\n" % potential)
102
> + sys.stderr.write("not a regular file: %s (%s)\n"
104
> elif not os.access(potential[0], os.X_OK):
106
> sys.stderr.write("no executable access: %s (%s)\n"\
111
- have a version for pre-generators (i.e. Python 2.1)
112
- add a "logging" interface