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 10 11defgetrevlimit(): 12 var ='SVNRMAX' 13if os.environ.has_key(var): 14return os.environ[var] 15return None 16 17defwritedump(url, lower, upper): 18if url.startswith('sim://'): 19 filename = url[6:] 20if filename[-1] =='/': filename = filename[:-1]#remove terminating slash 21else: 22raiseValueError('sim:// url required') 23 f =open(filename,'r'); 24 state ='header' 25 wroterev =False 26while(True): 27 l = f.readline() 28if l =='':break 29if state =='header'and l.startswith('Revision-number: '): 30 state ='prefix' 31if state =='prefix'and l =='Revision-number:%s\n'% lower: 32 state ='selection' 33if not upper =='HEAD'and state =='selection'and l =='Revision-number:%s\n'% upper: 34break; 35 36if state =='header'or state =='selection': 37if state =='selection': wroterev =True 38 sys.stdout.write(l) 39return wroterev 40 41if __name__ =="__main__": 42if not(len(sys.argv)in(3,4,5)): 43print"usage:%sdump URL -rLOWER:UPPER" 44 sys.exit(1) 45if not sys.argv[1] =='dump':raiseNotImplementedError('only "dump" is suppported.') 46 url = sys.argv[2] 47 r = ('0','HEAD') 48iflen(sys.argv) ==4and sys.argv[3][0:2] =='-r': 49 r = sys.argv[3][2:].lstrip().split(':') 50if notgetrevlimit()is None: r[1] =getrevlimit() 51ifwritedump(url, r[0], r[1]): ret =0 52else: ret =1 53 sys.exit(ret)