Mercurial > ~astiob > upreckon > hgweb
annotate upreckon-vcs @ 144:25b929aa92a1
publish.sh now uses hg identify
author | Oleg Oshmyan <chortos@inbox.lv> |
---|---|
date | Fri, 27 May 2011 02:27:07 +0100 |
parents | dfde0f5e0984 |
children |
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 |
102
796eb7667fb0
Added the --list-problems command-line option
Oleg Oshmyan <chortos@inbox.lv>
parents:
91
diff
changeset
|
9 version = '2.01.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)') |
102
796eb7667fb0
Added the --list-problems command-line option
Oleg Oshmyan <chortos@inbox.lv>
parents:
91
diff
changeset
|
14 parser.add_option('--list-problems', action='store_true', default=False, help='just list all problem names') |
16 | 15 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') |
16 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 | 17 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') |
18 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
|
19 parser.add_option('-k', '--skim', action='store_true', default=False, help='skip test groups as soon as one test case is failed') |
21 | 20 parser.add_option('--no-time-limits', dest='no_maxtime', action='store_true', default=False, help='disable all time limits') |
16 | 21 |
22 options, args = parser.parse_args() | |
23 parser.destroy() | |
24 del parser | |
25 | |
26 if options.update: | |
27 try: | |
28 urllib, urlread = compat.import_urllib() | |
29 except ImportError: | |
30 sys.exit('Error: the urllib Python module is missing. Without it, an automatic update is impossible.') | |
31 | |
32 latesttext = urlread('http://chortos.selfip.net/~astiob/test.py/version.txt') | |
33 latest = latesttext.split('.') | |
34 installed = version.split('.') | |
35 update = None | |
36 | |
37 if latest[0] > installed[0]: | |
38 update = 'major' | |
39 elif latest[0] == installed[0]: | |
40 if latest[1] > installed[1]: | |
41 update = 'feature' | |
42 elif latest[1] == installed[1]: | |
43 if latest[2] > installed[2]: | |
44 update = 'bug-fixing' | |
45 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
|
46 say('You are using the latest publicly available version of Upreckon (%s).' % latesttext) |
16 | 47 sys.exit() |
48 | |
49 if not update: | |
87
179bad0d29f4
--update now includes version numbers in all messages it prints
Oleg Oshmyan <chortos@inbox.lv>
parents:
85
diff
changeset
|
50 say('Your copy of Upreckon is newer (%s) than the publicly available version (%s).' % (version, latesttext)) |
16 | 51 sys.exit() |
52 | |
87
179bad0d29f4
--update now includes version numbers in all messages it prints
Oleg Oshmyan <chortos@inbox.lv>
parents:
85
diff
changeset
|
53 say('A %s update to Upreckon is available (%s). Downloading...' % (update, latesttext)) |
16 | 54 sys.stdout.flush() |
45 | 55 # FIXME: need to update all files! |
16 | 56 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
|
57 say('Downloaded and installed. Now you are using Upreckon %s.' % latesttext) |
16 | 58 sys.exit() |
59 | |
22 | 60 import config, itertools, os, subprocess, sys, time |
16 | 61 |
70
b9d5857f7b9a
Better emulation of built-ins for testconf
Oleg Oshmyan <chortos@inbox.lv>
parents:
66
diff
changeset
|
62 if options.legacy: |
b9d5857f7b9a
Better emulation of built-ins for testconf
Oleg Oshmyan <chortos@inbox.lv>
parents:
66
diff
changeset
|
63 compat.pseudobuiltins += 'xrange', |
b9d5857f7b9a
Better emulation of built-ins for testconf
Oleg Oshmyan <chortos@inbox.lv>
parents:
66
diff
changeset
|
64 |
102
796eb7667fb0
Added the --list-problems command-line option
Oleg Oshmyan <chortos@inbox.lv>
parents:
91
diff
changeset
|
65 if options.list_problems: |
796eb7667fb0
Added the --list-problems command-line option
Oleg Oshmyan <chortos@inbox.lv>
parents:
91
diff
changeset
|
66 options.pause = False |
796eb7667fb0
Added the --list-problems command-line option
Oleg Oshmyan <chortos@inbox.lv>
parents:
91
diff
changeset
|
67 |
91 | 68 import testcases |
66
34ba0b353fc6
Fixed an issue when import errors would be ignored
Oleg Oshmyan <chortos@inbox.lv>
parents:
64
diff
changeset
|
69 |
34ba0b353fc6
Fixed an issue when import errors would be ignored
Oleg Oshmyan <chortos@inbox.lv>
parents:
64
diff
changeset
|
70 try: |
22 | 71 from testcases import pause |
72 except ImportError: | |
73 pause = None | |
74 | |
75 try: | |
21 | 76 globalconf = config.load_global() |
102
796eb7667fb0
Added the --list-problems command-line option
Oleg Oshmyan <chortos@inbox.lv>
parents:
91
diff
changeset
|
77 |
21 | 78 # Do this check here so that if we have to warn them, we do it as early as possible |
22 | 79 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
|
80 if os.name == 'posix': |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
23
diff
changeset
|
81 globalconf.pause = 'read -s -n 1' |
45 | 82 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
|
83 sys.stderr.flush() |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
23
diff
changeset
|
84 elif os.name == 'nt': |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
23
diff
changeset
|
85 globalconf.pause = 'pause' |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
23
diff
changeset
|
86 else: |
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
23
diff
changeset
|
87 sys.exit('Error: configuration variable pause is not defined and cannot be devised automatically.') |
102
796eb7667fb0
Added the --list-problems command-line option
Oleg Oshmyan <chortos@inbox.lv>
parents:
91
diff
changeset
|
88 |
91 | 89 from problem import * |
102
796eb7667fb0
Added the --list-problems command-line option
Oleg Oshmyan <chortos@inbox.lv>
parents:
91
diff
changeset
|
90 |
21 | 91 # Support single-problem configurations |
79
ee8a99dcaaed
Renamed configuration variable tasknames to problems
Oleg Oshmyan <chortos@inbox.lv>
parents:
78
diff
changeset
|
92 if globalconf.problems is None: |
21 | 93 shouldprintnames = False |
94 globalconf.multiproblem = False | |
79
ee8a99dcaaed
Renamed configuration variable tasknames to problems
Oleg Oshmyan <chortos@inbox.lv>
parents:
78
diff
changeset
|
95 globalconf.problems = os.path.curdir, |
16 | 96 else: |
21 | 97 globalconf.multiproblem = True |
25
b500e117080e
Bug fixes and overhead reduction
Oleg Oshmyan <chortos@inbox.lv>
parents:
23
diff
changeset
|
98 shouldprintnames = True |
102
796eb7667fb0
Added the --list-problems command-line option
Oleg Oshmyan <chortos@inbox.lv>
parents:
91
diff
changeset
|
99 |
796eb7667fb0
Added the --list-problems command-line option
Oleg Oshmyan <chortos@inbox.lv>
parents:
91
diff
changeset
|
100 if options.list_problems: |
796eb7667fb0
Added the --list-problems command-line option
Oleg Oshmyan <chortos@inbox.lv>
parents:
91
diff
changeset
|
101 for taskname in globalconf.problems: |
796eb7667fb0
Added the --list-problems command-line option
Oleg Oshmyan <chortos@inbox.lv>
parents:
91
diff
changeset
|
102 say(taskname) |
796eb7667fb0
Added the --list-problems command-line option
Oleg Oshmyan <chortos@inbox.lv>
parents:
91
diff
changeset
|
103 sys.exit() |
796eb7667fb0
Added the --list-problems command-line option
Oleg Oshmyan <chortos@inbox.lv>
parents:
91
diff
changeset
|
104 |
21 | 105 ntasks = 0 |
106 nfulltasks = 0 | |
107 maxscore = 0 | |
108 realscore = 0 | |
102
796eb7667fb0
Added the --list-problems command-line option
Oleg Oshmyan <chortos@inbox.lv>
parents:
91
diff
changeset
|
109 |
79
ee8a99dcaaed
Renamed configuration variable tasknames to problems
Oleg Oshmyan <chortos@inbox.lv>
parents:
78
diff
changeset
|
110 for taskname in (globalconf.problems if not options.problems else options.problems): |
21 | 111 problem = Problem(taskname) |
112 | |
22 | 113 if ntasks and not options.copyonly: say() |
21 | 114 if shouldprintnames: say(taskname) |
115 | |
116 if options.copyonly: | |
117 problem.copytestdata() | |
118 else: | |
119 real, max = problem.test() | |
120 | |
121 ntasks += 1 | |
22 | 122 nfulltasks += real == max |
21 | 123 realscore += real |
124 maxscore += max | |
102
796eb7667fb0
Added the --list-problems command-line option
Oleg Oshmyan <chortos@inbox.lv>
parents:
91
diff
changeset
|
125 |
21 | 126 if options.copyonly: |
127 sys.exit() | |
102
796eb7667fb0
Added the --list-problems command-line option
Oleg Oshmyan <chortos@inbox.lv>
parents:
91
diff
changeset
|
128 |
21 | 129 if ntasks != 1: |
130 say() | |
64 | 131 say('Grand total: %g/%g weighted points; %d/%d problems solved fully' % (realscore, maxscore, nfulltasks, ntasks)) |
21 | 132 except KeyboardInterrupt: |
138
517dd43f06f8
Upreckon now properly reports exiting due to SIGINT to the calling process
Oleg Oshmyan <chortos@inbox.lv>
parents:
102
diff
changeset
|
133 say('Exiting due to a keyboard interrupt.', end='', file=sys.stderr) |
141 | 134 sys.stderr.flush() |
138
517dd43f06f8
Upreckon now properly reports exiting due to SIGINT to the calling process
Oleg Oshmyan <chortos@inbox.lv>
parents:
102
diff
changeset
|
135 try: |
517dd43f06f8
Upreckon now properly reports exiting due to SIGINT to the calling process
Oleg Oshmyan <chortos@inbox.lv>
parents:
102
diff
changeset
|
136 import os, signal |
517dd43f06f8
Upreckon now properly reports exiting due to SIGINT to the calling process
Oleg Oshmyan <chortos@inbox.lv>
parents:
102
diff
changeset
|
137 signal.signal(signal.SIGINT, signal.SIG_DFL) |
517dd43f06f8
Upreckon now properly reports exiting due to SIGINT to the calling process
Oleg Oshmyan <chortos@inbox.lv>
parents:
102
diff
changeset
|
138 os.kill(os.getpid(), signal.SIGINT) |
517dd43f06f8
Upreckon now properly reports exiting due to SIGINT to the calling process
Oleg Oshmyan <chortos@inbox.lv>
parents:
102
diff
changeset
|
139 except Exception: |
517dd43f06f8
Upreckon now properly reports exiting due to SIGINT to the calling process
Oleg Oshmyan <chortos@inbox.lv>
parents:
102
diff
changeset
|
140 pass |
517dd43f06f8
Upreckon now properly reports exiting due to SIGINT to the calling process
Oleg Oshmyan <chortos@inbox.lv>
parents:
102
diff
changeset
|
141 # Do this even if we got no exceptions, just in case |
517dd43f06f8
Upreckon now properly reports exiting due to SIGINT to the calling process
Oleg Oshmyan <chortos@inbox.lv>
parents:
102
diff
changeset
|
142 say(file=sys.stderr) |
517dd43f06f8
Upreckon now properly reports exiting due to SIGINT to the calling process
Oleg Oshmyan <chortos@inbox.lv>
parents:
102
diff
changeset
|
143 sys.exit(1) |
16 | 144 |
145 if options.pause: | |
21 | 146 say('Press any key to exit...') |
16 | 147 sys.stdout.flush() |
148 | |
22 | 149 if pause: |
150 pause() | |
151 elif callable(globalconf.pause): | |
152 globalconf.pause() | |
153 else: | |
154 with open(os.devnull, 'w') as devnull: | |
83 | 155 subprocess.call(globalconf.pause, shell=True, stdout=devnull, stderr=subprocess.STDOUT) |