Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
W
wendelin.core
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
Kirill Smelkov
wendelin.core
Commits
6772a539
Commit
6772a539
authored
May 25, 2020
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
a34ab52c
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
24 additions
and
39 deletions
+24
-39
wcfs/testprog/treegen.py
wcfs/testprog/treegen.py
+24
-39
No files found.
wcfs/testprog/treegen.py
View file @
6772a539
...
...
@@ -100,16 +100,21 @@ from BTrees import LOBTree
LOBTree
.
LOBTree
=
XLOTree
# ZConn represent treegen-level connection to ZODB.
# XXX high-level wrapper around zconn.
class
ZConn
(
object
):
# XXX +.zstor
# ZCtx represent treegen-level connection to ZODB.
# It wraps zconn + provides treegen-specif integration.
class
ZCtx
(
object
):
# .zconn
# .root
# .valdict = zconn.root['treegen/values'] = {} v -> ZBlk(v)
# XXX -> free function? (e.g. zopen(zstor)) ?
def
__init__
(
zstor
):
# ZCtx(zstor) opens connection to zstor.
def
__init__
(
zctx
,
zstor
):
zctx
.
db
=
DB
(
zstor
)
zctx
.
zconn
=
zctx
.
db
.
open
()
zctx
.
root
=
zctx
.
zconn
.
root
()
# root['treegen/values'] = {} v -> ZBlk(v)
# TODO don't generate if already there
valdict
=
root
[
'treegen/values'
]
=
PersistentMapping
()
valv
=
b'abcdefghi'
for
v
in
valv
:
...
...
@@ -118,15 +123,16 @@ class ZConn(object):
valdict
[
v
]
=
zblk
commit
(
'treegen/values -> %r'
%
valv
)
def
close
(
self
):
self
.
zconn
.
close
()
def
close
(
zctx
):
zctx
.
zconn
.
close
()
zctx
.
db
.
close
()
# vdecode(vtxt) -> vobj decodes value text into value object, e.g. 'a' -> ZBlk(a)
# vencode(vobj) -> vtxt encodes value object into value text, e.g. ZBlk(a) -> 'a'
def
vdecode
(
self
,
vtxt
):
# -> vobj
return
self
.
valdict
[
vtxt
]
def
vencode
(
self
,
vobj
):
# -> vtxt
for
(
k
,
v
)
in
self
.
valdict
.
items
():
def
vdecode
(
zctx
,
vtxt
):
# -> vobj
return
zctx
.
valdict
[
vtxt
]
def
vencode
(
zctx
,
vobj
):
# -> vtxt
for
(
k
,
v
)
in
zctx
.
valdict
.
items
():
if
v
is
vobj
:
return
k
raise
KeyError
(
"%r not found in value registry"
%
(
vobj
,))
...
...
@@ -135,15 +141,15 @@ class ZConn(object):
@
func
def
Trees
(
zstor
,
r
):
for
l
in
r
.
readlines
():
1
/
0
# AllStructs generates subset of all possible tree changes in
# between kv1 and kv2. See top-level documentation for details.
@
func
def
AllStructs
(
zstor
,
kv1txt
,
kv2txt
,
n
,
seed
=
None
):
db
=
DB
(
zstor
);
defer
(
db
.
close
)
zconn
=
db
.
open
();
defer
(
zconn
.
close
)
root
=
zconn
.
root
()
zctx
=
ZCtx
(
zstor
)
defer
(
zctx
.
close
)
# seed
if
seed
is
None
:
...
...
@@ -151,29 +157,8 @@ def AllStructs(zstor, kv1txt, kv2txt, n, seed=None):
print
(
"# seed=%d"
%
seed
)
random
.
seed
(
seed
)
"""
# root['treegen/values'] = {} v -> ZBlk(v)
valdict = root['treegen/values'] = PersistentMapping()
valv = b'abcdefghi'
for v in valv:
zblk = ZBlk()
zblk.setblkdata(v)
valdict[v] = zblk
commit('treegen/values -> %r' % valv)
# vdecode(vtxt) -> vobj decodes value text into value object, e.g. 'a' -> ZBlk(a)
# vencode(vobj) -> vtxt encodes value object into value text, e.g. ZBlk(a) -> 'a'
def vdecode(vtxt): # -> vobj
return valdict[vtxt]
def vencode(vobj): # -> vtxt
for (k,v) in valdict.items():
if v is vobj:
return k
raise KeyError("%r not found in value registry" % (vobj,))
"""
kv1
=
kvDecode
(
kv1txt
,
vdecode
)
kv2
=
kvDecode
(
kv2txt
,
vdecode
)
kv1
=
kvDecode
(
kv1txt
,
zctx
.
vdecode
)
kv2
=
kvDecode
(
kv2txt
,
zctx
.
vdecode
)
# δ kv1 <-> kv2
diff12
=
diff
(
kv1
,
kv2
)
...
...
@@ -186,7 +171,7 @@ def AllStructs(zstor, kv1txt, kv2txt, n, seed=None):
t2AllStructs
=
list
(
xbtree
.
AllStructs
(
kv2
.
keys
(),
maxdepth
,
maxsplit
))
# create the tree
ztree
=
root
[
'treegen/tree'
]
=
XLOTree
()
ztree
=
zctx
.
root
[
'treegen/tree'
]
=
XLOTree
()
commit
(
'treegen/tree'
)
# XXX print something?
...
...
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