mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2026-09-03 20:52:55 -05:00
Switched check_sources.py from getopt to optparse
This commit is contained in:
+16
-18
@@ -12,8 +12,8 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import sys, os, re
|
import sys, os, re
|
||||||
import getopt
|
|
||||||
import cStringIO
|
import cStringIO
|
||||||
|
from optparse import OptionParser
|
||||||
from os.path import join, splitext, abspath
|
from os.path import join, splitext, abspath
|
||||||
|
|
||||||
|
|
||||||
@@ -165,34 +165,32 @@ def check_xhtml(fn, lines):
|
|||||||
|
|
||||||
|
|
||||||
def main(argv):
|
def main(argv):
|
||||||
try:
|
parser = OptionParser(usage='Usage: %prog [-v] [-i ignorepath]* [path]')
|
||||||
gopts, args = getopt.getopt(argv[1:], "vi:")
|
parser.add_option('-v', '--verbose', dest='verbose', default=False,
|
||||||
except getopt.GetoptError:
|
action='store_true')
|
||||||
print "Usage: %s [-v] [-i ignorepath]* [path]" % argv[0]
|
parser.add_option('-i', '--ignore-path', dest='ignored_paths',
|
||||||
return 2
|
default=[], action='append')
|
||||||
opts = {}
|
options, args = parser.parse_args(argv[1:])
|
||||||
for opt, val in gopts:
|
|
||||||
if opt == '-i':
|
|
||||||
val = abspath(val)
|
|
||||||
opts.setdefault(opt, []).append(val)
|
|
||||||
|
|
||||||
if len(args) == 0:
|
if len(args) == 0:
|
||||||
path = '.'
|
path = '.'
|
||||||
elif len(args) == 1:
|
elif len(args) == 1:
|
||||||
path = args[0]
|
path = args[0]
|
||||||
else:
|
else:
|
||||||
print "Usage: %s [-v] [-i ignorepath]* [path]" % argv[0]
|
print args
|
||||||
return 2
|
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
|
num = 0
|
||||||
out = cStringIO.StringIO()
|
out = cStringIO.StringIO()
|
||||||
|
|
||||||
for root, dirs, files in os.walk(path):
|
for root, dirs, files in os.walk(path):
|
||||||
if '.svn' in dirs:
|
for vcs_dir in ['.svn', '.hg', '.git']:
|
||||||
dirs.remove('.svn')
|
if vcs_dir in dirs:
|
||||||
if '-i' in opts and abspath(root) in opts['-i']:
|
dirs.remove(vcs_dir)
|
||||||
|
if abspath(root) in ignored_paths:
|
||||||
del dirs[:]
|
del dirs[:]
|
||||||
continue
|
continue
|
||||||
in_check_pkg = root.startswith('./sphinx')
|
in_check_pkg = root.startswith('./sphinx')
|
||||||
@@ -201,7 +199,7 @@ def main(argv):
|
|||||||
fn = join(root, fn)
|
fn = join(root, fn)
|
||||||
if fn[:2] == './': fn = fn[2:]
|
if fn[:2] == './': fn = fn[2:]
|
||||||
|
|
||||||
if '-i' in opts and abspath(fn) in opts['-i']:
|
if abspath(fn) in ignored_paths:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
ext = splitext(fn)[1]
|
ext = splitext(fn)[1]
|
||||||
|
|||||||
Reference in New Issue
Block a user