changeset 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 231e3317477d
files publish.py test.py
diffstat 2 files changed, 47 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/publish.py	Fri Mar 12 23:53:27 2010 +0000
@@ -0,0 +1,12 @@
+#! /usr/bin/python
+# Copyright (c) 2009-2010 Chortos-2 <chortos@inbox.lv>
+
+with open('test.py') as t:
+	f = t.read()
+i = f.find('# $Rev: ')
+j = f.find('\n', i)
+rev = f[i+8:j-1]
+f = f[0:i] + f[j+1:]
+f = f.replace('$$REV$$', rev)
+with open('test-pub.py', 'wb') as t:
+	t.write(f)
\ No newline at end of file
--- a/test.py	Sun Feb 14 00:51:27 2010 +0000
+++ b/test.py	Fri Mar 12 23:53:27 2010 +0000
@@ -3,7 +3,10 @@
 
 import os, sys, shutil, time, subprocess, filecmp, optparse, signal, tempfile, tarfile, zipfile
 
-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.')
+# $Rev: 11$
+version = '1.21.0 (SVN r$$REV$$)'
+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.')
+parser.add_option('-u', '--update', dest='update', action='store_true', default=False, help='check for an updated version of test.py')
 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')
 parser.add_option('-c', '--cleanup', dest='clean', action='store_true', default=False, help='delete the copies of input/output files and exit')
 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')
@@ -16,6 +19,37 @@
 parser.destroy()
 del parser
 
+def update():
+	import urllib
+	homepage = urllib.urlopen('http://chortos.selfip.net/~astiob/test.py/').read()
+	i = homepage.find("The latest version of test.py is <span style='font-weight: bold; font-size: larger'>")
+	i += len("The latest version of test.py is <span style='font-weight: bold; font-size: larger'>")
+	j = homepage.find(".</span>", i)
+	latest = homepage[i:j].split('.')
+	installed = version.split('.')
+	update = ''
+	if latest[0] > installed[0]:
+		update = 'major'
+	elif latest[0] == installed[0]:
+		if latest[1] > installed[1]:
+			update = 'feature'
+		elif latest[1] == installed[1]:
+			if latest[2] > installed[2]:
+				update = 'bug-fixing'
+			elif latest[2] == installed[2]:
+				print 'You are using the latest publicly available version of test.py.'
+				return
+	if update == '':
+		print 'Your copy of test.py is newer than the publicly available version.'
+		return
+	print 'A ' + update + ' update to test.py is available. Downloading...'
+	urllib.urlretrieve('http://chortos.selfip.net/~astiob/test.py/test.py', 'test.py')
+	print 'Downloaded and installed. Now you are using test.py ' + homepage[i:j] + '.'
+
+if options.update:
+	update()
+	sys.exit()
+
 globals1 = set(globals())
 
 # Initialize some configuration variables with default values