Exemple #1
0
 def factory():
     filestorage = FileStorage(*args, **kw)
     demostorage = DemoStorage(base=filestorage)
     blobstorage = BlobStorage(blobstorage_dir,
                               demostorage,
                               layout=blobstorage_layout)
     return DB(blobstorage, **dbkw)
Exemple #2
0
    def _dump_zodb_to(self, zodbDB, stack):
        """Dump the zodbDB into a data.fs by constructing a FileStorage database
        and copying the transactions from the DemoStorage.
        """
        ori_site_manager_bases = None
        if getSite():
            # The __bases__ of our local persistent component registry is
            # probably a volatile site manager. Pickling it will corrupt the
            # database.
            # Therefore we remember the stack bases and remove the __bases__
            # for the duration of the DB dump.
            ori_site_manager_bases = getSite().getSiteManager().__bases__
            self.data['site_site_manager_bases'][str(stack['path'].name)] = [
                base.__name__ for base in ori_site_manager_bases
            ]
            getSite().getSiteManager().__bases__ = ()

        transaction.commit()  # Make sure we have the latest state.
        # The transaction records in testing have no _extension set, causing
        # a RuntimeError when copied to a filestorage.
        map(lambda record: setattr(record, '_extension', record.extension),
            zodbDB.storage.iterator())

        zodb_file = str(stack['path'].joinpath('zodb.fs'))
        blob_dir = str(stack['path'].joinpath('blobs'))
        cache_storage = FileStorage(zodb_file, create=True, blob_dir=blob_dir)
        copyTransactionsFromTo(zodbDB.storage, cache_storage)

        if ori_site_manager_bases is not None:
            # Restore the __bases__ of the local persistent component registry,
            # which've removed above.
            getSite().getSiteManager().__bases__ = ori_site_manager_bases
            transaction.commit()
def open_db(options):
    if options.db_filename:
        storage = FileStorage(options.db_filename, read_only=options.readonly)
    else:
        storage = ClientStorage(options.zeo_address,
                                storage=options.zeo_storage,
                                read_only=options.readonly)
    return DB(storage)
Exemple #4
0
 def __init__(self, filename, appname, timeout=1200, period=20):
     from ZODB.FileStorage.FileStorage import FileStorage
     from ZODB.DB import DB
     f = FileStorage(filename)
     self.db = DB(f)
     self.appname = appname
     self.timeout = timeout
     self.period = period
Exemple #5
0
 def setUp(self):
     self.tmpdir = tempfile.mkdtemp(prefix='test-zodbbrowser-')
     self.addCleanup(shutil.rmtree, self.tmpdir)
     self.storage = FileStorage(os.path.join(self.tmpdir, 'Data.fs'))
     self.addCleanup(self.storage.close)
     self.db = DB(self.storage)
     self.addCleanup(self.db.close)
     self.conn = self.db.open()
     self.addCleanup(self.conn.close)
Exemple #6
0
 def get_index(self):
     if not os.path.exists(self.dbfn):
         raise NotImplementedError  # XXX create index-creation code
     from ZODB.FileStorage.FileStorage import FileStorage
     from ZODB.DB import DB
     s = FileStorage(self.dbfn)
     db = DB(s, cache_size=300000)
     c = db.open()
     root = c.root()
     return root[self.dbkey]
Exemple #7
0
 def _load_zodb_from(self, stack):
     """Load the ZODB from the FileStorage cache.
     This does not copy the transactions back to the DemoStorage, because
     this will be hard to do because of missing features in the DemoStorage.
     The FileStorage is directly used as base for the later created
     DemoStorage instead.
     """
     zodb_file = str(stack['path'].joinpath('zodb.fs'))
     blob_dir = str(stack['path'].joinpath('blobs'))
     return DB(FileStorage(zodb_file, read_only=True, blob_dir=blob_dir))
Exemple #8
0
    def __init__(self, filename, appname, **kw):
        """ ``filename`` is a filename to the FileStorage storage,
        ``appname`` is a key name in the root of the FileStorage in
        which to store the catalog, and ``**kw`` is passed as extra
        keyword arguments to :class:`ZODB.DB.DB` when creating a
        database.  Note that when we create a :class:`ZODB.DB.DB`
        instance, if a ``cache_size`` is not passed in ``*kw``, we
        override the default ``cache_size`` value with ``50000`` in
        order to provide a more realistic cache size for modern apps"""
        cache_size = kw.get('cache_size')
        if cache_size is None:
            kw['cache_size'] = 50000

        from ZODB.FileStorage.FileStorage import FileStorage
        from ZODB.DB import DB
        f = FileStorage(filename)
        self.db = DB(f, **kw)
        self.appname = appname
 def createTestData(cls):
     storage = FileStorage(cls.data_fs)
     db = DB(storage)
     # Create root folder and all that jazz
     bootStrapSubscriber(DatabaseOpened(db))
     connection = db.open()
     root = connection.root()
     root_folder = root[ZopePublication.root_name]
     transaction.get().note(u"setUp creating root folder")
     transaction.commit()
     # This is not a great way to set up test fixtures, but it'll do
     # for now
     cls.createTestDataForBrowsing(root_folder)
     cls.createTestDataForRollbacking(root_folder)
     cls.createTestDataForRollbackCanBeCancelled(root_folder)
     cls.createTestDataForImplementsOnly(root_folder)
     cls.createTestDataForTruncation(root_folder)
     connection.close()
     db.close()
Exemple #10
0
def main(fspath, key):
    fs = FileStorage(fspath, read_only=1)
    db = ZODB.DB(fs)
    rt = db.open().root()
    index = rt[key]

    lex = index.lexicon
    idx = index.index
    print("Words", lex.length())
    print("Documents", idx.length())

    print("Word frequencies: count, word, wid")
    for word, wid in lex.items():
        docs = idx._wordinfo[wid]
        print(len(docs), word, wid)

    print("Per-doc scores: wid, (doc, score,)+")
    for wid in lex.wids():
        print(wid,)
        docs = idx._wordinfo[wid]
        for docid, score in docs.items():
            print(docid, score,)
        print()
Exemple #11
0
 def factory():
     filestorage = FileStorage(*args, **kw)
     return DB(filestorage, **dbkw)
Exemple #12
0
 def factory():
     filestorage = FileStorage(*args, **kw)
     demostorage = DemoStorage(base=filestorage)
     return DB(demostorage, **dbkw)
Exemple #13
0
 def factory():
     filestorage = FileStorage(*args, **kw)
     blobstorage = BlobStorage(blobstorage_dir, filestorage,
                               layout=blobstorage_layout)
     return DB(blobstorage, **dbkw)
Exemple #14
0
 def factory():
     return FileStorage(*args, **kw)
Exemple #15
0
 def factory():
     filestorage = FileStorage(*args, **kw)
     return DemoStorage(base=filestorage)
Exemple #16
0
def FileStorage28():
    here = os.path.dirname(__file__)
    data_fs = os.path.join(here, "Data28.fs")
    return FileStorage(data_fs)