Skip to content
This repository has been archived by the owner on May 13, 2020. It is now read-only.

Commit

Permalink
- Provide container and root attributes on IConfigurationStore
Browse files Browse the repository at this point in the history
  they come handy in various load and dump situation instead of __parent__
  and getSite
  • Loading branch information
Adam Groszer committed Aug 30, 2012
1 parent 1c84c56 commit 2d4899b
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
4 changes: 3 additions & 1 deletion CHANGES.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ CHANGES
1.2.2 (unrelease)
-----------------

- No changes yet.
- Provide ``container`` and ``root`` attributes on IConfigurationStore
they come handy in various load and dump situation instead of __parent__
and getSite

1.2.1 (2012-06-05)
------------------
Expand Down
9 changes: 9 additions & 0 deletions src/cipher/configstore/configstore.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ class ConfigurationStore(object):
schema = None
fields = None
section = None
container = None
root = None

def __init__(self, context, schema=None, section=None):
if self.schema is None:
Expand Down Expand Up @@ -144,6 +146,7 @@ def load(self, config):
(self.context,), interfaces.IConfigurationStore)
for store in stores:
if not isinstance(store, self.__class__):
store.root = self.root
store.load(config)
zope.event.notify(
interfaces.ObjectConfigurationLoadedEvent(
Expand Down Expand Up @@ -215,6 +218,7 @@ def dump(self, config=None):
(self.context,), interfaces.IConfigurationStore)
for store in stores:
__traceback_info__ = repr(store)
store.root = self.root
store.dump(config)
return config

Expand Down Expand Up @@ -262,6 +266,8 @@ def load(self, config):
item = itemFactory()
item_store = interfaces.IConfigurationStore(item)
item_store.section = section
item_store.container = self.context
item_store.root = self.root
item_store.load(config)
# Note sends a ContainerModifiedEvent which would causes a config
# dump, overwriting the original file with partial information.
Expand All @@ -287,6 +293,7 @@ def dump(self, config=None):
continue
item_store = interfaces.IConfigurationStore(item)
item_store.section = self.section_prefix + name.encode('UTF-8')
item_store.root = self.root
__traceback_info__ = item_store.section
item_store.dump(config)
return config
Expand Down Expand Up @@ -320,6 +327,7 @@ def _load_from_external(self, config):
(self.context,), interfaces.IConfigurationStore)
for store in stores:
if not isinstance(store, self.__class__):
store.root = self.root
store.load(config)
zope.event.notify(
interfaces.ObjectConfigurationLoadedEvent(
Expand Down Expand Up @@ -355,6 +363,7 @@ def _dump_to_external(self):
(self.context,), interfaces.IConfigurationStore)
for store in stores:
__traceback_info__ = (fn, store)
store.root = self.root
store.dump(config)
# Write the configuration out.
with open(fn, 'w') as file:
Expand Down
9 changes: 9 additions & 0 deletions src/cipher/configstore/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,15 @@ class IConfigurationStore(zope.interface.Interface):
description=u'The name of the section in the configuration.',
required=True)

container = zope.interface.Attribute(
'The container in case the item under load will be added to one. '
'Happens if CollectionConfigurationStore loads the object.')

root = zope.interface.Attribute(
"The root object being loaded by the ConfigurationStore hierarchy. "
"You'll need to set this attribute on the root ConfigurationStore "
"then it will get passed down the tree")

def load(config):
"""Load configuration and apply it to the object."""

Expand Down

0 comments on commit 2d4899b

Please sign in to comment.