Mercurial > ~astiob > upreckon > hgweb
comparison test-svn.py @ 15:c0e925ae721e
Flush stdout during update; initial work on memory usage control
| author | Oleg Oshmyan <chortos@inbox.lv> |
|---|---|
| date | Tue, 01 Jun 2010 21:57:05 +0000 |
| parents | 28b1f4853968 |
| children | d4fc9341664e |
comparison
equal
deleted
inserted
replaced
| 14:28b1f4853968 | 15:c0e925ae721e |
|---|---|
| 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') | 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') |
| 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') | 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') |
| 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') | 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') |
| 15 parser.add_option('-p', '--python', action='store_true', default=False, help='always parse all positional arguments as a single Python expression (including the first argument even if it names an executable file)') | 15 parser.add_option('-p', '--python', action='store_true', default=False, help='always parse all positional arguments as a single Python expression (including the first argument even if it names an executable file)') |
| 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') | 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') |
| 17 parser.add_option('-b', dest='builtin', action='store_true', default=False) | |
| 17 | 18 |
| 18 options, args = parser.parse_args() | 19 options, args = parser.parse_args() |
| 19 parser.destroy() | 20 parser.destroy() |
| 20 del parser | 21 del parser |
| 22 | |
| 23 if options.builtin: | |
| 24 try: | |
| 25 if args[0] == 'run': | |
| 26 import resource | |
| 27 maxmemory = int(args[1]) | |
| 28 resource.setrlimit(resource.RLIMIT_AS, (maxmemory*1024**2, maxmemory*1024**2)) | |
| 29 os.execv(args[2], args[2:]) | |
| 30 else: | |
| 31 sys.exit(2) | |
| 32 except: | |
| 33 sys.exit(2) | |
| 21 | 34 |
| 22 def update(): | 35 def update(): |
| 23 import urllib | 36 import urllib |
| 24 latesttext = urllib.urlopen('http://chortos.selfip.net/~astiob/test.py/version.txt').read() | 37 latesttext = urllib.urlopen('http://chortos.selfip.net/~astiob/test.py/version.txt').read() |
| 25 latest = latesttext.split('.') | 38 latest = latesttext.split('.') |
| 38 return | 51 return |
| 39 if update == '': | 52 if update == '': |
| 40 print 'Your copy of test.py is newer than the publicly available version.' | 53 print 'Your copy of test.py is newer than the publicly available version.' |
| 41 return | 54 return |
| 42 print 'A ' + update + ' update to test.py is available. Downloading...' | 55 print 'A ' + update + ' update to test.py is available. Downloading...' |
| 56 sys.stdout.flush() | |
| 43 urllib.urlretrieve('http://chortos.selfip.net/~astiob/test.py/test.py', 'test.py') | 57 urllib.urlretrieve('http://chortos.selfip.net/~astiob/test.py/test.py', 'test.py') |
| 44 print 'Downloaded and installed. Now you are using test.py ' + latesttext + '.' | 58 print 'Downloaded and installed. Now you are using test.py ' + latesttext + '.' |
| 45 | 59 |
| 46 if options.update: | 60 if options.update: |
| 47 update() | 61 update() |
| 48 sys.exit() | 62 sys.exit() |
| 63 | |
| 64 try: | |
| 65 import resource | |
| 66 memlimit = True | |
| 67 def call(name): | |
| 68 pid = os.fork() | |
| 69 if not pid: | |
| 70 resource.setrlimit(resource.RLIMIT_AS, (maxmemory*1024**2, maxmemory*1024**2)) | |
| 71 os.execl(name) | |
| 72 else: | |
| 73 return pid | |
| 74 except ImportError: | |
| 75 memlimit = False | |
| 49 | 76 |
| 50 globals1 = set(globals()) | 77 globals1 = set(globals()) |
| 51 | 78 |
| 52 # Initialize some configuration variables with default values | 79 # Initialize some configuration variables with default values |
| 53 tasknames = (os.path.curdir,) | 80 tasknames = (os.path.curdir,) |
