Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | which.py -- a portable GNU which replacement |
michael@0 | 2 | ============================================ |
michael@0 | 3 | |
michael@0 | 4 | Download the latest which.py packages from here: |
michael@0 | 5 | (source) http://trentm.com/downloads/which/1.1.0/which-1.1.0.zip |
michael@0 | 6 | |
michael@0 | 7 | |
michael@0 | 8 | Home : http://trentm.com/projects/which/ |
michael@0 | 9 | License : MIT (see LICENSE.txt) |
michael@0 | 10 | Platforms : Windows, Linux, Mac OS X, Unix |
michael@0 | 11 | Current Version : 1.1 |
michael@0 | 12 | Dev Status : mature, has been heavily used in a commercial product for |
michael@0 | 13 | over 2 years |
michael@0 | 14 | Requirements : Python >= 2.3 (http://www.activestate.com/ActivePython/) |
michael@0 | 15 | |
michael@0 | 16 | |
michael@0 | 17 | What's new? |
michael@0 | 18 | ----------- |
michael@0 | 19 | |
michael@0 | 20 | I have moved hosting of `which.py` from my old [Starship |
michael@0 | 21 | pages](http://starship.python.net/~tmick/) to this site. These starter |
michael@0 | 22 | docs have been improved a little bit. See the [Change Log](#changelog) |
michael@0 | 23 | below for more. |
michael@0 | 24 | |
michael@0 | 25 | **WARNING**: If you are upgrading your `which.py` and you also use my |
michael@0 | 26 | [process.py](../process/) module, you must upgrade `process.py` as well |
michael@0 | 27 | because of the `_version_/__version__` change in v1.1.0. |
michael@0 | 28 | |
michael@0 | 29 | |
michael@0 | 30 | Why which.py? |
michael@0 | 31 | ------------- |
michael@0 | 32 | |
michael@0 | 33 | `which.py` is a small GNU-which replacement. It has the following |
michael@0 | 34 | features: |
michael@0 | 35 | |
michael@0 | 36 | - it is portable (Windows, Linux, Mac OS X, Un*x); |
michael@0 | 37 | - it understands PATHEXT and "App Paths" registration on Windows |
michael@0 | 38 | (i.e. it will find everything that `start` does from the command shell); |
michael@0 | 39 | - it can print all matches on the PATH; |
michael@0 | 40 | - it can note "near misses" on the PATH (e.g. files that match but may |
michael@0 | 41 | not, say, have execute permissions); and |
michael@0 | 42 | - it can be used as a Python module. |
michael@0 | 43 | |
michael@0 | 44 | I also would be happy to have this be a replacement for the `which.py` in the |
michael@0 | 45 | Python CVS tree at `dist/src/Tools/scripts/which.py` which is |
michael@0 | 46 | Unix-specific and not usable as a module; and perhaps for inclusion in |
michael@0 | 47 | the stdlib. |
michael@0 | 48 | |
michael@0 | 49 | Please send any feedback to [Trent Mick](mailto:TrentM@ActiveState.com). |
michael@0 | 50 | |
michael@0 | 51 | |
michael@0 | 52 | Install Notes |
michael@0 | 53 | ------------- |
michael@0 | 54 | |
michael@0 | 55 | Download the latest `which.py` source package, unzip it, and run |
michael@0 | 56 | `python setup.py install`: |
michael@0 | 57 | |
michael@0 | 58 | unzip which-1.1.0.zip |
michael@0 | 59 | cd which-1.1.0 |
michael@0 | 60 | python setup.py install |
michael@0 | 61 | |
michael@0 | 62 | If your install fails then please visit [the Troubleshooting |
michael@0 | 63 | FAQ](http://trentm.com/faq.html#troubleshooting-python-package-installation). |
michael@0 | 64 | |
michael@0 | 65 | `which.py` can be used both as a module and as a script. By default, |
michael@0 | 66 | `which.py` will be installed into your Python's `site-packages` |
michael@0 | 67 | directory so it can be used as a module. On *Windows only*, `which.py` |
michael@0 | 68 | (and the launcher stub `which.exe`) will be installed in the Python |
michael@0 | 69 | install dir to (hopefully) put `which` on your PATH. |
michael@0 | 70 | |
michael@0 | 71 | On Un*x platforms (including Linux and Mac OS X) there is often a |
michael@0 | 72 | `which` executable already on your PATH. To use this `which` instead of |
michael@0 | 73 | your system's on those platforms you can manually do one of the |
michael@0 | 74 | following: |
michael@0 | 75 | |
michael@0 | 76 | - Copy `which.py` to `which` somewhere on your PATH ahead of the system |
michael@0 | 77 | `which`. This can be a symlink, as well: |
michael@0 | 78 | |
michael@0 | 79 | ln -s /PATH/TO/site-packages/which.py /usr/local/bin/which |
michael@0 | 80 | |
michael@0 | 81 | - Python 2.4 users might want to use Python's new '-m' switch and setup |
michael@0 | 82 | and alias: |
michael@0 | 83 | |
michael@0 | 84 | alias which='python -m which' |
michael@0 | 85 | |
michael@0 | 86 | or stub script like this: |
michael@0 | 87 | |
michael@0 | 88 | #!/bin/sh |
michael@0 | 89 | python -m which $@ |
michael@0 | 90 | |
michael@0 | 91 | |
michael@0 | 92 | Getting Started |
michael@0 | 93 | --------------- |
michael@0 | 94 | |
michael@0 | 95 | Currently the best intro to using `which.py` as a module is its module |
michael@0 | 96 | documentation. Either install `which.py` and run: |
michael@0 | 97 | |
michael@0 | 98 | pydoc which |
michael@0 | 99 | |
michael@0 | 100 | take a look at `which.py` in your editor or [here](which.py), or read |
michael@0 | 101 | on. Most commonly you'll use the `which()` method to find an |
michael@0 | 102 | executable: |
michael@0 | 103 | |
michael@0 | 104 | >>> import which |
michael@0 | 105 | >>> which.which("perl") |
michael@0 | 106 | '/usr/local/bin/perl' |
michael@0 | 107 | |
michael@0 | 108 | Or you might want to know if you have multiple versions on your path: |
michael@0 | 109 | |
michael@0 | 110 | >>> which.whichall("perl") |
michael@0 | 111 | ['/usr/local/bin/perl', '/usr/bin/perl'] |
michael@0 | 112 | |
michael@0 | 113 | Use `verbose` to see where your executable is being found. (On Windows |
michael@0 | 114 | this might not always be so obvious as your PATH environment variable. |
michael@0 | 115 | There is an "App Paths" area of the registry where the `start` command |
michael@0 | 116 | will find "registered" executables -- `which.py` mimics this.) |
michael@0 | 117 | |
michael@0 | 118 | >>> which.whichall("perl", verbose=True) |
michael@0 | 119 | [('/usr/local/bin/perl', 'from PATH element 10'), |
michael@0 | 120 | ('/usr/bin/perl', 'from PATH element 15')] |
michael@0 | 121 | |
michael@0 | 122 | You can restrict the searched path: |
michael@0 | 123 | |
michael@0 | 124 | >>> which.whichall("perl", path=["/usr/bin"]) |
michael@0 | 125 | ['/usr/bin/perl'] |
michael@0 | 126 | |
michael@0 | 127 | There is a generator interface: |
michael@0 | 128 | |
michael@0 | 129 | >>> for perl in which.whichgen("perl"): |
michael@0 | 130 | ... print "found a perl here:", perl |
michael@0 | 131 | ... |
michael@0 | 132 | found a perl here: /usr/local/bin/perl |
michael@0 | 133 | found a perl here: /usr/bin/perl |
michael@0 | 134 | |
michael@0 | 135 | An exception is raised if your executable is not found: |
michael@0 | 136 | |
michael@0 | 137 | >>> which.which("fuzzywuzzy") |
michael@0 | 138 | Traceback (most recent call last): |
michael@0 | 139 | ... |
michael@0 | 140 | which.WhichError: Could not find 'fuzzywuzzy' on the path. |
michael@0 | 141 | >>> |
michael@0 | 142 | |
michael@0 | 143 | There are some other options too: |
michael@0 | 144 | |
michael@0 | 145 | >>> help(which.which) |
michael@0 | 146 | ... |
michael@0 | 147 | |
michael@0 | 148 | Run `which --help` to see command-line usage: |
michael@0 | 149 | |
michael@0 | 150 | $ which --help |
michael@0 | 151 | Show the full path of commands. |
michael@0 | 152 | |
michael@0 | 153 | Usage: |
michael@0 | 154 | which [<options>...] [<command-name>...] |
michael@0 | 155 | |
michael@0 | 156 | Options: |
michael@0 | 157 | -h, --help Print this help and exit. |
michael@0 | 158 | -V, --version Print the version info and exit. |
michael@0 | 159 | |
michael@0 | 160 | -a, --all Print *all* matching paths. |
michael@0 | 161 | -v, --verbose Print out how matches were located and |
michael@0 | 162 | show near misses on stderr. |
michael@0 | 163 | -q, --quiet Just print out matches. I.e., do not print out |
michael@0 | 164 | near misses. |
michael@0 | 165 | |
michael@0 | 166 | -p <altpath>, --path=<altpath> |
michael@0 | 167 | An alternative path (list of directories) may |
michael@0 | 168 | be specified for searching. |
michael@0 | 169 | -e <exts>, --exts=<exts> |
michael@0 | 170 | Specify a list of extensions to consider instead |
michael@0 | 171 | of the usual list (';'-separate list, Windows |
michael@0 | 172 | only). |
michael@0 | 173 | |
michael@0 | 174 | Show the full path to the program that would be run for each given |
michael@0 | 175 | command name, if any. Which, like GNU's which, returns the number of |
michael@0 | 176 | failed arguments, or -1 when no <command-name> was given. |
michael@0 | 177 | |
michael@0 | 178 | Near misses include duplicates, non-regular files and (on Un*x) |
michael@0 | 179 | files without executable access. |
michael@0 | 180 | |
michael@0 | 181 | |
michael@0 | 182 | Change Log |
michael@0 | 183 | ---------- |
michael@0 | 184 | |
michael@0 | 185 | ### v1.1.0 |
michael@0 | 186 | - Change version attributes and semantics. Before: had a _version_ |
michael@0 | 187 | tuple. After: __version__ is a string, __version_info__ is a tuple. |
michael@0 | 188 | |
michael@0 | 189 | ### v1.0.3 |
michael@0 | 190 | - Move hosting of which.py to trentm.com. Tweaks to associated bits |
michael@0 | 191 | (README.txt, etc.) |
michael@0 | 192 | |
michael@0 | 193 | ### v1.0.2: |
michael@0 | 194 | - Rename mainline handler function from _main() to main(). I can |
michael@0 | 195 | conceive of it being called from externally. |
michael@0 | 196 | |
michael@0 | 197 | ### v1.0.1: |
michael@0 | 198 | - Add an optimization for Windows to allow the optional |
michael@0 | 199 | specification of a list of exts to consider when searching the |
michael@0 | 200 | path. |
michael@0 | 201 | |
michael@0 | 202 | ### v1.0.0: |
michael@0 | 203 | - Simpler interface: What was which() is now called whichgen() -- it |
michael@0 | 204 | is a generator of matches. The simpler which() and whichall() |
michael@0 | 205 | non-generator interfaces were added. |
michael@0 | 206 | |
michael@0 | 207 | ### v0.8.1: |
michael@0 | 208 | - API change: 0.8.0's API change making "verbose" output the default |
michael@0 | 209 | was a mistake -- it breaks backward compatibility for existing |
michael@0 | 210 | uses of which in scripts. This makes verbose, once again, optional |
michael@0 | 211 | but NOT the default. |
michael@0 | 212 | |
michael@0 | 213 | ### v0.8.0: |
michael@0 | 214 | - bug fix: "App Paths" lookup had been crippled in 0.7.0. Restore that. |
michael@0 | 215 | - feature/module API change: Now print out (and return for the module |
michael@0 | 216 | interface) from where a match was found, e.g. "(from PATH element 3)". |
michael@0 | 217 | The module interfaces now returns (match, from-where) tuples. |
michael@0 | 218 | - bug fix: --path argument was broken (-p shortform was fine) |
michael@0 | 219 | |
michael@0 | 220 | ### v0.7.0: |
michael@0 | 221 | - bug fix: Handle "App Paths" registered executable that does not |
michael@0 | 222 | exist. |
michael@0 | 223 | - feature: Allow an alternate PATH to be specified via 'path' |
michael@0 | 224 | optional argument to which.which() and via -p|--path command line |
michael@0 | 225 | option. |
michael@0 | 226 | |
michael@0 | 227 | ### v0.6.1: |
michael@0 | 228 | - first public release |
michael@0 | 229 |