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:
--max=txncount
Stop after committing txncount transactions.
-k txncount
--skip=txncount
Skip the first txncount transactions.
-p/--profile
Turn on specialized profiling.
......@@ -64,10 +68,10 @@ def usage(code, msg=''):
def main():
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',
'output=', 'logfile=', 'profile',
'max='])
'max=', 'skip='])
except getopt.error, msg:
usage(1, msg)
......@@ -79,6 +83,7 @@ def main():
logfile = None
profilep = 0
maxtxn = -1
skiptxn = -1
options = Options()
......@@ -99,6 +104,8 @@ def main():
options.profilep = 1
elif opt in ('-m', '--max'):
options.maxtxn = int(arg)
elif opt in ('-k', '--skip'):
options.skiptxn = int(arg)
if args:
usage(1)
......@@ -106,6 +113,26 @@ def main():
if not options.source or not options.dest:
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...'
t0 = time.time()
srcdb = FileStorage(options.source, read_only=1)
......@@ -119,6 +146,7 @@ def main():
dstdb = Full(options.dest)
t1 = time.time()
print >>sys.stderr, 'Opening destination BDB done. %s seconds' % (t1-t0)
#
# Uncomment this section to do a FS->FS migration
#
......@@ -129,26 +157,6 @@ def main():
## print >>sys.stderr, 'Opening destination FileStorage done. %s seconds' % (
## 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:
t0 = time.time()
doit(srcdb, dstdb, options)
......@@ -179,7 +187,11 @@ def doit(srcdb, dstdb, options):
ok = 1
prevrevids = {}
counter = 0
skipper = 0
for txn in srcdb.iterator():
skipper += 1
if skipper <= options.skiptxn:
continue
counter += 1
if counter > options.maxtxn > 0:
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