Skip to content

Commit

Permalink
Rename 'ZODB.FileStorage.FileStorage' as 'ZODB.filestorage._impl'.
Browse files Browse the repository at this point in the history
The expected API to get to the 'FileStorage' class is now::

  import ZODB.filestorage # and use FileStorage attr

or::

  from ZODB.filestorage import FileStorage

BBB aliases exist to support code which imported the 'FileStorage' class
via 'ZODB.FileStorage'  or 'ZODB.FileStorage.FileStorage'.
  • Loading branch information
tseaver committed Jan 18, 2013
1 parent 2e1a758 commit dd5cc53
Show file tree
Hide file tree
Showing 41 changed files with 166 additions and 127 deletions.
16 changes: 16 additions & 0 deletions CHANGES.rst
Expand Up @@ -5,9 +5,25 @@
Unreleased
==========

- Renamed the hard-to-grab module, ``ZODB.FileStorage.FileStorage`` as
``ZODB.filestorage._impl``. The expected API to get to the ``FileStorage``
class is now::

import ZODB.filestorage # and use FileStorage attr

or::

from ZODB.filestorage import FileStorage
BBB aliases exist to support code which imported the ``FileStorage`` class
via ``ZODB.FileStorage`` or ``ZODB.FileStorage.FileStorage``.

- Renamed the hard-to-grab module, ``ZODB.DB`` as ``ZODB.db``.
``ZODB.DB`` is now unambigously the ``DB`` class, imported as a convenience
api from the no-longer-shadowed ``ZODB.db``.

A BBB aliases exist to support code which imported the ``DB`` class or
the ``connection`` function via ``ZODB.DB``.

- Tests are now runnable via ``python setup.py test`` and via ``nose``.

Expand Down
2 changes: 1 addition & 1 deletion src/ZODB/DemoStorage.test
Expand Up @@ -19,7 +19,7 @@ existing, base, storage without updating the storage.
To see how this works, we'll start by creating a base storage and
puting an object (in addition to the root object) in it:

>>> from ZODB.FileStorage import FileStorage
>>> from ZODB.filestorage import FileStorage
>>> base = FileStorage('base.fs')
>>> from ZODB.DB import DB
>>> db = DB(base)
Expand Down
8 changes: 0 additions & 8 deletions src/ZODB/FileStorage/__init__.py

This file was deleted.

4 changes: 2 additions & 2 deletions src/ZODB/collaborations.txt
Expand Up @@ -12,7 +12,7 @@ Participants

- ``DB``: ``ZODB.db.DB``
- ``C``: ``ZODB.Connection.Connection``
- ``S``: ``ZODB.FileStorage.FileStorage``
- ``S``: ``ZODB.filestorage.FileStorage``
- ``T``: ``transaction.interfaces.ITransaction``
- ``TM``: ``transaction.interfaces.ITransactionManager``
- ``o1``, ``o2``, ...: pre-existing persistent objects
Expand Down Expand Up @@ -71,7 +71,7 @@ Participants

- ``DB``: ``ZODB.db.DB``
- ``C``: ``ZODB.Connection.Connection``
- ``S``: ``ZODB.FileStorage.FileStorage``
- ``S``: ``ZODB.filestorage.FileStorage``
- ``T``: ``transaction.interfaces.ITransaction``
- ``TM``: ``transaction.interfaces.ITransactionManager``
- ``o1``, ``o2``, ...: pre-existing persistent objects
Expand Down
2 changes: 1 addition & 1 deletion src/ZODB/config.py
Expand Up @@ -155,7 +155,7 @@ def open(self):
class FileStorage(BaseConfig):

def open(self):
from ZODB.FileStorage.FileStorage import FileStorage
from ZODB.filestorage import FileStorage
config = self.config
options = {}
if getattr(config, 'packer', None):
Expand Down
2 changes: 1 addition & 1 deletion src/ZODB/db.py
Expand Up @@ -399,7 +399,7 @@ def __init__(self, storage,
references are allowed
"""
if isinstance(storage, basestring):
from ZODB.FileStorage.FileStorage import FileStorage
from ZODB.filestorage import FileStorage
storage = FileStorage(storage, **storage_args)
elif storage is None:
from ZODB.MappingStorage import MappingStorage
Expand Down
18 changes: 18 additions & 0 deletions src/ZODB/filestorage/__init__.py
@@ -0,0 +1,18 @@
# this is a package

from ._impl import FileStorage
from ._impl import TransactionRecord
from ._impl import FileIterator
from ._impl import Record
from ._impl import packed_version


# BBB Alias for compatibility
RecordIterator = TransactionRecord


# More BBB in sys.modules
from sys import modules
modules['ZODB.FileStorage'] = modules['ZODB.filestorage']
modules['ZODB.FileStorage.FileStorage'] = modules['ZODB.filestorage._impl']
del modules
Expand Up @@ -20,11 +20,11 @@
from persistent.TimeStamp import TimeStamp
from struct import pack, unpack
from zc.lockfile import LockFile
from ZODB.FileStorage.format import CorruptedError, CorruptedDataError
from ZODB.FileStorage.format import FileStorageFormatter, DataHeader
from ZODB.FileStorage.format import TRANS_HDR, TRANS_HDR_LEN
from ZODB.FileStorage.format import TxnHeader, DATA_HDR, DATA_HDR_LEN
from ZODB.FileStorage.fspack import FileStoragePacker
from ZODB.filestorage.format import CorruptedError, CorruptedDataError
from ZODB.filestorage.format import FileStorageFormatter, DataHeader
from ZODB.filestorage.format import TRANS_HDR, TRANS_HDR_LEN
from ZODB.filestorage.format import TxnHeader, DATA_HDR, DATA_HDR_LEN
from ZODB.filestorage.fspack import FileStoragePacker
from ZODB.fsIndex import fsIndex
from ZODB import BaseStorage, ConflictResolution, POSException
from ZODB.POSException import UndoError, POSKeyError, MultipleUndoErrors
Expand All @@ -47,7 +47,7 @@

packed_version = "FS21"

logger = logging.getLogger('ZODB.FileStorage')
logger = logging.getLogger('ZODB.filestorage')

def panic(message, *data):
logger.critical(message, *data)
Expand Down
Expand Up @@ -119,7 +119,7 @@ def __str__(self):
assert struct.calcsize(TRANS_HDR) == TRANS_HDR_LEN
assert struct.calcsize(DATA_HDR) == DATA_HDR_LEN

logger = logging.getLogger('ZODB.FileStorage.format')
logger = logging.getLogger('ZODB.filestorage.format')

class FileStorageFormatter(object):
"""Mixin class that can read and write the low-level format."""
Expand Down
Expand Up @@ -13,9 +13,9 @@
##############################################################################
import struct

from ZODB.FileStorage import FileIterator
from ZODB.FileStorage.format import TRANS_HDR, TRANS_HDR_LEN
from ZODB.FileStorage.format import DATA_HDR, DATA_HDR_LEN
from ZODB.filestorage import FileIterator
from ZODB.filestorage.format import TRANS_HDR, TRANS_HDR_LEN
from ZODB.filestorage.format import DATA_HDR, DATA_HDR_LEN
from ZODB.TimeStamp import TimeStamp
from ZODB.utils import u64, get_pickle_metadata

Expand Down
Expand Up @@ -12,7 +12,7 @@
#
##############################################################################

import ZODB.FileStorage
from ZODB.filestorage import FileIterator
from ZODB.utils import get_pickle_metadata, p64, oid_repr, tid_repr
from ZODB.serialize import get_refs
from ZODB.TimeStamp import TimeStamp
Expand Down Expand Up @@ -127,7 +127,7 @@ def run(self):

# Maps oid of a reference to its module.class name.
self._ref2name = {}
for txn in ZODB.FileStorage.FileIterator(self.path):
for txn in FileIterator(self.path):
self._check_trec(txn)

# Process next transaction record.
Expand Down
Expand Up @@ -24,8 +24,8 @@
a backpointer after that time.
"""

from ZODB.FileStorage.format import DataHeader, TRANS_HDR_LEN
from ZODB.FileStorage.format import FileStorageFormatter, CorruptedDataError
from ZODB.filestorage.format import DataHeader, TRANS_HDR_LEN
from ZODB.filestorage.format import FileStorageFormatter, CorruptedDataError
from ZODB.utils import p64, u64, z64

import logging
Expand Down Expand Up @@ -247,7 +247,7 @@ def buildPackIndex(self):
if th.status == 'p':
# Delayed import to cope with circular imports.
# TODO: put exceptions in a separate module.
from ZODB.FileStorage.FileStorage import RedundantPackWarning
from ZODB.filestorage import RedundantPackWarning
raise RedundantPackWarning(
"The database has already been packed to a later time"
" or no changes have been made since the last pack")
Expand Down
File renamed without changes.
Expand Up @@ -17,7 +17,7 @@ We'll make some assertions about time, so we'll take it over:

Commit a bunch of transactions:

>>> import ZODB.FileStorage, transaction
>>> import ZODB.filestorage, transaction
>>> db = ZODB.DB('data.fs')
>>> tids = [db.storage.lastTransaction()]
>>> poss = [db.storage._pos]
Expand All @@ -33,7 +33,7 @@ Deciding where to start

By default, we start at the beginning:

>>> it = ZODB.FileStorage.FileIterator('data.fs')
>>> it = ZODB.filestorage.FileIterator('data.fs')
>>> it.next().tid == tids[0]
True

Expand All @@ -51,60 +51,60 @@ logging:
If we specify a start transaction, we'll scan forward or backward, as
seems best and set the next record to that:

>>> it = ZODB.FileStorage.FileIterator('data.fs', tids[0])
>>> it = ZODB.filestorage.FileIterator('data.fs', tids[0])
>>> it.next().tid == tids[0]
True

>>> it = ZODB.FileStorage.FileIterator('data.fs', tids[1])
>>> it = ZODB.filestorage.FileIterator('data.fs', tids[1])
Scan forward data.fs:4 looking for '\x03z\xbd\xd8\xd06\x9c\xcc'
>>> it.next().tid == tids[1]
True

>>> it = ZODB.FileStorage.FileIterator('data.fs', tids[30])
>>> it = ZODB.filestorage.FileIterator('data.fs', tids[30])
Scan forward data.fs:4 looking for '\x03z\xbd\xd8\xdc\x96.\xcc'
>>> it.next().tid == tids[30]
True

>>> it = ZODB.FileStorage.FileIterator('data.fs', tids[70])
>>> it = ZODB.filestorage.FileIterator('data.fs', tids[70])
Scan backward data.fs:117080 looking for '\x03z\xbd\xd8\xed\xa7>\xcc'
>>> it.next().tid == tids[70]
True

>>> it = ZODB.FileStorage.FileIterator('data.fs', tids[-2])
>>> it = ZODB.filestorage.FileIterator('data.fs', tids[-2])
Scan backward data.fs:117080 looking for '\x03z\xbd\xd8\xfa\x06\xd0\xcc'
>>> it.next().tid == tids[-2]
True

>>> it = ZODB.FileStorage.FileIterator('data.fs', tids[-1])
>>> it = ZODB.filestorage.FileIterator('data.fs', tids[-1])
>>> it.next().tid == tids[-1]
True

We can also supply a file position. This can speed up finding the
starting point, or just pick up where another iterator left off:

>>> it = ZODB.FileStorage.FileIterator('data.fs', pos=poss[50])
>>> it = ZODB.filestorage.FileIterator('data.fs', pos=poss[50])
>>> it.next().tid == tids[51]
True

>>> it = ZODB.FileStorage.FileIterator('data.fs', tids[0], pos=4)
>>> it = ZODB.filestorage.FileIterator('data.fs', tids[0], pos=4)
>>> it.next().tid == tids[0]
True

>>> it = ZODB.FileStorage.FileIterator('data.fs', tids[-1], pos=poss[-2])
>>> it = ZODB.filestorage.FileIterator('data.fs', tids[-1], pos=poss[-2])
>>> it.next().tid == tids[-1]
True

>>> it = ZODB.FileStorage.FileIterator('data.fs', tids[50], pos=poss[50])
>>> it = ZODB.filestorage.FileIterator('data.fs', tids[50], pos=poss[50])
Scan backward data.fs:35936 looking for '\x03z\xbd\xd8\xe5\x1e\xb6\xcc'
>>> it.next().tid == tids[50]
True

>>> it = ZODB.FileStorage.FileIterator('data.fs', tids[49], pos=poss[50])
>>> it = ZODB.filestorage.FileIterator('data.fs', tids[49], pos=poss[50])
Scan backward data.fs:35936 looking for '\x03z\xbd\xd8\xe4\xb1|\xcc'
>>> it.next().tid == tids[49]
True

>>> it = ZODB.FileStorage.FileIterator('data.fs', tids[51], pos=poss[50])
>>> it = ZODB.filestorage.FileIterator('data.fs', tids[51], pos=poss[50])
>>> it.next().tid == tids[51]
True

Expand All @@ -116,19 +116,19 @@ If a starting transaction is before the first transaction in the file,
then the first transaction is returned.

>>> from ZODB.utils import p64, u64
>>> it = ZODB.FileStorage.FileIterator('data.fs', p64(u64(tids[0])-1))
>>> it = ZODB.filestorage.FileIterator('data.fs', p64(u64(tids[0])-1))
>>> it.next().tid == tids[0]
True

If it is after the last transaction, then iteration be empty:

>>> it = ZODB.FileStorage.FileIterator('data.fs', p64(u64(tids[-1])+1))
>>> it = ZODB.filestorage.FileIterator('data.fs', p64(u64(tids[-1])+1))
>>> list(it)
[]

Even if we write more transactions:

>>> it = ZODB.FileStorage.FileIterator('data.fs', p64(u64(tids[-1])+1))
>>> it = ZODB.filestorage.FileIterator('data.fs', p64(u64(tids[-1])+1))
>>> for i in range(10):
... conn.root()[i] = conn.root().__class__()
... transaction.commit()
Expand Down
33 changes: 16 additions & 17 deletions src/ZODB/FileStorage/tests.py → src/ZODB/filestorage/tests.py
Expand Up @@ -11,22 +11,18 @@
# FOR A PARTICULAR PURPOSE.
#
##############################################################################
import doctest
import os
import time
import transaction
import unittest
import ZODB.blob
import ZODB.FileStorage
import ZODB.tests.util

def pack_keep_old():
"""Should a copy of the database be kept?
The pack_keep_old constructor argument controls whether a .old file (and .old directory for blobs is kept.)
>>> import os
>>> import time
>>> import transaction
>>> from ZODB.db import DB
>>> from ZODB.FileStorage import FileStorage
>>> from ZODB.filestorage import FileStorage
>>> from ZODB.blob import Blob
>>> fs = FileStorage('data.fs', blob_dir='blobs')
>>> db = DB(fs)
Expand Down Expand Up @@ -95,8 +91,10 @@ def pack_with_repeated_blob_records():
fixed by the time you read this, but there might still be
transactions in the wild that have duplicate records.
>>> import time
>>> import transaction
>>> from ZODB.db import DB
>>> from ZODB.FileStorage import FileStorage
>>> from ZODB.filestorage import FileStorage
>>> from ZODB.blob import Blob
>>> fs = FileStorage('t', blob_dir='bobs')
>>> db = DB(fs)
Expand Down Expand Up @@ -132,8 +130,10 @@ def _save_index():
_save_index can fail for large indexes.
>>> import transaction
>>> import ZODB.utils
>>> fs = ZODB.FileStorage.FileStorage('data.fs')
>>> from ZODB.filestorage import FileStorage
>>> fs = FileStorage('data.fs')
>>> t = transaction.begin()
>>> fs.tpc_begin(t)
Expand All @@ -153,7 +153,7 @@ def _save_index():
>>> import logging
>>> handler = logging.StreamHandler(sys.stdout)
>>> logger = logging.getLogger('ZODB.FileStorage')
>>> logger = logging.getLogger('ZODB.filestorage')
>>> logger.setLevel(logging.DEBUG)
>>> logger.addHandler(handler)
>>> index, pos, tid = fs._restore_index()
Expand All @@ -172,13 +172,12 @@ def _save_index():


def test_suite():
import doctest
from ZODB.tests.util import setUp
from ZODB.tests.util import tearDown
return unittest.TestSuite((
doctest.DocFileSuite(
'zconfig.txt', 'iterator.test',
setUp=ZODB.tests.util.setUp, tearDown=ZODB.tests.util.tearDown,
),
doctest.DocTestSuite(
setUp=ZODB.tests.util.setUp, tearDown=ZODB.tests.util.tearDown,
),
'zconfig.txt', 'iterator.test', setUp=setUp, tearDown=tearDown),
doctest.DocTestSuite(setUp=setUp, tearDown=tearDown),
))

0 comments on commit dd5cc53

Please sign in to comment.