Commit c91d06fe authored by Jim Fulton's avatar Jim Fulton

New Feature:

  The filestorage packer configuration option noe accepts calues of
  the form ``modname:expression``, allowing the use of packer
  factories with options.
parent 0632ffa6
...@@ -41,6 +41,10 @@ New Features ...@@ -41,6 +41,10 @@ New Features
index file if an output file name is given via the --output/-o index file if an output file name is given via the --output/-o
option. option.
- The filestorage packer configuration option noe accepts calues of
the form ``modname:expression``, allowing the use of packer
factories with options.
Bugs Fixed Bugs Fixed
---------- ----------
......
...@@ -134,6 +134,33 @@ packer ...@@ -134,6 +134,33 @@ packer
>>> fs.close() >>> fs.close()
If the packer contains a ':', then the text after the first ':' is
interpreted as an expression. This is handy to pass limited
configuration information to the packer:
>>> def packer_factory(name):
... def packer(storage, referencesf, stop, gc):
... print repr(name), referencesf, storage is fs, gc,
... print storage.pack_keep_old
... return packer
>>> ZODB.FileStorage.config_demo_printing_packer_factory = packer_factory
>>> fs = ZODB.config.storageFromString("""
... <filestorage>
... path my.fs
... packer ZODB.FileStorage:config_demo_printing_packer_factory('bob ')
... </filestorage>
... """)
>>> import time
>>> db = ZODB.DB(fs) # writes object 0
>>> fs.pack(time.time(), 42)
'bob ' 42 True True True
>>> fs.close()
pack-gc pack-gc
If false, then no garbage collection will be performed when If false, then no garbage collection will be performed when
packing. This can make packing go much faster and can avoid packing. This can make packing go much faster and can avoid
......
...@@ -44,7 +44,7 @@ ...@@ -44,7 +44,7 @@
raised. raised.
</description> </description>
</key> </key>
<key name="packer" datatype="dotted-name"> <key name="packer" datatype="string">
<description> <description>
The dotted name (dotted module name and object name) of a The dotted name (dotted module name and object name) of a
packer object. This is used to provide an alternative pack packer object. This is used to provide an alternative pack
......
...@@ -158,8 +158,15 @@ class FileStorage(BaseConfig): ...@@ -158,8 +158,15 @@ class FileStorage(BaseConfig):
config = self.config config = self.config
options = {} options = {}
if getattr(config, 'packer', None): if getattr(config, 'packer', None):
packer = config.packer
if ':' in packer:
m, expr = packer.split(':', 1)
m = __import__(m, {}, {}, ['*'])
options['packer'] = eval(expr, m.__dict__)
else:
m, name = config.packer.rsplit('.', 1) m, name = config.packer.rsplit('.', 1)
options['packer'] = getattr(__import__(m, {}, {}, ['*']), name) m = __import__(m, {}, {}, ['*'])
options['packer'] = getattr(m, name)
for name in ('blob_dir', 'create', 'read_only', 'quota', 'pack_gc', for name in ('blob_dir', 'create', 'read_only', 'quota', 'pack_gc',
'pack_keep_old'): 'pack_keep_old'):
......
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