Commit 8192b9bc authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 5c6637ef
......@@ -37,7 +37,7 @@ import (
)
// fsIndex is Oid -> Data record position mapping used to associate Oid with
// Data record in latest transaction which changed it. XXX text
// Data record in latest transaction which changed it.
type fsIndex struct {
*fsb.Tree
}
......
// Copyright (C) 2017 Nexedi SA and Contributors. XXX -> GPLv3
// 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 2, or (at your
// 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.
//
......
// Copyright (C) 2017 Nexedi SA and Contributors. XXX -> GPLv3
// 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 2, or (at your
// 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.
//
......
......@@ -10,6 +10,9 @@ import (
"os"
)
// XXX interface for a Reader/Writer which can report position
// -> Nread(), Nwrote() ?
// CountReader is an io.Reader that count total bytes read
type CountReader struct {
io.Reader
......@@ -25,7 +28,7 @@ func (r *CountReader) Read(p []byte) (int, error) {
// TODO func to get position (requiring io.Seeker to just Seek(0, SeekCurrent) is too much)
// XXX previously used InputOffset(), but generally e.g. for io.Writer "input" is not appropriate
// like io.LimitedReader but for writes
// LimitedWriter is like io.LimitedReader but for writes
type LimitedWriter struct {
io.Writer
N int64
......
......@@ -2,9 +2,14 @@
// 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 2, or (at your
// 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.
//
......@@ -29,7 +34,7 @@ txn ...
*/
package main
package zodbtools
import (
"crypto/sha1"
......@@ -41,8 +46,8 @@ import (
"lab.nexedi.com/kirr/go123/xfmt"
"../../../zodb"
"../../../storage/fs1"
"../../zodb"
"../../storage/fs1"
)
......@@ -190,35 +195,36 @@ func (d *dumper) Dump(stor zodb.IStorage, tidMin, tidMax zodb.Tid) error {
return nil
}
// zodbDump dumps contents of a storage in between tidMin..tidMax range to a writer.
// Dump dumps contents of a storage in between tidMin..tidMax range to a writer.
// see top-level documentation for the dump format.
func zodbDump(w io.Writer, stor zodb.IStorage, tidMin, tidMax zodb.Tid, hashOnly bool) error {
func Dump(w io.Writer, stor zodb.IStorage, tidMin, tidMax zodb.Tid, hashOnly bool) error {
d := dumper{W: w, HashOnly: hashOnly}
return d.Dump(stor, tidMin, tidMax)
}
func usage() {
fmt.Fprintf(os.Stderr,
`zodbdump [options] <storage> [tidmin..tidmax]
func dumpUsage(w io.Writer) {
fmt.Fprintf(w,
`zodb dump [options] <storage> [tidmin..tidmax]
Dump content of a ZODB database.
<storage> is a path to FileStorage XXX will become URL
<storage> is an URL (see 'zodb help zurl') of a ZODB-storage.
options:
Options:
-h --help this help text.
-hashonly dump only hashes of objects without content.
`)
}
func main() {
func DumpMain(argv []string) {
hashOnly := false
tidRange := ".." // (0, +inf)
flag.Usage = usage
flag.BoolVar(&hashOnly, "hashonly", hashOnly, "dump only hashes of objects")
flag.Parse()
flags := flag.FlagSet{Usage: func() { dumpUsage(os.Stderr) }}
flags.Init("", flag.ExitOnError)
flags.BoolVar(&hashOnly, "hashonly", hashOnly, "dump only hashes of objects")
flags.Parse(argv)
argv := flag.Args()
if len(argv) < 1 {
......@@ -242,7 +248,7 @@ func main() {
log.Fatal(err)
}
err = zodbDump(os.Stdout, stor, tidMin, tidMax, hashOnly)
err = Dump(os.Stdout, stor, tidMin, tidMax, hashOnly)
if err != nil {
log.Fatal(err)
}
......
// TODO copyright/license
// Copyright (C) 2016-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.
package main
......@@ -10,8 +25,8 @@ import (
"regexp"
"testing"
"../../../storage/fs1"
"../../../zodb"
"../../storage/fs1"
"../../zodb"
"github.com/sergi/go-diff/diffmatchpatch"
"lab.nexedi.com/kirr/go123/exc"
......@@ -56,7 +71,8 @@ func loadZdumpPy(t *testing.T, path string) string {
}
func withTestdata1Fs(t testing.TB, f func(fs *fs1.FileStorage)) {
fs, err := fs1.Open("../../../storage/fs1/testdata/1.fs") // XXX read-only, path?
// XXX -> zodb.OpenURL
fs, err := fs1.Open("../../storage/fs1/testdata/1.fs") // XXX read-only, path?
if err != nil {
t.Fatal(err)
}
......
// 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
package zodbtools
# {} 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