#!/bin/python

import run_tests
import os
import time
import subprocess
import sys

# returns a list of new revisions
def svn_fetch():

	current_version = run_tests.svn_info()[0]

	p = subprocess.Popen(['svn', 'up'], stdout=subprocess.PIPE)

	revision = -1

	output = ''
	for l in p.stdout:
		if 'At revision ' in l:
			revision = int(l.split('At revision')[1].strip()[0:-1])
		if 'Updated to revision ' in l:
			revision = int(l.split('Updated to revision')[1].strip()[0:-1])
		output += l

	if revision == -1:
		print '\n\nsvn update failed\n\n%s' % output
		sys.exit(1)

	return range(current_version + 1, revision + 1)

def svn_up(revision):
	os.system('svn up %d' % revision)

def print_usage():
	print '''usage: run_regression_tests.py [options] toolset [toolset...]

toolset are bjam toolsets. For instance clang, gcc, darwin, msvc etc.
The path "./regression_tests" is expected to be a shared folder
between all testsers.

options:

   -j<n>    use n parallel processes for running tests
'''


def loop():

	if len(sys.argv) < 3:
		print_usage()
		sys.exit(1)

	while True:
		revs = svn_fetch()
		# reverse the list to always run the tests for the
		# latest version first, then fill in with the history
		revs.reverse()

		for r in revs:
			print '\n\nREVISION %d ===\n' % r
			svn_up(r)
	
			run_tests.main(sys.argv[1:])
	
		time.sleep(120)

if __name__ == "__main__":
	loop()

@@ -129,54 +129,18 @@
 tch(
-):%0A%0A%09current_version = run_tests.svn_info()%5B0%5D
+last_rev):
 %0A%0A%09p
@@ -549,23 +549,16 @@
 nge(
-current_version
+last_rev
  + 1
@@ -1024,165 +1024,289 @@
 )%0A%0A%09
-while True:%0A%09%09revs = svn_fetch()%0A%09%09# reverse the list to always run the tests for the%0A%09%09# latest version first, then fill in with the history%0A%09%09revs.reverse(
+rev_file = os.path.join(os.getcwd(), '.rev')%0A%09print 'restoring last state from %22%25s%22' %25 rev_file%0A%0A%09try:%0A%09%09last_rev = int(open(rev_file, 'r').read())%0A%09except:%0A%09%09last_rev = run_tests.svn_info()%5B0%5D%0A%09%09open(rev_file, 'w+').write('%25d' %25 last_rev)%0A%0A%09while True:%0A%09%09revs = svn_fetch(last_rev
 )%0A%0A%09
@@ -1405,16 +1405,81 @@
 gv%5B1:%5D)%0A
+%09%09%09last_rev = r;%0A%0A%09%09%09open(rev_file, 'w+').write('%25d' %25 last_rev)%0A
 %09%0A%09%09time

save state about last regression test revision across invocations