Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
N
neo
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Jobs
Commits
Open sidebar
Kirill Smelkov
neo
Commits
af34e00a
Commit
af34e00a
authored
Apr 21, 2017
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
15b948d7
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
169 additions
and
65 deletions
+169
-65
t/neo/zodb/cmd/zodb/zodb.go
t/neo/zodb/cmd/zodb/zodb.go
+5
-0
t/neo/zodb/zodb.go
t/neo/zodb/zodb.go
+8
-0
t/neo/zodb/zodbtools/command.go
t/neo/zodb/zodbtools/command.go
+54
-0
t/neo/zodb/zodbtools/dump.go
t/neo/zodb/zodbtools/dump.go
+9
-6
t/neo/zodb/zodbtools/dump_test.go
t/neo/zodb/zodbtools/dump_test.go
+1
-1
t/neo/zodb/zodbtools/info.go
t/neo/zodb/zodbtools/info.go
+92
-58
No files found.
t/neo/zodb/cmd/zodb/zodb.go
View file @
af34e00a
...
@@ -19,6 +19,7 @@
...
@@ -19,6 +19,7 @@
package
main
package
main
import
(
import
(
"../../zodbtools"
)
)
...
@@ -41,6 +42,10 @@ Usage:
...
@@ -41,6 +42,10 @@ Usage:
The commands are:
The commands are:
`
)
`
)
// TODO print commands
// TODO print commands
for
_
,
cmd
:=
range
zodbtools
.
AllCommands
()
{
fmt
.
Fprintf
(
w
,
"
\t
%s
\t
%s
\n
"
,
cmd
.
Name
,
cmd
.
Summary
)
}
fmt
.
Fprintf
(
w
,
fmt
.
Fprintf
(
w
,
`
`
...
...
t/neo/zodb/zodb.go
View file @
af34e00a
...
@@ -158,3 +158,11 @@ type IStorageRecordIterator interface { // XXX naming -> IRecordIterator
...
@@ -158,3 +158,11 @@ type IStorageRecordIterator interface { // XXX naming -> IRecordIterator
// end of iteration is indicated with io.EOF
// end of iteration is indicated with io.EOF
NextData
()
(
*
StorageRecordInformation
,
error
)
NextData
()
(
*
StorageRecordInformation
,
error
)
}
}
// TODO readonly
func
Open
(
storageURL
string
)
(
IStorage
,
error
)
{
// TODO
return
nil
,
nil
}
t/neo/zodb/zodbtools/command.go
0 → 100644
View file @
af34e00a
// 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.
package
zodbtools
import
(
"io"
)
// Command describes one zodb subcommand
type
Command
struct
{
Name
string
Summary
string
Usage
func
(
w
io
.
Writer
)
Main
func
(
argv
[]
string
)
}
// registry of all commands
var
cmdv
=
[]
Command
{
// NOTE the order commands are listed here is the order how they will appear in help
// TODO analyze ?
// TODO cmp
{
"dump"
,
dumpSummary
,
dumpUsage
,
dumpMain
},
{
"info"
,
infoSummary
,
infoUsage
,
infoMain
},
}
// LookupCommand returns Command with corresponding name or nil
func
LookupCommand
(
command
string
)
*
Command
{
for
i
:=
range
cmdv
{
if
cmdv
[
i
]
.
Name
==
command
{
return
&
cmdv
[
i
]
}
}
return
nil
}
// AllCommands returns list of all zodbtools commands
func
AllCommands
()
[]
Command
{
return
cmdv
}
t/neo/zodb/zodbtools/dump.go
View file @
af34e00a
...
@@ -47,7 +47,7 @@ import (
...
@@ -47,7 +47,7 @@ import (
"lab.nexedi.com/kirr/go123/xfmt"
"lab.nexedi.com/kirr/go123/xfmt"
"../../zodb"
"../../zodb"
"../../storage/fs1"
//
"../../storage/fs1"
)
)
...
@@ -202,10 +202,13 @@ func Dump(w io.Writer, stor zodb.IStorage, tidMin, tidMax zodb.Tid, hashOnly boo
...
@@ -202,10 +202,13 @@ func Dump(w io.Writer, stor zodb.IStorage, tidMin, tidMax zodb.Tid, hashOnly boo
return
d
.
Dump
(
stor
,
tidMin
,
tidMax
)
return
d
.
Dump
(
stor
,
tidMin
,
tidMax
)
}
}
// ----------------------------------------
const
dumpSummary
=
"dump content of a ZODB database"
func
dumpUsage
(
w
io
.
Writer
)
{
func
dumpUsage
(
w
io
.
Writer
)
{
fmt
.
Fprintf
(
w
,
fmt
.
Fprintf
(
w
,
`
zodb dump [options
] <storage> [tidmin..tidmax]
`
Usage: zodb dump [OPTIONS
] <storage> [tidmin..tidmax]
Dump content of a ZODB database.
Dump content of a ZODB database.
<storage> is an URL (see 'zodb help zurl') of a ZODB-storage.
<storage> is an URL (see 'zodb help zurl') of a ZODB-storage.
...
@@ -217,7 +220,7 @@ Options:
...
@@ -217,7 +220,7 @@ Options:
`
)
`
)
}
}
func
D
umpMain
(
argv
[]
string
)
{
func
d
umpMain
(
argv
[]
string
)
{
hashOnly
:=
false
hashOnly
:=
false
tidRange
:=
".."
// (0, +inf)
tidRange
:=
".."
// (0, +inf)
...
@@ -226,9 +229,9 @@ func DumpMain(argv []string) {
...
@@ -226,9 +229,9 @@ func DumpMain(argv []string) {
flags
.
BoolVar
(
&
hashOnly
,
"hashonly"
,
hashOnly
,
"dump only hashes of objects"
)
flags
.
BoolVar
(
&
hashOnly
,
"hashonly"
,
hashOnly
,
"dump only hashes of objects"
)
flags
.
Parse
(
argv
)
flags
.
Parse
(
argv
)
argv
:=
flag
.
Args
()
argv
=
flags
.
Args
()
if
len
(
argv
)
<
1
{
if
len
(
argv
)
<
1
{
u
sage
()
flags
.
U
sage
()
os
.
Exit
(
2
)
os
.
Exit
(
2
)
}
}
storUrl
:=
argv
[
0
]
storUrl
:=
argv
[
0
]
...
@@ -243,7 +246,7 @@ func DumpMain(argv []string) {
...
@@ -243,7 +246,7 @@ func DumpMain(argv []string) {
log
.
Fatal
(
err
)
// XXX recheck
log
.
Fatal
(
err
)
// XXX recheck
}
}
stor
,
err
:=
fs1
.
Open
(
storUrl
)
// TODO read-only
stor
,
err
:=
zodb
.
Open
(
storUrl
)
// TODO read-only
if
err
!=
nil
{
if
err
!=
nil
{
log
.
Fatal
(
err
)
log
.
Fatal
(
err
)
}
}
...
...
t/neo/zodb/zodbtools/dump_test.go
View file @
af34e00a
...
@@ -15,7 +15,7 @@
...
@@ -15,7 +15,7 @@
//
//
// See COPYING file for full licensing terms.
// See COPYING file for full licensing terms.
package
main
package
zodbtools
//go:generate sh -c "python2 -m zodbtools.zodb dump ../../../storage/fs1/testdata/1.fs >testdata/1.zdump.pyok"
//go:generate sh -c "python2 -m zodbtools.zodb dump ../../../storage/fs1/testdata/1.fs >testdata/1.zdump.pyok"
...
...
t/neo/zodb/zodbtools/info.go
View file @
af34e00a
...
@@ -19,40 +19,73 @@
...
@@ -19,40 +19,73 @@
package
zodbtools
package
zodbtools
#
{}
parameter_name
->
get_parameter
(
stor
)
import
(
infoDict
=
OrderedDict
([
"flag"
(
"name"
,
lambda
stor
:
stor
.
getName
()),
"fmt"
(
"size"
,
lambda
stor
:
stor
.
getSize
()),
"io"
(
"last_tid"
,
lambda
stor
:
ashex
(
stor
.
lastTransaction
())),
"log"
])
"os"
def
zodbinfo
(
stor
,
parameterv
)
:
"../../zodb"
wantnames
=
False
)
if
not
parameterv
:
parameterv
=
infoDict
.
keys
()
// paramFunc is a function to retrieve 1 storage parameter
wantnames
=
True
type
paramFunc
func
(
stor
zodb
.
IStorage
)
(
string
,
error
)
for
parameter
in
parameterv
:
var
infov
=
[]
struct
{
name
string
;
getParam
paramFunc
}
{
get_parameter
=
infoDict
.
get
(
parameter
)
// XXX e.g. stor.LastTid() should return err itself
if
get_parameter
is
None
:
{
"name"
,
func
(
stor
zodb
.
IStorage
)
(
string
,
error
)
{
return
stor
.
StorageName
(),
nil
}},
print
(
"invalid parameter: %s"
%
parameter
,
file
=
sys
.
stderr
)
// {"size", func(stor zodb.IStorage) (string, error) { return stor.StorageSize(), nil }},
sys
.
exit
(
1
)
{
"last_tid"
,
func
(
stor
zodb
.
IStorage
)
(
string
,
error
)
{
return
stor
.
LastTid
()
.
String
(),
nil
}},
}
out
=
""
if
wantnames
:
// {} parameter_name -> get_parameter(stor)
var
infoDict
map
[
string
]
paramFunc
func
init
()
{
for
_
,
info
:=
range
infov
{
infoDict
[
info
.
name
]
=
info
.
getParam
}
}
// Info prints general information about a ZODB storage
func
Info
(
w
io
.
Writer
,
stor
zodb
.
IStorage
,
parameterv
[]
string
)
error
{
wantnames
:=
false
if
len
(
parameterv
)
==
0
{
for
_
,
info
:=
range
infov
{
parameterv
=
append
(
parameterv
,
info
.
name
)
}
wantnames
=
true
}
for
_
,
parameter
:=
range
parameterv
{
getParam
,
ok
:=
infoDict
[
parameter
]
if
!
ok
{
return
fmt
.
Errorf
(
"invalid parameter: %s"
,
parameter
)
}
out
:=
""
if
wantnames
{
out
+=
parameter
+
"="
out
+=
parameter
+
"="
out
+=
"%s"
%
(
get_parameter
(
stor
),)
}
print
(
out
)
value
,
err
:=
getParam
(
stor
)
if
err
!=
nil
{
return
fmt
.
Errorf
(
"getting %s: %v"
,
parameter
,
err
)
}
out
+=
value
fmt
.
Fprintf
(
w
,
"%s
\n
"
,
out
)
}
return
nil
}
#
----------------------------------------
// ----------------------------------------
import
getopt
s
ummary
=
"print general information about a ZODB database"
const
infoS
ummary
=
"print general information about a ZODB database"
def
usage
(
out
)
:
func
infoUsage
(
w
io
.
Writer
)
{
print
(
"""
\
fmt
.
Fprintf
(
w
,
Usage: zodb info [OPTIONS] <storage> [parameter ...]
`
Usage: zodb info [OPTIONS] <storage> [parameter ...]
Print general information about a ZODB database.
Print general information about a ZODB database.
<storage> is an URL (see 'zodb help zurl') of a ZODB-storage.
<storage> is an URL (see 'zodb help zurl') of a ZODB-storage.
...
@@ -64,27 +97,28 @@ named parameter on its own line.
...
@@ -64,27 +97,28 @@ named parameter on its own line.
Options:
Options:
-h --help show this help
-h --help show this help
"""
,
file
=
out
)
`
)
}
def
main
(
argv
)
:
try
:
func
infoMain
(
argv
[]
string
)
{
optv
,
argv
=
getopt
.
getopt
(
argv
[
1
:
],
"h"
,
[
"help"
])
flags
:=
flag
.
FlagSet
{
Usage
:
func
()
{
infoUsage
(
os
.
Stderr
)
}}
except
getopt
.
GetoptError
as
e
:
flags
.
Init
(
""
,
flag
.
ExitOnError
)
print
(
e
,
file
=
sys
.
stderr
)
flags
.
Parse
(
argv
)
usage
(
sys
.
stderr
)
sys
.
exit
(
2
)
argv
=
flags
.
Args
()
if
len
(
argv
)
<
1
{
for
opt
,
_
in
optv
:
flags
.
Usage
()
if
opt
in
(
"-h"
,
"--help"
)
:
os
.
Exit
(
2
)
usage
(
sys
.
stdout
)
}
sys
.
exit
(
0
)
storUrl
:=
argv
[
0
]
try
:
stor
,
err
:=
zodb
.
Open
(
storUrl
)
// TODO read-only
storurl
=
argv
[
0
]
if
err
!=
nil
{
except
IndexError
:
log
.
Fatal
(
err
)
usage
(
sys
.
stderr
)
}
sys
.
exit
(
2
)
err
=
Info
(
os
.
Stdout
,
stor
,
argv
[
1
:
])
stor
=
storageFromURL
(
storurl
,
read_only
=
True
)
if
err
!=
nil
{
log
.
Fatal
(
err
)
zodbinfo
(
stor
,
argv
[
1
:
])
}
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment