Commit 37b9fbde authored by Kirill Smelkov's avatar Kirill Smelkov

Zodbinfo - Tool to print general information about a ZODB database

Either all general parameters at once:

    $ zodb info neo://neo1@127.0.0.1:24573
    name=NEOStorage(neo1)
    size=0
    last_tid=03be7484ddc7f6ee

or one particular parameter:

    $ zodb info neo://neo1@127.0.0.1:24573 last_tid
    03be7484ddc7f6ee
parent bfeb1690
...@@ -11,3 +11,4 @@ __ https://github.com/zopefoundation/ZODB/pull/128#issuecomment-260970932 ...@@ -11,3 +11,4 @@ __ https://github.com/zopefoundation/ZODB/pull/128#issuecomment-260970932
- `zodb analyze` - analyze FileStorage or repozo deltafs usage. - `zodb analyze` - analyze FileStorage or repozo deltafs usage.
- `zodb cmp` - compare content of two ZODB databases bit-to-bit. - `zodb cmp` - compare content of two ZODB databases bit-to-bit.
- `zodb dump` - dump content of a ZODB database. - `zodb dump` - dump content of a ZODB database.
- `zodb info` - print general information about a ZODB database.
...@@ -33,7 +33,7 @@ def register_command(cmdname): ...@@ -33,7 +33,7 @@ def register_command(cmdname):
command_module = importlib.import_module('zodbtools.zodb' + cmdname) command_module = importlib.import_module('zodbtools.zodb' + cmdname)
command_dict[cmdname] = command_module command_dict[cmdname] = command_module
for _ in ('analyze', 'cmp', 'dump'): for _ in ('analyze', 'cmp', 'dump', 'info'):
register_command(_) register_command(_)
......
# -*- coding: utf-8 -*-
# Copyright (C) 2017 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com>
#
# This program is free software: you can Use, Study, Modify and Redistribute
# it under the terms of the GNU General Public License version 3, or (at your
# option) any later version, as published by the Free Software Foundation.
#
# You can also Link and Combine this program with other software covered by
# the terms of any of the Open Source Initiative approved licenses and Convey
# the resulting work. Corresponding source of such a combination shall include
# the source code for all other software used.
#
# This program is distributed WITHOUT ANY WARRANTY; without even the implied
# warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
#
# See COPYING file for full licensing terms.
"""Zodbinfo - Print general information about a ZODB database"""
from __future__ import print_function
from zodbtools.util import ashex, storageFromURL
from collections import OrderedDict
import sys
# {} parameter_name -> get_parameter(stor)
infoDict = OrderedDict([
("name", lambda stor: stor.getName()),
("size", lambda stor: stor.getSize()),
("last_tid", lambda stor: ashex(stor.lastTransaction())),
])
def zodbinfo(stor, parameterv):
wantnames = False
if not parameterv:
parameterv = infoDict.keys()
wantnames = True
for parameter in parameterv:
get_parameter = infoDict.get(parameter)
if get_parameter is None:
print("invalid parameter: %s" % parameter, file=sys.stderr)
sys.exit(1)
out = ""
if wantnames:
out += parameter + "="
out += "%s" % (get_parameter(stor),)
print(out)
# ----------------------------------------
import getopt
summary = "print general information about a ZODB database"
def usage(out):
print("""\
Usage: zodb info [OPTIONS] <storage> [parameter ...]
Print general information about a ZODB database.
<storage> is an URL (see 'zodb help zurl') of a ZODB-storage.
By default info prints information about all storage parameters. If one or
more parameter names are given as arguments, info prints the value of each
named parameter on its own line.
Options:
-h --help show this help
""", file=out)
def main(argv):
try:
optv, argv = getopt.getopt(argv[1:], "h", ["help"])
except getopt.GetoptError as e:
print(e, file=sys.stderr)
usage(sys.stderr)
sys.exit(2)
for opt, _ in optv:
if opt in ("-h", "--help"):
usage(sys.stdout)
sys.exit(0)
try:
storurl = argv[0]
except IndexError:
usage(sys.stderr)
sys.exit(2)
stor = storageFromURL(storurl, read_only=True)
zodbinfo(stor, argv[1:])
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