]>
gitweb.michael.orlitzky.com - dead/census-tools.git/blob - bin/find_file_paths
4 Find the location of one or more filenames, and output them to
5 stdout. The search can be anchored within a directory using the --root
6 parameter. By default, all matching paths (for all arguments) will be
7 output. However, if the --single flag is set, only the first path
12 $ ./find_file_paths --root /bin -s mv
17 $ ./find_file_paths --root /bin mv ls
24 from optparse
import OptionParser
29 # Basically, add '../src' to our path.
30 # Needed for the imports that follow.
31 site
.addsitedir(os
.path
.dirname(os
.path
.abspath(sys
.argv
[0])) + '/../src')
38 usage
= '%prog [options] file1 [file2, file3...]'
39 fmtr
= CLI
.VerbatimHelpFormatter()
40 parser
= OptionParser(usage
, formatter
=fmtr
)
42 parser
.add_option('-r',
44 help='The folder under which to search. Defaults to /.',
47 parser
.add_option('-s',
50 help='Return only the first matching path.',
53 # Use this module's docstring as the description.
54 parser
.description
= __doc__
56 (options
, args
) = parser
.parse_args()
60 print "\nERROR: You must supply at least one filename.\n"
62 print '' # Print a newline.
63 raise SystemExit(ExitCodes
.NOT_ENOUGH_ARGS
)
66 found_paths
= FileUtils
.find_file_paths(options
.root
,
70 for fp
in found_paths
: