Mercurial > ~astiob > upreckon > hgweb
annotate upreckon-vcs @ 111:5462291b66d5 2.00
Fixed mishandling of some variables in multi-problem legacy configurations
| author | Oleg Oshmyan <chortos@inbox.lv> |
|---|---|
| date | Fri, 08 Apr 2011 19:22:19 +0300 |
| parents | c62c9bfd614a |
| children | 796eb7667fb0 c4dba6d44194 |
| rev | line source |
|---|---|
| 21 | 1 #! /usr/bin/env python |
| 78 | 2 # Copyright (c) 2009-2011 Chortos-2 <chortos@inbox.lv> |
| 16 | 3 |
| 4 from __future__ import division, with_statement | |
| 5 import optparse, sys, compat | |
| 21 | 6 |
| 7 from compat import * | |
| 16 | 8 |
|
33
f90bd2d1a12b
Converted revision reporting from SVN to hg.
Oleg Oshmyan <chortos@inbox.lv>
parents:
26
diff
changeset
|
9 version = '2.00.0 ($$REV$$)' |
| 45 | 10 parser = optparse.OptionParser(version='Upreckon '+version, epilog='Python 2.5 or newer is required.') |
| 23 | 11 parser.add_option('-1', dest='legacy', action='store_true', default=False, help='handle configuration files in a way more compatible with test.py 1.x') |
| 45 | 12 parser.add_option('-u', '--update', dest='update', action='store_true', default=False, help='update the installed Upreckon to the latest publicly available version') |
|
25
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
23
diff
changeset
|
13 parser.add_option('-p', '--problem', dest='problems', metavar='PROBLEM', action='append', help='test only the PROBLEM (this option can be specified more than once with different problem names, all of which will be tested)') |
| 16 | 14 parser.add_option('-m', '--copy-io', dest='copyonly', action='store_true', default=False, help='create a copy of the input/output files of the last test case for manual testing and exit') |
| 15 parser.add_option('-x', '--auto-exit', dest='pause', action='store_false', default=True, help='do not wait for a key to be pressed after finishing testing') | |
| 21 | 16 parser.add_option('-s', '--save-io', dest='erase', action='store_false', default=True, help='do not delete the copies of input/output files after the last test case; create copies of input files and store output in files even if the solution uses standard I/O; delete the stored input/output files if the solution uses standard I/O and the -c/--cleanup option is specified') |
| 17 parser.add_option('-t', '--detect-time', dest='autotime', action='store_true', default=False, help='spend a second detecting the most precise time measurement function') | |
|
90
1fb319ec33af
Skimming mode added (-k/--skim option)
Oleg Oshmyan <chortos@inbox.lv>
parents:
87
diff
changeset
|
18 parser.add_option('-k', '--skim', action='store_true', default=False, help='skip test groups as soon as one test case is failed') |
| 21 | 19 parser.add_option('--no-time-limits', dest='no_maxtime', action='store_true', default=False, help='disable all time limits') |
| 16 | 20 |
| 21 options, args = parser.parse_args() | |
| 22 parser.destroy() | |
| 23 del parser | |
| 24 | |
| 25 if options.update: | |
| 26 try: | |
| 27 urllib, urlread = compat.import_urllib() | |
| 28 except ImportError: | |
| 29 sys.exit('Error: the urllib Python module is missing. Without it, an automatic update is impossible.') | |
| 30 | |
| 31 latesttext = urlread('http://chortos.selfip.net/~astiob/test.py/version.txt') | |
| 32 latest = latesttext.split('.') | |
| 33 installed = version.split('.') | |
| 34 update = None | |
| 35 | |
| 36 if latest[0] > installed[0]: | |
| 37 update = 'major' | |
| 38 elif latest[0] == installed[0]: | |
| 39 if latest[1] > installed[1]: | |
| 40 update = 'feature' | |
| 41 elif latest[1] == installed[1]: | |
| 42 if latest[2] > installed[2]: | |
| 43 update = 'bug-fixing' | |
| 44 elif latest[2] == installed[2]: | |
|
87
179bad0d29f4
--update now includes version numbers in all messages it prints
Oleg Oshmyan <chortos@inbox.lv>
parents:
85
diff
changeset
|
45 say('You are using the latest publicly available version of Upreckon (%s).' % latesttext) |
| 16 | 46 sys.exit() |
| 47 | |
| 48 if not update: | |
|
87
179bad0d29f4
--update now includes version numbers in all messages it prints
Oleg Oshmyan <chortos@inbox.lv>
parents:
85
diff
changeset
|
49 say('Your copy of Upreckon is newer (%s) than the publicly available version (%s).' % (version, latesttext)) |
| 16 | 50 sys.exit() |
| 51 | |
|
87
179bad0d29f4
--update now includes version numbers in all messages it prints
Oleg Oshmyan <chortos@inbox.lv>
parents:
85
diff
changeset
|
52 say('A %s update to Upreckon is available (%s). Downloading...' % (update, latesttext)) |
| 16 | 53 sys.stdout.flush() |
| 45 | 54 # FIXME: need to update all files! |
| 16 | 55 urllib.urlretrieve('http://chortos.selfip.net/~astiob/test.py/test.py', sys.argv[0]) |
|
87
179bad0d29f4
--update now includes version numbers in all messages it prints
Oleg Oshmyan <chortos@inbox.lv>
parents:
85
diff
changeset
|
56 say('Downloaded and installed. Now you are using Upreckon %s.' % latesttext) |
| 16 | 57 sys.exit() |
| 58 | |
| 22 | 59 import config, itertools, os, subprocess, sys, time |
| 16 | 60 |
|
70
b9d5857f7b9a
Better emulation of built-ins for testconf
Oleg Oshmyan <chortos@inbox.lv>
parents:
66
diff
changeset
|
61 if options.legacy: |
|
b9d5857f7b9a
Better emulation of built-ins for testconf
Oleg Oshmyan <chortos@inbox.lv>
parents:
66
diff
changeset
|
62 compat.pseudobuiltins += 'xrange', |
|
b9d5857f7b9a
Better emulation of built-ins for testconf
Oleg Oshmyan <chortos@inbox.lv>
parents:
66
diff
changeset
|
63 |
| 91 | 64 import testcases |
|
66
34ba0b353fc6
Fixed an issue when import errors would be ignored
Oleg Oshmyan <chortos@inbox.lv>
parents:
64
diff
changeset
|
65 |
|
34ba0b353fc6
Fixed an issue when import errors would be ignored
Oleg Oshmyan <chortos@inbox.lv>
parents:
64
diff
changeset
|
66 try: |
| 22 | 67 from testcases import pause |
| 68 except ImportError: | |
| 69 pause = None | |
| 70 | |
| 71 try: | |
| 21 | 72 globalconf = config.load_global() |
| 16 | 73 |
| 21 | 74 # Do this check here so that if we have to warn them, we do it as early as possible |
| 22 | 75 if options.pause and not pause and not hasattr(globalconf, 'pause'): |
|
25
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
23
diff
changeset
|
76 if os.name == 'posix': |
|
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
23
diff
changeset
|
77 globalconf.pause = 'read -s -n 1' |
| 45 | 78 say('Warning: configuration variable pause is not defined; it was devised automatically but the choice might be incorrect, so Upreckon might exit immediately after the testing is completed.', file=sys.stderr) |
|
25
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
23
diff
changeset
|
79 sys.stderr.flush() |
|
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
23
diff
changeset
|
80 elif os.name == 'nt': |
|
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
23
diff
changeset
|
81 globalconf.pause = 'pause' |
|
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
23
diff
changeset
|
82 else: |
|
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
23
diff
changeset
|
83 sys.exit('Error: configuration variable pause is not defined and cannot be devised automatically.') |
| 16 | 84 |
| 91 | 85 from problem import * |
| 16 | 86 |
| 21 | 87 # Support single-problem configurations |
|
79
ee8a99dcaaed
Renamed configuration variable tasknames to problems
Oleg Oshmyan <chortos@inbox.lv>
parents:
78
diff
changeset
|
88 if globalconf.problems is None: |
| 21 | 89 shouldprintnames = False |
| 90 globalconf.multiproblem = False | |
|
79
ee8a99dcaaed
Renamed configuration variable tasknames to problems
Oleg Oshmyan <chortos@inbox.lv>
parents:
78
diff
changeset
|
91 globalconf.problems = os.path.curdir, |
| 16 | 92 else: |
| 21 | 93 globalconf.multiproblem = True |
|
25
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
23
diff
changeset
|
94 shouldprintnames = True |
| 16 | 95 |
| 21 | 96 ntasks = 0 |
| 97 nfulltasks = 0 | |
| 98 maxscore = 0 | |
| 99 realscore = 0 | |
| 16 | 100 |
|
79
ee8a99dcaaed
Renamed configuration variable tasknames to problems
Oleg Oshmyan <chortos@inbox.lv>
parents:
78
diff
changeset
|
101 for taskname in (globalconf.problems if not options.problems else options.problems): |
| 21 | 102 problem = Problem(taskname) |
| 103 | |
| 22 | 104 if ntasks and not options.copyonly: say() |
| 21 | 105 if shouldprintnames: say(taskname) |
| 106 | |
| 107 if options.copyonly: | |
| 108 problem.copytestdata() | |
| 109 else: | |
| 110 real, max = problem.test() | |
| 111 | |
| 112 ntasks += 1 | |
| 22 | 113 nfulltasks += real == max |
| 21 | 114 realscore += real |
| 115 maxscore += max | |
| 116 | |
| 117 if options.copyonly: | |
| 118 sys.exit() | |
| 119 | |
| 120 if ntasks != 1: | |
| 121 say() | |
| 64 | 122 say('Grand total: %g/%g weighted points; %d/%d problems solved fully' % (realscore, maxscore, nfulltasks, ntasks)) |
| 21 | 123 except KeyboardInterrupt: |
| 124 sys.exit('Exiting due to a keyboard interrupt.') | |
| 16 | 125 |
| 126 if options.pause: | |
| 21 | 127 say('Press any key to exit...') |
| 16 | 128 sys.stdout.flush() |
| 129 | |
| 22 | 130 if pause: |
| 131 pause() | |
| 132 elif callable(globalconf.pause): | |
| 133 globalconf.pause() | |
| 134 else: | |
| 135 with open(os.devnull, 'w') as devnull: | |
| 83 | 136 subprocess.call(globalconf.pause, shell=True, stdout=devnull, stderr=subprocess.STDOUT) |
