comparison test.py @ 10:c87ec78f1fae

Auto-update and revision number reporting added
author Oleg Oshmyan <chortos@inbox.lv>
date Fri, 12 Mar 2010 23:53:27 +0000
parents ed90b375d197
children
comparison
equal deleted inserted replaced
9:ed90b375d197 10:c87ec78f1fae
1 #! /usr/bin/python 1 #! /usr/bin/python
2 # Copyright (c) 2009-2010 Chortos-2 <chortos@inbox.lv> 2 # Copyright (c) 2009-2010 Chortos-2 <chortos@inbox.lv>
3 3
4 import os, sys, shutil, time, subprocess, filecmp, optparse, signal, tempfile, tarfile, zipfile 4 import os, sys, shutil, time, subprocess, filecmp, optparse, signal, tempfile, tarfile, zipfile
5 5
6 parser = optparse.OptionParser(version='test.py 1.21.0 (SVN)', usage='usage: %prog [options] [problem names] [[path' + os.path.sep + 'to' + os.path.sep + ']solution-app] [test case numbers]\n\nTest case numbers can be specified in plain text or as a Python expression\nif there is only one positional argument.\n\nOnly problem names listed in testconf.py are recognized.') 6 # $Rev: 11$
7 version = '1.21.0 (SVN r$$REV$$)'
8 parser = optparse.OptionParser(version='test.py '+version, usage='usage: %prog [options] [problem names] [[path' + os.path.sep + 'to' + os.path.sep + ']solution-app] [test case numbers]\n\nTest case numbers can be specified in plain text or as a Python expression\nif there is only one positional argument.\n\nOnly problem names listed in testconf.py are recognized.')
9 parser.add_option('-u', '--update', dest='update', action='store_true', default=False, help='check for an updated version of test.py')
7 parser.add_option('-e', '--exclude', dest='exclude', action='append', help='test case number(s) to exclude, as a Python expression; multiple -e options can be supplied') 10 parser.add_option('-e', '--exclude', dest='exclude', action='append', help='test case number(s) to exclude, as a Python expression; multiple -e options can be supplied')
8 parser.add_option('-c', '--cleanup', dest='clean', action='store_true', default=False, help='delete the copies of input/output files and exit') 11 parser.add_option('-c', '--cleanup', dest='clean', action='store_true', default=False, help='delete the copies of input/output files and exit')
9 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') 12 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')
10 parser.add_option('-m', '--copy-io', dest='copyonly', action='store_true', default=False, help='only create a copy of the input/output files of the last test case for manual testing; to delete them, use options -cs or -cm') 13 parser.add_option('-m', '--copy-io', dest='copyonly', action='store_true', default=False, help='only create a copy of the input/output files of the last test case for manual testing; to delete them, use options -cs or -cm')
11 parser.add_option('-x', '--auto-exit', dest='pause', action='store_false', default=True, help='do not wait for a key to be pressed when finished testing') 14 parser.add_option('-x', '--auto-exit', dest='pause', action='store_false', default=True, help='do not wait for a key to be pressed when finished testing')
13 parser.add_option('-t', '--detect-time', dest='autotime', action='store_true', default=False, help='spend a second detecting the most precise time measurement function') 16 parser.add_option('-t', '--detect-time', dest='autotime', action='store_true', default=False, help='spend a second detecting the most precise time measurement function')
14 17
15 options, args = parser.parse_args() 18 options, args = parser.parse_args()
16 parser.destroy() 19 parser.destroy()
17 del parser 20 del parser
21
22 def update():
23 import urllib
24 homepage = urllib.urlopen('http://chortos.selfip.net/~astiob/test.py/').read()
25 i = homepage.find("The latest version of test.py is <span style='font-weight: bold; font-size: larger'>")
26 i += len("The latest version of test.py is <span style='font-weight: bold; font-size: larger'>")
27 j = homepage.find(".</span>", i)
28 latest = homepage[i:j].split('.')
29 installed = version.split('.')
30 update = ''
31 if latest[0] > installed[0]:
32 update = 'major'
33 elif latest[0] == installed[0]:
34 if latest[1] > installed[1]:
35 update = 'feature'
36 elif latest[1] == installed[1]:
37 if latest[2] > installed[2]:
38 update = 'bug-fixing'
39 elif latest[2] == installed[2]:
40 print 'You are using the latest publicly available version of test.py.'
41 return
42 if update == '':
43 print 'Your copy of test.py is newer than the publicly available version.'
44 return
45 print 'A ' + update + ' update to test.py is available. Downloading...'
46 urllib.urlretrieve('http://chortos.selfip.net/~astiob/test.py/test.py', 'test.py')
47 print 'Downloaded and installed. Now you are using test.py ' + homepage[i:j] + '.'
48
49 if options.update:
50 update()
51 sys.exit()
18 52
19 globals1 = set(globals()) 53 globals1 = set(globals())
20 54
21 # Initialize some configuration variables with default values 55 # Initialize some configuration variables with default values
22 tasknames = (os.path.curdir,) 56 tasknames = (os.path.curdir,)