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 9import os 10 11if sys.hexversion <0x02040000: 12# The limiter is the ValueError() calls. This may be too conservative 13 sys.stderr.write("svnrdump-sim.py: requires Python 2.4 or later.\n") 14 sys.exit(1) 15 16 17defgetrevlimit(): 18 var ='SVNRMAX' 19if var in os.environ: 20return os.environ[var] 21return None 22 23 24defwritedump(url, lower, upper): 25if url.startswith('sim://'): 26 filename = url[6:] 27if filename[-1] =='/': 28 filename = filename[:-1]# remove terminating slash 29else: 30raiseValueError('sim:// url required') 31 f =open(filename,'r') 32 state ='header' 33 wroterev =False 34while(True): 35 l = f.readline() 36if l =='': 37break 38if state =='header'and l.startswith('Revision-number: '): 39 state ='prefix' 40if state =='prefix'and l =='Revision-number:%s\n'% lower: 41 state ='selection' 42if not upper =='HEAD'and state =='selection'and \ 43 l =='Revision-number:%s\n'% upper: 44break 45 46if state =='header'or state =='selection': 47if state =='selection': 48 wroterev =True 49 sys.stdout.write(l) 50return wroterev 51 52if __name__ =="__main__": 53if not(len(sys.argv)in(3,4,5)): 54print("usage:%sdump URL -rLOWER:UPPER") 55 sys.exit(1) 56if not sys.argv[1] =='dump': 57raiseNotImplementedError('only "dump" is suppported.') 58 url = sys.argv[2] 59 r = ('0','HEAD') 60iflen(sys.argv) ==4and sys.argv[3][0:2] =='-r': 61 r = sys.argv[3][2:].lstrip().split(':') 62if notgetrevlimit()is None: 63 r[1] =getrevlimit() 64ifwritedump(url, r[0], r[1]): 65 ret =0 66else: 67 ret =1 68 sys.exit(ret)