diff options
author | DasIch <dasdasich@gmail.com> | 2010-05-16 17:50:13 +0200 |
---|---|---|
committer | DasIch <dasdasich@gmail.com> | 2010-05-16 17:50:13 +0200 |
commit | 048f02e974c8d37bde6cb437b069c645e9b1f9b6 (patch) | |
tree | 2d2d3f508f3c34a8f0b82dd3088edcc98ed75a97 /utils | |
parent | 4648596f35777e509b3718396e3c8aa97829cc2b (diff) | |
download | sphinx-048f02e974c8d37bde6cb437b069c645e9b1f9b6.tar.gz |
Switched check_sources.py from getopt to optparse
Diffstat (limited to 'utils')
-rwxr-xr-x | utils/check_sources.py | 34 |
1 files changed, 16 insertions, 18 deletions
diff --git a/utils/check_sources.py b/utils/check_sources.py index 0571ab1e..1b30f2dc 100755 --- a/utils/check_sources.py +++ b/utils/check_sources.py @@ -12,8 +12,8 @@ """ import sys, os, re -import getopt import cStringIO +from optparse import OptionParser from os.path import join, splitext, abspath @@ -165,34 +165,32 @@ def check_xhtml(fn, lines): def main(argv): - try: - gopts, args = getopt.getopt(argv[1:], "vi:") - except getopt.GetoptError: - print "Usage: %s [-v] [-i ignorepath]* [path]" % argv[0] - return 2 - opts = {} - for opt, val in gopts: - if opt == '-i': - val = abspath(val) - opts.setdefault(opt, []).append(val) + parser = OptionParser(usage='Usage: %prog [-v] [-i ignorepath]* [path]') + parser.add_option('-v', '--verbose', dest='verbose', default=False, + action='store_true') + parser.add_option('-i', '--ignore-path', dest='ignored_paths', + default=[], action='append') + options, args = parser.parse_args(argv[1:]) if len(args) == 0: path = '.' elif len(args) == 1: path = args[0] else: - print "Usage: %s [-v] [-i ignorepath]* [path]" % argv[0] - return 2 + print args + parser.error('No more then one path supported') - verbose = '-v' in opts + verbose = options.verbose + ignored_paths = set(abspath(p) for p in options.ignored_paths) num = 0 out = cStringIO.StringIO() for root, dirs, files in os.walk(path): - if '.svn' in dirs: - dirs.remove('.svn') - if '-i' in opts and abspath(root) in opts['-i']: + for vcs_dir in ['.svn', '.hg', '.git']: + if vcs_dir in dirs: + dirs.remove(vcs_dir) + if abspath(root) in ignored_paths: del dirs[:] continue in_check_pkg = root.startswith('./sphinx') @@ -201,7 +199,7 @@ def main(argv): fn = join(root, fn) if fn[:2] == './': fn = fn[2:] - if '-i' in opts and abspath(fn) in opts['-i']: + if abspath(fn) in ignored_paths: continue ext = splitext(fn)[1] |