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 @@
"""Zodbpack - Pack a ZODB database"""
from
__future__
import
print_function
from
zodbtools.util
import
storageFromURL
from
zodbtools.util
import
storageFromURL
,
parse_tid
,
ashex
import
ZODB.serialize
from
ZODB.utils
import
u64
from
persistent.TimeStamp
import
TimeStamp
import
sys
import
time
from
golang
import
func
,
defer
import
sys
,
time
from
golang
import
func
,
defer
,
panic
# XXX try to avoid
import
numpy
as
np
# XXX
# XXX +packtime
def
zodbpack
(
stor
,
gc
):
t
=
time
.
time
()
def
zodbpack
(
stor
,
packat
,
gc
):
kw
=
{}
if
gc
is
not
None
:
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
)
...
...
@@ -45,7 +68,7 @@ summary = "pack a ZODB database"
def
usage
(
out
):
print
(
"""
\
Usage: zodb pack [OPTIONS] <storage>
Usage: zodb pack [OPTIONS] <storage>
<packat>
Pack a ZODB database.
<storage> is an URL (see 'zodb help zurl') of a ZODB-storage.
...
...
@@ -63,7 +86,7 @@ def main(argv):
gc
=
False
try
:
optv
,
argv
=
getopt
.
getopt
(
argv
[
1
:],
"h"
,
[
"help"
])
optv
,
argv
=
getopt
.
getopt
(
argv
[
1
:],
"h"
,
[
"
gc"
,
"
help"
])
except
getopt
.
GetoptError
as
e
:
print
(
e
,
file
=
sys
.
stderr
)
usage
(
sys
.
stderr
)
...
...
@@ -76,13 +99,15 @@ def main(argv):
if
opt
in
(
"--gc"
):
gc
=
True
try
:
storurl
=
argv
[
0
]
except
IndexError
:
if
len
(
argv
)
!=
2
:
usage
(
sys
.
stderr
)
sys
.
exit
(
2
)
storurl
=
argv
[
0
]
packat
=
parse_tid
(
argv
[
1
])
print
(
`packat`
)
stor
=
storageFromURL
(
storurl
)
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