hgbook
diff en/examples/run-example @ 512:9412f706651e
Publishing via rsync
author | Igor Támara <igor@tamarapatino.org> |
---|---|
date | Fri Jan 16 23:34:35 2009 -0500 (2009-01-16) |
parents | 06ab90119fa6 |
children | d8913b7869b5 |
line diff
1.1 --- a/en/examples/run-example Mon Apr 16 14:39:51 2007 -0700 1.2 +++ b/en/examples/run-example Fri Jan 16 23:34:35 2009 -0500 1.3 @@ -323,10 +323,26 @@ 1.4 os.system('diff -u %s %s 1>&2' % (oldname, errname)) 1.5 return True 1.6 1.7 +def print_help(exit, msg=None): 1.8 + if msg: 1.9 + print >> sys.stderr, 'Error:', msg 1.10 + print >> sys.stderr, 'Usage: run-example [options] [test...]' 1.11 + print >> sys.stderr, 'Options:' 1.12 + print >> sys.stderr, ' -a --all run all tests in this directory' 1.13 + print >> sys.stderr, ' -h --help print this help message' 1.14 + print >> sys.stderr, ' -v --verbose display extra debug output' 1.15 + sys.exit(exit) 1.16 + 1.17 def main(path='.'): 1.18 - opts, args = getopt.getopt(sys.argv[1:], 'v', ['verbose']) 1.19 + opts, args = getopt.getopt(sys.argv[1:], '?ahv', 1.20 + ['all', 'help', 'verbose']) 1.21 verbose = False 1.22 + run_all = False 1.23 for o, a in opts: 1.24 + if o in ('-h', '-?', '--help'): 1.25 + print_help(0) 1.26 + if o in ('-a', '--all'): 1.27 + run_all = True 1.28 if o in ('-v', '--verbose'): 1.29 verbose = True 1.30 errs = 0 1.31 @@ -344,26 +360,32 @@ 1.32 else: 1.33 print >> sys.stderr, '%s: not a file, or not executable' % a 1.34 errs += 1 1.35 - return errs 1.36 - names = os.listdir(path) 1.37 - names.sort() 1.38 - for name in names: 1.39 - if name == 'run-example' or name.startswith('.'): continue 1.40 - if name.endswith('.out') or name.endswith('~'): continue 1.41 - if name.endswith('.run'): continue 1.42 - pathname = os.path.join(path, name) 1.43 - try: 1.44 - st = os.lstat(pathname) 1.45 - except OSError, err: 1.46 - # could be an output file that was removed while we ran 1.47 - if err.errno != errno.ENOENT: 1.48 - raise 1.49 - continue 1.50 - if stat.S_ISREG(st.st_mode) and st.st_mode & 0111: 1.51 - if example(pathname, verbose).run(): 1.52 - errs += 1 1.53 - print >> open(os.path.join(path, '.run'), 'w'), time.asctime() 1.54 + elif run_all: 1.55 + names = os.listdir(path) 1.56 + names.sort() 1.57 + for name in names: 1.58 + if name == 'run-example' or name.startswith('.'): continue 1.59 + if name.endswith('.out') or name.endswith('~'): continue 1.60 + if name.endswith('.run'): continue 1.61 + pathname = os.path.join(path, name) 1.62 + try: 1.63 + st = os.lstat(pathname) 1.64 + except OSError, err: 1.65 + # could be an output file that was removed while we ran 1.66 + if err.errno != errno.ENOENT: 1.67 + raise 1.68 + continue 1.69 + if stat.S_ISREG(st.st_mode) and st.st_mode & 0111: 1.70 + if example(pathname, verbose).run(): 1.71 + errs += 1 1.72 + print >> open(os.path.join(path, '.run'), 'w'), time.asctime() 1.73 + else: 1.74 + print_help(1, msg='no test names given, and --all not provided') 1.75 return errs 1.76 1.77 if __name__ == '__main__': 1.78 - sys.exit(main()) 1.79 + try: 1.80 + sys.exit(main()) 1.81 + except KeyboardInterrupt: 1.82 + print >> sys.stderr, 'interrupted!' 1.83 + sys.exit(1)