Ejemplo n.º 1
0
def zodb_test():
    db = DB(FileStorage.FileStorage('Data.fs')).open()

    # Via http://www.ibm.com/developerworks/aix/library/au-zodb/
    dbroot = db.root()
    dbroot['a_number'] = 3
    dbroot['a_string'] = 'Gift'
    dbroot['a_list'] = [1, 2, 3, 5, 7, 12]
    dbroot['a_dictionary'] = { 1918: 'Red Sox', 1919: 'Reds' }
    dbroot['deeply_nested'] = {
      1918: [ ('Red Sox', 4), ('Cubs', 2) ],
      1919: [ ('Reds', 5), ('White Sox', 3) ],
      }
    transaction.commit()
    db.close()
Ejemplo n.º 2
0
def connect(server=None, zodb=None):
    global conn
    close()  # close any existing connection
    if zodb:
        conn = DB(FileStorage(os.path.expanduser(zodb))).open()
    else:
        if not server:
            server = cluster.ZEOSERVER
        s = server
        p = 12345
        if ':' in server:
            s, p = server.split(':')
            p = int(p)
        MB = 1024**2
        storage = ClientStorage((s, p), cache_size=16 * MB)
        db = DB(storage)
        conn = db.open()
    root = conn.root()
    return root
Ejemplo n.º 3
0
def bad(z):
    r = z[-4:]
    try:
        c = DB(FileStorage(z)).open()
        root = c.root()
        if root.has_key(r):
            e = 0
            debug('good %s', z)
        else:
            e = 1
            debug('bad %s (key %s missing)', z, r)
        c.close()
        c.db().close()
    except IOError:
        debug('good %s (busy)', z)
        e = 0
    except Exception:
        debug('bad zodb %s (corrupt)', z)
        e = 1
    return e
Ejemplo n.º 4
0
#!/usr/bin/python

import os, sys, re, copy, logging, traceback
from ZODB.FileStorage import FileStorage
from ZODB import DB
from logging import debug, error

logging.getLogger().setLevel(logging.DEBUG)
logging.getLogger('ZODB').setLevel(logging.INFO)
D = os.path.expanduser('~/done/')

l = os.listdir(D)
dbs = [(x, D + x) for x in l if re.match(r'[pb]\d\d\d$', x)]
dbs.sort()
for (r, f) in dbs:
    try:
        c = DB(FileStorage(f)).open()
        root = c.root()
        assert len(root[r].scores) == root[r].final_gen_num + 1
        if '-d' in sys.argv:
            copy.deepcopy(root[r])
        c.close()
        c.db().close()
        debug('%s OK', r)
    except Exception, e:
        error('%s FAIL\n%s', r, traceback.format_exc())