Kaydet (Commit) f9a6d7d4 authored tarafından Guido van Rossum's avatar Guido van Rossum

Print serious errors to stderr instead of stdout.

üst bc3760b0
...@@ -13,18 +13,25 @@ import tokenize ...@@ -13,18 +13,25 @@ import tokenize
verbose = 0 verbose = 0
def errprint(*args):
sep = ""
for arg in args:
sys.stderr.write(sep + str(arg))
sep = " "
sys.stderr.write("\n")
def main(): def main():
global verbose global verbose
try: try:
opts, args = getopt.getopt(sys.argv[1:], "v") opts, args = getopt.getopt(sys.argv[1:], "v")
except getopt.error, msg: except getopt.error, msg:
print msg errprint(msg)
return return
for o, a in opts: for o, a in opts:
if o == '-v': if o == '-v':
verbose = verbose + 1 verbose = verbose + 1
if not args: if not args:
print "Usage:", sys.argv[0], "[-v] file_or_directory ..." errprint("Usage:", sys.argv[0], "[-v] file_or_directory ...")
return return
for arg in args: for arg in args:
check(arg) check(arg)
...@@ -55,7 +62,7 @@ def check(file): ...@@ -55,7 +62,7 @@ def check(file):
try: try:
f = open(file) f = open(file)
except IOError, msg: except IOError, msg:
print "%s: I/O Error: %s" % (`file`, str(msg)) errprint("%s: I/O Error: %s" % (`file`, str(msg)))
return return
if verbose > 1: if verbose > 1:
...@@ -66,7 +73,7 @@ def check(file): ...@@ -66,7 +73,7 @@ def check(file):
tokenize.tokenize(f.readline, tokeneater) tokenize.tokenize(f.readline, tokeneater)
except tokenize.TokenError, msg: except tokenize.TokenError, msg:
print "%s: Token Error: %s" % (`file`, str(msg)) errprint("%s: Token Error: %s" % (`file`, str(msg)))
return return
except NannyNag, nag: except NannyNag, nag:
......
...@@ -13,18 +13,25 @@ import tokenize ...@@ -13,18 +13,25 @@ import tokenize
verbose = 0 verbose = 0
def errprint(*args):
sep = ""
for arg in args:
sys.stderr.write(sep + str(arg))
sep = " "
sys.stderr.write("\n")
def main(): def main():
global verbose global verbose
try: try:
opts, args = getopt.getopt(sys.argv[1:], "v") opts, args = getopt.getopt(sys.argv[1:], "v")
except getopt.error, msg: except getopt.error, msg:
print msg errprint(msg)
return return
for o, a in opts: for o, a in opts:
if o == '-v': if o == '-v':
verbose = verbose + 1 verbose = verbose + 1
if not args: if not args:
print "Usage:", sys.argv[0], "[-v] file_or_directory ..." errprint("Usage:", sys.argv[0], "[-v] file_or_directory ...")
return return
for arg in args: for arg in args:
check(arg) check(arg)
...@@ -55,7 +62,7 @@ def check(file): ...@@ -55,7 +62,7 @@ def check(file):
try: try:
f = open(file) f = open(file)
except IOError, msg: except IOError, msg:
print "%s: I/O Error: %s" % (`file`, str(msg)) errprint("%s: I/O Error: %s" % (`file`, str(msg)))
return return
if verbose > 1: if verbose > 1:
...@@ -66,7 +73,7 @@ def check(file): ...@@ -66,7 +73,7 @@ def check(file):
tokenize.tokenize(f.readline, tokeneater) tokenize.tokenize(f.readline, tokeneater)
except tokenize.TokenError, msg: except tokenize.TokenError, msg:
print "%s: Token Error: %s" % (`file`, str(msg)) errprint("%s: Token Error: %s" % (`file`, str(msg)))
return return
except NannyNag, nag: except NannyNag, nag:
......
...@@ -13,18 +13,25 @@ import tokenize ...@@ -13,18 +13,25 @@ import tokenize
verbose = 0 verbose = 0
def errprint(*args):
sep = ""
for arg in args:
sys.stderr.write(sep + str(arg))
sep = " "
sys.stderr.write("\n")
def main(): def main():
global verbose global verbose
try: try:
opts, args = getopt.getopt(sys.argv[1:], "v") opts, args = getopt.getopt(sys.argv[1:], "v")
except getopt.error, msg: except getopt.error, msg:
print msg errprint(msg)
return return
for o, a in opts: for o, a in opts:
if o == '-v': if o == '-v':
verbose = verbose + 1 verbose = verbose + 1
if not args: if not args:
print "Usage:", sys.argv[0], "[-v] file_or_directory ..." errprint("Usage:", sys.argv[0], "[-v] file_or_directory ...")
return return
for arg in args: for arg in args:
check(arg) check(arg)
...@@ -55,7 +62,7 @@ def check(file): ...@@ -55,7 +62,7 @@ def check(file):
try: try:
f = open(file) f = open(file)
except IOError, msg: except IOError, msg:
print "%s: I/O Error: %s" % (`file`, str(msg)) errprint("%s: I/O Error: %s" % (`file`, str(msg)))
return return
if verbose > 1: if verbose > 1:
...@@ -66,7 +73,7 @@ def check(file): ...@@ -66,7 +73,7 @@ def check(file):
tokenize.tokenize(f.readline, tokeneater) tokenize.tokenize(f.readline, tokeneater)
except tokenize.TokenError, msg: except tokenize.TokenError, msg:
print "%s: Token Error: %s" % (`file`, str(msg)) errprint("%s: Token Error: %s" % (`file`, str(msg)))
return return
except NannyNag, nag: except NannyNag, nag:
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment