1#!/usr/bin/python 2""" 3Simulates svnrdump by replaying an existing dump from a file, taking care 4of the specified revision range. 5To simulate incremental imports the environment variable SVNRMAX can be set 6to the highest revision that should be available. 7""" 8import sys, os 9 10if sys.hexversion <0x02040000: 11# The limiter is the ValueError() calls. This may be too conservative 12 sys.stderr.write("svnrdump-sim.py: requires Python 2.4 or later.\n") 13 sys.exit(1) 14 15defgetrevlimit(): 16 var ='SVNRMAX' 17if var in os.environ: 18return os.environ[var] 19return None 20 21defwritedump(url, lower, upper): 22if url.startswith('sim://'): 23 filename = url[6:] 24if filename[-1] =='/': filename = filename[:-1]#remove terminating slash 25else: 26raiseValueError('sim:// url required') 27 f =open(filename,'r'); 28 state ='header' 29 wroterev =False 30while(True): 31 l = f.readline() 32if l =='':break 33if state =='header'and l.startswith('Revision-number: '): 34 state ='prefix' 35if state =='prefix'and l =='Revision-number:%s\n'% lower: 36 state ='selection' 37if not upper =='HEAD'and state =='selection'and l =='Revision-number:%s\n'% upper: 38break; 39 40if state =='header'or state =='selection': 41if state =='selection': wroterev =True 42 sys.stdout.write(l) 43return wroterev 44 45if __name__ =="__main__": 46if not(len(sys.argv)in(3,4,5)): 47print("usage:%sdump URL -rLOWER:UPPER") 48 sys.exit(1) 49if not sys.argv[1] =='dump':raiseNotImplementedError('only "dump" is suppported.') 50 url = sys.argv[2] 51 r = ('0','HEAD') 52iflen(sys.argv) ==4and sys.argv[3][0:2] =='-r': 53 r = sys.argv[3][2:].lstrip().split(':') 54if notgetrevlimit()is None: r[1] =getrevlimit() 55ifwritedump(url, r[0], r[1]): ret =0 56else: ret =1 57 sys.exit(ret)