Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Z
zodbtools
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
zodbtools
Commits
735ab157
Commit
735ab157
authored
Jul 24, 2020
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
e9a36412
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
13 deletions
+38
-13
zodbtools/zodbpack.py
zodbtools/zodbpack.py
+38
-13
No files found.
zodbtools/zodbpack.py
View file @
735ab157
...
@@ -20,21 +20,44 @@
...
@@ -20,21 +20,44 @@
"""Zodbpack - Pack a ZODB database"""
"""Zodbpack - Pack a ZODB database"""
from
__future__
import
print_function
from
__future__
import
print_function
from
zodbtools.util
import
storageFromURL
from
zodbtools.util
import
storageFromURL
,
parse_tid
,
ashex
import
ZODB.serialize
import
ZODB.serialize
from
ZODB.utils
import
u64
from
persistent.TimeStamp
import
TimeStamp
import
sys
import
sys
,
time
import
time
from
golang
import
func
,
defer
,
panic
from
golang
import
func
,
defer
# XXX try to avoid
import
numpy
as
np
# XXX
# XXX
# XXX +packtime
def
zodbpack
(
stor
,
packat
,
gc
):
def
zodbpack
(
stor
,
gc
):
t
=
time
.
time
()
kw
=
{}
kw
=
{}
if
gc
is
not
None
:
if
gc
is
not
None
:
kw
[
'gc'
]
=
gc
kw
[
'gc'
]
=
gc
# packat(tid) -> t(float) (IStorage.pack requres float packtime)
# the conversion is not exact due to potential rounding.
# we are ok to go a bit before, but not after - so that if packat specifies
# transaction exactly, this transaction is not pruned and stays in [packat range.
t
=
TimeStamp
(
packat
).
timeTime
()
while
1
:
packat_
=
TimeStamp
(
*
time
.
gmtime
(
t
)[:
5
]
+
(
t
%
60
,)).
raw
()
d
=
u64
(
packat_
)
-
u64
(
packat
)
if
abs
(
d
)
>
1E2
:
panic
(
"too much divergence due to rounding:"
"
\
n
packat: %s
\
n
packat_: %s
\
n
δ: %d"
%
(
ashex
(
packat
),
ashex
(
packat_
),
d
))
print
(
"
\
n
packat: %s
\
n
packat_: %s
\
n
δ: %d"
%
(
ashex
(
packat
),
ashex
(
packat_
),
d
))
if
d
<=
0
:
break
t
=
np
.
nextafter
(
t
,
-
np
.
inf
)
stor
.
pack
(
t
,
ZODB
.
serialize
.
referencesf
,
**
kw
)
stor
.
pack
(
t
,
ZODB
.
serialize
.
referencesf
,
**
kw
)
...
@@ -45,7 +68,7 @@ summary = "pack a ZODB database"
...
@@ -45,7 +68,7 @@ summary = "pack a ZODB database"
def
usage
(
out
):
def
usage
(
out
):
print
(
"""
\
print
(
"""
\
Usage: zodb pack [OPTIONS] <storage>
Usage: zodb pack [OPTIONS] <storage>
<packat>
Pack a ZODB database.
Pack 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.
...
@@ -63,7 +86,7 @@ def main(argv):
...
@@ -63,7 +86,7 @@ def main(argv):
gc
=
False
gc
=
False
try
:
try
:
optv
,
argv
=
getopt
.
getopt
(
argv
[
1
:],
"h"
,
[
"help"
])
optv
,
argv
=
getopt
.
getopt
(
argv
[
1
:],
"h"
,
[
"
gc"
,
"
help"
])
except
getopt
.
GetoptError
as
e
:
except
getopt
.
GetoptError
as
e
:
print
(
e
,
file
=
sys
.
stderr
)
print
(
e
,
file
=
sys
.
stderr
)
usage
(
sys
.
stderr
)
usage
(
sys
.
stderr
)
...
@@ -76,13 +99,15 @@ def main(argv):
...
@@ -76,13 +99,15 @@ def main(argv):
if
opt
in
(
"--gc"
):
if
opt
in
(
"--gc"
):
gc
=
True
gc
=
True
try
:
if
len
(
argv
)
!=
2
:
storurl
=
argv
[
0
]
except
IndexError
:
usage
(
sys
.
stderr
)
usage
(
sys
.
stderr
)
sys
.
exit
(
2
)
sys
.
exit
(
2
)
storurl
=
argv
[
0
]
packat
=
parse_tid
(
argv
[
1
])
print
(
`packat`
)
stor
=
storageFromURL
(
storurl
)
stor
=
storageFromURL
(
storurl
)
defer
(
stor
.
close
)
defer
(
stor
.
close
)
zodbpack
(
stor
,
gc
)
zodbpack
(
stor
,
packat
,
gc
)
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