Commit 3b52b2fd authored by Barry Warsaw's avatar Barry Warsaw

Added -k/--skip option.

Also, move the opening of the output and log files above the opening
of the storages so there's a closer link between that and the
try/finally that closes closes the storages.
parent 35cf6062
...@@ -26,6 +26,10 @@ Options: ...@@ -26,6 +26,10 @@ Options:
--max=txncount --max=txncount
Stop after committing txncount transactions. Stop after committing txncount transactions.
-k txncount
--skip=txncount
Skip the first txncount transactions.
-p/--profile -p/--profile
Turn on specialized profiling. Turn on specialized profiling.
...@@ -64,10 +68,10 @@ def usage(code, msg=''): ...@@ -64,10 +68,10 @@ def usage(code, msg=''):
def main(): def main():
try: try:
opts, args = getopt.getopt(sys.argv[1:], 'hs:d:qo:l:pm:', opts, args = getopt.getopt(sys.argv[1:], 'hs:d:qo:l:pm:k:',
['help', 'source=', 'dest=', 'quiet', ['help', 'source=', 'dest=', 'quiet',
'output=', 'logfile=', 'profile', 'output=', 'logfile=', 'profile',
'max=']) 'max=', 'skip='])
except getopt.error, msg: except getopt.error, msg:
usage(1, msg) usage(1, msg)
...@@ -79,6 +83,7 @@ def main(): ...@@ -79,6 +83,7 @@ def main():
logfile = None logfile = None
profilep = 0 profilep = 0
maxtxn = -1 maxtxn = -1
skiptxn = -1
options = Options() options = Options()
...@@ -99,6 +104,8 @@ def main(): ...@@ -99,6 +104,8 @@ def main():
options.profilep = 1 options.profilep = 1
elif opt in ('-m', '--max'): elif opt in ('-m', '--max'):
options.maxtxn = int(arg) options.maxtxn = int(arg)
elif opt in ('-k', '--skip'):
options.skiptxn = int(arg)
if args: if args:
usage(1) usage(1)
...@@ -106,6 +113,26 @@ def main(): ...@@ -106,6 +113,26 @@ def main():
if not options.source or not options.dest: if not options.source or not options.dest:
usage(1, 'Source and destination databases must be provided') usage(1, 'Source and destination databases must be provided')
# Open the output file
if options.outfile is None:
options.outfp = sys.stdout
options.outclosep = 0
else:
options.outfp = open(options.outfile, 'w')
options.outclosep = 1
# Open the logfile
if options.logfile is None:
options.logfp = sys.stdout
options.logclosep = 0
else:
options.logfp = open(options.logfile, 'w')
options.logclosep = 1
# Print a comment, this is a hack
print >> options.outfp, '# FS->BDB 3.3.11'
print >> options.outfp, '#', time.ctime()
print >>sys.stderr, 'Opening source FileStorage...' print >>sys.stderr, 'Opening source FileStorage...'
t0 = time.time() t0 = time.time()
srcdb = FileStorage(options.source, read_only=1) srcdb = FileStorage(options.source, read_only=1)
...@@ -119,6 +146,7 @@ def main(): ...@@ -119,6 +146,7 @@ def main():
dstdb = Full(options.dest) dstdb = Full(options.dest)
t1 = time.time() t1 = time.time()
print >>sys.stderr, 'Opening destination BDB done. %s seconds' % (t1-t0) print >>sys.stderr, 'Opening destination BDB done. %s seconds' % (t1-t0)
# #
# Uncomment this section to do a FS->FS migration # Uncomment this section to do a FS->FS migration
# #
...@@ -129,26 +157,6 @@ def main(): ...@@ -129,26 +157,6 @@ def main():
## print >>sys.stderr, 'Opening destination FileStorage done. %s seconds' % ( ## print >>sys.stderr, 'Opening destination FileStorage done. %s seconds' % (
## t1-t0) ## t1-t0)
# Open the output file
if options.outfile is None:
options.outfp = sys.stdout
options.outclosep = 0
else:
options.outfp = open(options.outfile, 'w')
options.outclosep = 1
# Open the logfile
if options.logfile is None:
options.logfp = sys.stdout
options.logclosep = 0
else:
options.logfp = open(options.logfile, 'w')
options.logclosep = 1
# Print a comment, this is a hack
print >> options.outfp, '# FS->BDB 3.3.11'
print >> options.outfp, '#', time.ctime()
try: try:
t0 = time.time() t0 = time.time()
doit(srcdb, dstdb, options) doit(srcdb, dstdb, options)
...@@ -179,7 +187,11 @@ def doit(srcdb, dstdb, options): ...@@ -179,7 +187,11 @@ def doit(srcdb, dstdb, options):
ok = 1 ok = 1
prevrevids = {} prevrevids = {}
counter = 0 counter = 0
skipper = 0
for txn in srcdb.iterator(): for txn in srcdb.iterator():
skipper += 1
if skipper <= options.skiptxn:
continue
counter += 1 counter += 1
if counter > options.maxtxn > 0: if counter > options.maxtxn > 0:
break break
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment