#/usr/bin/python

from ZODB import FileStorage, DB
from BTrees import OOBTree
from persistent import Persistent
from persistent.mapping import PersistentMapping as ZM
from persistent.list import PersistentList as ZL
import transaction

"""
TODO:
A multi-threaded program should open a separate Connection instance for each thread. Different threads can then modify objects and commit their modifications independently.
"""

db = None
zdbroot = None
conn = None

def set_db(filename):
    global db, zdbroot, conn

    storage = FileStorage.FileStorage(filename)
    db = DB(storage)
    conn = db.open()
    zdbroot = conn.root()

def get_section(section_key, tp=None):
    if zdbroot.has_key(section_key):
        section = zdbroot[section_key]
    else:
        if tp is None:
            tp = OOBTree.OOBTree
        section = zdbroot[section_key] = tp()
    return section

def sync():
    transaction.commit()

def abort():
    transaction.abort()

def delete_all_dangerous():
    """ Only use this for test code!!!"""
    zdbroot.clear()



@@ -227,16 +227,38 @@
 nsaction
+%0Aimport zc.zlibstorage
 %0A%0A%22%22%22%0ATO
@@ -542,16 +542,68 @@
 torage =
+ zc.zlibstorage.ZlibStorage(%0A                       
  FileSto
@@ -628,16 +628,17 @@
 ilename)
+)
 %0A    db 

Use compressed file storage