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
Hide 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 @@
package
main
import
(
"../../zodbtools"
)
...
...
@@ -41,6 +42,10 @@ Usage:
The commands are:
`
)
// TODO print commands
for
_
,
cmd
:=
range
zodbtools
.
AllCommands
()
{
fmt
.
Fprintf
(
w
,
"
\t
%s
\t
%s
\n
"
,
cmd
.
Name
,
cmd
.
Summary
)
}
fmt
.
Fprintf
(
w
,
`
...
...
t/neo/zodb/zodb.go
View file @
af34e00a
...
...
@@ -158,3 +158,11 @@ type IStorageRecordIterator interface { // XXX naming -> IRecordIterator
// end of iteration is indicated with io.EOF
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 (
"lab.nexedi.com/kirr/go123/xfmt"
"../../zodb"
"../../storage/fs1"
//
"../../storage/fs1"
)
...
...
@@ -202,10 +202,13 @@ func Dump(w io.Writer, stor zodb.IStorage, tidMin, tidMax zodb.Tid, hashOnly boo
return
d
.
Dump
(
stor
,
tidMin
,
tidMax
)
}
// ----------------------------------------
const
dumpSummary
=
"dump content of a ZODB database"
func
dumpUsage
(
w
io
.
Writer
)
{
fmt
.
Fprintf
(
w
,
`
zodb dump [options
] <storage> [tidmin..tidmax]
`
Usage: zodb dump [OPTIONS
] <storage> [tidmin..tidmax]
Dump content of a ZODB database.
<storage> is an URL (see 'zodb help zurl') of a ZODB-storage.
...
...
@@ -217,7 +220,7 @@ Options:
`
)
}
func
D
umpMain
(
argv
[]
string
)
{
func
d
umpMain
(
argv
[]
string
)
{
hashOnly
:=
false
tidRange
:=
".."
// (0, +inf)
...
...
@@ -226,9 +229,9 @@ func DumpMain(argv []string) {
flags
.
BoolVar
(
&
hashOnly
,
"hashonly"
,
hashOnly
,
"dump only hashes of objects"
)
flags
.
Parse
(
argv
)
argv
:=
flag
.
Args
()
argv
=
flags
.
Args
()
if
len
(
argv
)
<
1
{
u
sage
()
flags
.
U
sage
()
os
.
Exit
(
2
)
}
storUrl
:=
argv
[
0
]
...
...
@@ -243,7 +246,7 @@ func DumpMain(argv []string) {
log
.
Fatal
(
err
)
// XXX recheck
}
stor
,
err
:=
fs1
.
Open
(
storUrl
)
// TODO read-only
stor
,
err
:=
zodb
.
Open
(
storUrl
)
// TODO read-only
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
...
...
t/neo/zodb/zodbtools/dump_test.go
View file @
af34e00a
...
...
@@ -15,7 +15,7 @@
//
// 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"
...
...
t/neo/zodb/zodbtools/info.go
View file @
af34e00a
...
...
@@ -19,40 +19,73 @@
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 ...]
import
(
"flag"
"fmt"
"io"
"log"
"os"
"../../zodb"
)
// paramFunc is a function to retrieve 1 storage parameter
type
paramFunc
func
(
stor
zodb
.
IStorage
)
(
string
,
error
)
var
infov
=
[]
struct
{
name
string
;
getParam
paramFunc
}
{
// XXX e.g. stor.LastTid() should return err itself
{
"name"
,
func
(
stor
zodb
.
IStorage
)
(
string
,
error
)
{
return
stor
.
StorageName
(),
nil
}},
// {"size", func(stor zodb.IStorage) (string, error) { return stor.StorageSize(), nil }},
{
"last_tid"
,
func
(
stor
zodb
.
IStorage
)
(
string
,
error
)
{
return
stor
.
LastTid
()
.
String
(),
nil
}},
}
// {} 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
+
"="
}
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
}
// ----------------------------------------
const
infoSummary
=
"print general information about a ZODB database"
func
infoUsage
(
w
io
.
Writer
)
{
fmt
.
Fprintf
(
w
,
`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.
...
...
@@ -64,27 +97,28 @@ 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
:
])
`
)
}
func
infoMain
(
argv
[]
string
)
{
flags
:=
flag
.
FlagSet
{
Usage
:
func
()
{
infoUsage
(
os
.
Stderr
)
}}
flags
.
Init
(
""
,
flag
.
ExitOnError
)
flags
.
Parse
(
argv
)
argv
=
flags
.
Args
()
if
len
(
argv
)
<
1
{
flags
.
Usage
()
os
.
Exit
(
2
)
}
storUrl
:=
argv
[
0
]
stor
,
err
:=
zodb
.
Open
(
storUrl
)
// TODO read-only
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
err
=
Info
(
os
.
Stdout
,
stor
,
argv
[
1
:
])
if
err
!=
nil
{
log
.
Fatal
(
err
)
}
}
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