Commit 6bac5920 authored by Ivan Tyagov's avatar Ivan Tyagov

X on zodb catobj

parent b1163449
......@@ -35,7 +35,7 @@ def register_command(cmdname):
command_module = importlib.import_module('zodbtools.zodb' + cmdname)
command_dict[cmdname] = command_module
for _ in ('analyze', 'cmp', 'dump', 'info'):
for _ in ('analyze', 'catobj', 'cmp', 'dump', 'info'):
register_command(_)
......
# Copyright (C) 2017-2018 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 Free Software licenses or 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.
# See https://www.nexedi.com/licensing for rationale and options.
"""Catobj dump content of a database object"""
from __future__ import print_function
from zodbtools.util import storageFromURL
# XXX -> common place
class Xid:
# .at tid for ZODB view
# .oid object ID
def __init__(self, at, oid):
self.at, self.oid = at, oid
# catobj dumps content of one ZODB object.
#
# The object is printed in raw form without any headers (see Dumpobj)
def catobj(w, stor, xid):
# XXX hack
data, serial, serial_next = stor.loadBefore(xid.oid, xid.at) # FIXME at -> at2Before(at)
w.write(data)
# TODO dumpobj
# ----------------------------------------
import sys, getopt
summary = "dump content of a database object"
def usage(out):
print("""\
Usage: zodb catobj [OPTIONS] <storage> xid...
Dump content of a ZODB database object.
<storage> is an URL (see 'zodb help zurl') of a ZODB-storage.
xid is object address (see 'zodb help xid').
Options:
-h --help this help text.
--hashonly dump only hashes of objects without content.
--raw dump object data without any headers. Only one object allowed.
""", file=out)
def main(argv):
hashonly = False
raw = False
try:
optv, argv = getopt.getopt(argv[1:], "h", ["help", "hashonly", "raw"])
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)
if opt in ("--hashonly"):
hashonly = True
if opt in ("--raw"):
raw = True
try:
storurl = argv[0]
except IndexError:
usage(sys.stderr)
sys.exit(2)
if hashonly and raw:
print("--hashonly & --raw are incompativle", file=sys.stderr)
sys.exit(2)
# XXX parse xid -> xidv
from ZODB.utils import p64
at = p64(0x03c8c86d1a31a5f3 + 1)
oid = p64(0xf87b)
xidv = [Xid(at, oid)] # XXX hack, temp
stor = storageFromURL(storurl, read_only=True)
def _catobj(xid):
if raw:
catobj(sys.stdout, stor, xid)
else:
dumpobj(sys.stdout, stor, xid, hashonly)
for xid in xidv:
_catobj(xid)
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