From 9065ea36deb5812654c1959413a92cfb18ad3b5a Mon Sep 17 00:00:00 2001 From: Fred Drake Date: Mon, 29 Mar 1999 20:25:40 +0000 Subject: When run as a script, report failures in the exit code as well. Patch largely based on changes by Andrew Dalke, as discussed in the distutils-sig. --- Lib/compileall.py | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/Lib/compileall.py b/Lib/compileall.py index 69a59b3..e56c8b2 100644 --- a/Lib/compileall.py +++ b/Lib/compileall.py @@ -36,6 +36,7 @@ def compile_dir(dir, maxlevels=10, ddir=None, force=0): print "Can't list", dir names = [] names.sort() + success = 1 for name in names: fullname = os.path.join(dir, name) if ddir: @@ -61,11 +62,13 @@ def compile_dir(dir, maxlevels=10, ddir=None, force=0): else: exc_type_name = sys.exc_type.__name__ print 'Sorry:', exc_type_name + ':', print sys.exc_value + success = 0 elif maxlevels > 0 and \ name != os.curdir and name != os.pardir and \ os.path.isdir(fullname) and \ not os.path.islink(fullname): compile_dir(fullname, maxlevels - 1, dfile, force) + return success def compile_path(skip_curdir=1, maxlevels=0, force=0): """Byte-compile all module on sys.path. @@ -77,11 +80,13 @@ def compile_path(skip_curdir=1, maxlevels=0, force=0): force: as for compile_dir() (default 0) """ + success = 1 for dir in sys.path: if (not dir or dir == os.curdir) and skip_curdir: print 'Skipping current directory' else: - compile_dir(dir, maxlevels, None, force) + success = success and compile_dir(dir, maxlevels, None, force) + return success def main(): """Script main program.""" @@ -107,14 +112,17 @@ def main(): if len(args) != 1: print "-d destdir require exactly one directory argument" sys.exit(2) + success = 1 try: if args: for dir in args: - compile_dir(dir, maxlevels, ddir, force) + success = success and compile_dir(dir, maxlevels, ddir, force) else: - compile_path() + success = compile_path() except KeyboardInterrupt: print "\n[interrupt]" + success = 0 + return success if __name__ == '__main__': - main() + sys.exit(not main()) -- cgit v0.12