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
Jérome Perrin
zodbtools
Commits
d955f79a
Commit
d955f79a
authored
Nov 16, 2016
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Factor out utility routines to zodbtool.util
parent
66946b8d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
54 additions
and
51 deletions
+54
-51
zodbtool/util.py
zodbtool/util.py
+53
-0
zodbtool/zodbcmp.py
zodbtool/zodbcmp.py
+1
-51
No files found.
zodbtool/util.py
0 → 100644
View file @
d955f79a
# zodbtool - various utility routines
# Copyright (C) 2016 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com>
def
ashex
(
s
):
return
s
.
encode
(
'hex'
)
# something that is greater than everything else
class
Inf
:
def
__cmp__
(
self
,
other
):
return
+
1
inf
=
Inf
()
# get next item from iter -> (item, !stop)
def
nextitem
(
it
):
try
:
item
=
it
.
next
()
except
StopIteration
:
return
None
,
False
else
:
return
item
,
True
# objects of a IStorageTransactionInformation
def
txnobjv
(
txn
):
objv
=
[]
for
obj
in
txn
:
assert
obj
.
tid
==
txn
.
tid
assert
obj
.
version
==
''
objv
.
append
(
obj
)
objv
.
sort
(
key
=
lambda
obj
:
obj
.
oid
)
# in canonical order
return
objv
# "tidmin..tidmax" -> (tidmin, tidmax)
class
TidRangeInvalid
(
Exception
):
pass
def
parse_tidrange
(
tidrange
):
try
:
tidmin
,
tidmax
=
tidrange
.
split
(
".."
)
except
ValueError
:
# not exactly 2 parts in between ".."
raise
TidRangeInvalid
(
tidrange
)
try
:
tidmin
=
tidmin
.
decode
(
"hex"
)
tidmax
=
tidmax
.
decode
(
"hex"
)
except
TypeError
:
# hex decoding error
raise
TidRangeInvalid
(
tidrange
)
# empty tid means -inf / +inf respectively
# ( which is None in IStorage.iterator() )
return
(
tidmin
or
None
,
tidmax
or
None
)
zodbtool/zodbcmp.py
View file @
d955f79a
...
...
@@ -16,39 +16,9 @@ Exit status is 0 if inputs are the same, 1 if different, 2 if error.
"""
from
__future__
import
print_function
from
zodbtool.util
import
ashex
,
inf
,
nextitem
,
txnobjv
,
parse_tidrange
,
TidRangeInvalid
from
time
import
time
def
ashex
(
s
):
return
s
.
encode
(
'hex'
)
# something that is greater than everything else
class
Inf
:
def
__cmp__
(
self
,
other
):
return
+
1
inf
=
Inf
()
# get next item from iter -> (item, !stop)
def
nextitem
(
it
):
try
:
item
=
it
.
next
()
except
StopIteration
:
return
None
,
False
else
:
return
item
,
True
# objects of a IStorageTransactionInformation
def
txnobjv
(
txn
):
objv
=
[]
for
obj
in
txn
:
assert
obj
.
tid
==
txn
.
tid
assert
obj
.
version
==
''
objv
.
append
(
obj
)
objv
.
sort
(
key
=
lambda
obj
:
obj
.
oid
)
# in canonical order
return
objv
# compare two storage transactions
# 0 - equal, 1 - non-equal
def
txncmp
(
txn1
,
txn2
):
...
...
@@ -146,26 +116,6 @@ Options:
-h --help show this help
"""
,
file
=
out
)
# tidmin..tidmax -> (tidmin, tidmax)
class
TidRangeInvalid
(
Exception
):
pass
def
parse_tidrange
(
tidrange
):
try
:
tidmin
,
tidmax
=
tidrange
.
split
(
".."
)
except
ValueError
:
# not exactly 2 parts in between ".."
raise
TidRangeInvalid
(
tidrange
)
try
:
tidmin
=
tidmin
.
decode
(
"hex"
)
tidmax
=
tidmax
.
decode
(
"hex"
)
except
TypeError
:
# hex decoding error
raise
TidRangeInvalid
(
tidrange
)
# empty tid means -inf / +inf respectively
# ( which is None in IStorage.iterator() )
return
(
tidmin
or
None
,
tidmax
or
None
)
def
main2
():
verbose
=
False
...
...
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