Use argparse. Fixes #58.
This commit is contained in:
parent
1317268843
commit
961bc45385
|
@ -84,7 +84,11 @@ Other Enhancements
|
|||
same). See :issue:`38`.
|
||||
|
||||
- Conflict resolution reads all conflicts from the database in one
|
||||
query, instead of querying for each individual conflict. See :issue:`39`.
|
||||
query, instead of querying for each individual conflict. See
|
||||
:issue:`39`.
|
||||
|
||||
- ``zodbconvert`` and ``zodbpack`` use :mod:`argparse` instead of
|
||||
:mod:`optparse` for command line handling.
|
||||
|
||||
|
||||
1.6.0b3 (2014-12-08)
|
||||
|
|
|
@ -18,7 +18,7 @@ ZODB storage conversion utility.
|
|||
from __future__ import print_function
|
||||
|
||||
import logging
|
||||
import optparse
|
||||
import argparse
|
||||
from persistent.TimeStamp import TimeStamp
|
||||
from io import StringIO
|
||||
import sys
|
||||
|
@ -71,34 +71,32 @@ class _DefaultStartStorageIteration(object):
|
|||
def main(argv=None):
|
||||
if argv is None:
|
||||
argv = sys.argv
|
||||
parser = optparse.OptionParser(description=__doc__,
|
||||
usage="%prog [options] config_file")
|
||||
parser.add_option(
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument(
|
||||
"--dry-run", dest="dry_run", action="store_true",
|
||||
default=False,
|
||||
help="Attempt to open both storages, then explain what would be done.")
|
||||
parser.add_option(
|
||||
parser.add_argument(
|
||||
"--clear", dest="clear", action="store_true",
|
||||
default=False,
|
||||
help="Clear the contents of the destination storage before copying. Only works if the destination is a RelStorage."
|
||||
" WARNING: use this only if you are certain the destination has no useful data.")
|
||||
parser.add_option(
|
||||
parser.add_argument(
|
||||
"--incremental", dest="incremental", action="store_true",
|
||||
help="Assume the destination contains a partial copy of the source "
|
||||
"and resume copying from the last transaction. WARNING: no "
|
||||
"effort is made to verify that the destination holds the same "
|
||||
"transaction data before this point! Use at your own risk. ")
|
||||
parser.add_argument("config_file")
|
||||
|
||||
parser.set_defaults(dry_run=False, clear=False)
|
||||
options, args = parser.parse_args(argv[1:])
|
||||
|
||||
if len(args) != 1:
|
||||
parser.error("The name of one configuration file is required.")
|
||||
options = parser.parse_args(argv[1:])
|
||||
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
format="%(asctime)s [%(name)s] %(levelname)s %(message)s")
|
||||
|
||||
schema = ZConfig.loadSchemaFile(StringIO(schema_xml))
|
||||
config, _ = ZConfig.loadConfig(schema, args[0])
|
||||
config, _ = ZConfig.loadConfig(schema, options.config_file)
|
||||
source = config.source.open()
|
||||
destination = config.destination.open()
|
||||
|
||||
|
|
|
@ -12,12 +12,13 @@
|
|||
# FOR A PARTICULAR PURPOSE.
|
||||
#
|
||||
##############################################################################
|
||||
"""ZODB storage packing utility.
|
||||
"""
|
||||
ZODB storage packing utility.
|
||||
"""
|
||||
|
||||
from io import StringIO
|
||||
import logging
|
||||
import optparse
|
||||
import argparse
|
||||
import sys
|
||||
import time
|
||||
import ZConfig
|
||||
|
@ -37,38 +38,37 @@ log = logging.getLogger("zodbpack")
|
|||
def main(argv=None):
|
||||
if argv is None:
|
||||
argv = sys.argv
|
||||
parser = optparse.OptionParser(description=__doc__,
|
||||
usage="%prog [options] config_file")
|
||||
parser.add_option(
|
||||
"-d", "--days", dest="days", default="0",
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
|
||||
parser.add_argument(
|
||||
"-d", "--days", dest="days", default=0,
|
||||
help="Days of history to keep (default 0)",
|
||||
type=float,
|
||||
)
|
||||
parser.add_option(
|
||||
parser.add_argument(
|
||||
"--prepack", dest="prepack", default=False,
|
||||
action="store_true",
|
||||
help="Perform only the pre-pack preparation stage of a pack. "
|
||||
"(Only works with some storage types)",
|
||||
)
|
||||
parser.add_option(
|
||||
parser.add_argument(
|
||||
"--use-prepack-state", dest="reuse_prepack", default=False,
|
||||
action="store_true",
|
||||
help="Skip the preparation stage and go straight to packing. "
|
||||
"Requires that a pre-pack has been run, or that packing was aborted "
|
||||
"before it was completed.",
|
||||
)
|
||||
options, args = parser.parse_args(argv[1:])
|
||||
|
||||
if len(args) != 1:
|
||||
parser.error("The name of one configuration file is required.")
|
||||
parser.add_argument("config_file")
|
||||
options = parser.parse_args(argv[1:])
|
||||
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
format="%(asctime)s [%(name)s] %(levelname)s %(message)s")
|
||||
|
||||
schema = ZConfig.loadSchemaFile(StringIO(schema_xml))
|
||||
config, _ = ZConfig.loadConfig(schema, args[0])
|
||||
config, _ = ZConfig.loadConfig(schema, options.config_file)
|
||||
|
||||
t = time.time() - float(options.days) * 86400.0
|
||||
t = time.time() - options.days * 86400.0
|
||||
for s in config.storages:
|
||||
name = '%s (%s)' % ((s.name or 'storage'), s.__class__.__name__)
|
||||
log.info("Opening %s...", name)
|
||||
|
|
Loading…
Reference in New Issue