Commit c20bc635 authored by Kirill Smelkov's avatar Kirill Smelkov

go/zodb/*: Fix Python database generators to work with ZODB5 + preserve DB compatibility with ZODB3

Paralleling zodbtools@0b6f99da.

All test databases in */testdata/ stay as before bit-to-bit the same.
parent 84845c97
#!/usr/bin/env python2 #!/usr/bin/env python2
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright (C) 2018 Nexedi SA and Contributors. # Copyright (C) 2018-2020 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com> # Kirill Smelkov <kirr@nexedi.com>
# #
# This program is free software: you can Use, Study, Modify and Redistribute # This program is free software: you can Use, Study, Modify and Redistribute
...@@ -23,6 +23,7 @@ ...@@ -23,6 +23,7 @@
from ZODB.DB import DB from ZODB.DB import DB
from BTrees.LOBTree import LOBucket, LOBTree from BTrees.LOBTree import LOBucket, LOBTree
from ZODB.utils import u64 from ZODB.utils import u64
from zodbtools.test.gen_testdata import run_with_zodb3py2_compat
import os, os.path, transaction import os, os.path, transaction
from golang.gcompat import qq from golang.gcompat import qq
...@@ -31,7 +32,7 @@ def rm_f(path): ...@@ -31,7 +32,7 @@ def rm_f(path):
if os.path.exists(path): if os.path.exists(path):
os.remove(path) os.remove(path)
def main(): def main2():
import zodbtools.test.gen_testdata # to make time predictable (XXX) import zodbtools.test.gen_testdata # to make time predictable (XXX)
outfs = "testdata/1.fs" outfs = "testdata/1.fs"
...@@ -87,6 +88,9 @@ def main(): ...@@ -87,6 +88,9 @@ def main():
conn.close() conn.close()
db.close() db.close()
def main():
run_with_zodb3py2_compat(main2)
if __name__ == '__main__': if __name__ == '__main__':
main() main()
#!/usr/bin/env python2 #!/usr/bin/env python2
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright (C) 2017-2018 Nexedi SA and Contributors. # Copyright (C) 2017-2020 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com> # Kirill Smelkov <kirr@nexedi.com>
# #
# This program is free software: you can Use, Study, Modify and Redistribute # This program is free software: you can Use, Study, Modify and Redistribute
...@@ -20,11 +20,14 @@ ...@@ -20,11 +20,14 @@
# See https://www.nexedi.com/licensing for rationale and options. # See https://www.nexedi.com/licensing for rationale and options.
"""generate reference pickle objects encoding for tests""" """generate reference pickle objects encoding for tests"""
from ZODB.tests import testSerialize
from ZODB import serialize from ZODB import serialize
from zodbtools.test.gen_testdata import run_with_zodb3py2_compat
from golang.gcompat import qq from golang.gcompat import qq
def main(): def main2():
# import ZODB.tests at runtime after ZODB.X._protocol is patched
from ZODB.tests import testSerialize
# dump to go what to expect # dump to go what to expect
with open("ztestdata_pydata_test.go", "w") as f: with open("ztestdata_pydata_test.go", "w") as f:
def emit(v): def emit(v):
...@@ -52,5 +55,8 @@ def main(): ...@@ -52,5 +55,8 @@ def main():
emit('\t{"aaa", "?.?"},') # invalid emit('\t{"aaa", "?.?"},') # invalid
emit("}") emit("}")
def main():
run_with_zodb3py2_compat(main2)
if __name__ == '__main__': if __name__ == '__main__':
main() main()
#!/usr/bin/env python2 #!/usr/bin/env python2
# -*- coding: utf-8 -*- # -*- coding: utf-8 -*-
# Copyright (C) 2017-2019 Nexedi SA and Contributors. # Copyright (C) 2017-2020 Nexedi SA and Contributors.
# Kirill Smelkov <kirr@nexedi.com> # Kirill Smelkov <kirr@nexedi.com>
# #
# This program is free software: you can Use, Study, Modify and Redistribute # This program is free software: you can Use, Study, Modify and Redistribute
...@@ -22,7 +22,8 @@ ...@@ -22,7 +22,8 @@
from ZODB.FileStorage import FileStorage from ZODB.FileStorage import FileStorage
from ZODB import DB from ZODB import DB
from zodbtools.test.gen_testdata import gen_testdb, precommit from ZODB.Connection import TransactionMetaData
from zodbtools.test.gen_testdata import gen_testdb, precommit, run_with_zodb3py2_compat
from os import stat, remove from os import stat, remove
from shutil import copyfile from shutil import copyfile
from golang.gcompat import qq from golang.gcompat import qq
...@@ -142,6 +143,7 @@ def main(): ...@@ -142,6 +143,7 @@ def main():
# prepare file with voted (not fully committed) tail # prepare file with voted (not fully committed) tail
voted = "testdata/1voted.fs" voted = "testdata/1voted.fs"
copyfile(outfs, voted) copyfile(outfs, voted)
def _():
vstor = FileStorage(voted) vstor = FileStorage(voted)
vdb = DB(vstor) vdb = DB(vstor)
vconn = vdb.open() vconn = vdb.open()
...@@ -149,10 +151,12 @@ def main(): ...@@ -149,10 +151,12 @@ def main():
vroot._p_activate() # to know its current serial vroot._p_activate() # to know its current serial
txn = precommit(u"author", u"description", {'aaa': 'bbb'}) txn = precommit(u"author", u"description", {'aaa': 'bbb'})
vstor.tpc_begin(txn) txn_stormeta = TransactionMetaData(txn.user, txn.description, txn.extension)
vstor.store(vroot._p_oid, vroot._p_serial, '000 data 000', '', txn) vstor.tpc_begin(txn_stormeta)
vstor.tpc_vote(txn) vstor.store(vroot._p_oid, vroot._p_serial, '000 data 000', '', txn_stormeta)
vstor.tpc_vote(txn_stormeta)
# NO tpc_finish here so that status remain 'c' (voted) instead of ' ' (committed) # NO tpc_finish here so that status remain 'c' (voted) instead of ' ' (committed)
run_with_zodb3py2_compat(_)
st = stat(outfs) st = stat(outfs)
l = st.st_size l = st.st_size
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment