Skip to content

Commit

Permalink
introduce default_file_factory on directories for controlling def…
Browse files Browse the repository at this point in the history
…ault file child creation
  • Loading branch information
rnixx committed Dec 9, 2013
1 parent 1832055 commit eca6fb0
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 5 deletions.
4 changes: 4 additions & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ Changes
0.3dev
------

- introduce ``default_file_factory`` on directories for controlling default
file child creation.
[rnix, 2013-12-09]

- move file logic in ``FileStorage`` behavior.
[rnix, 2013-08-06]

Expand Down
15 changes: 10 additions & 5 deletions src/node/ext/directory/directory.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ class File(object):
class DirectoryStorage(DictStorage):
backup = default(True)
ignores = default(list())
default_file_factory = default(File)

# XXX: rename later to file_factories, keep now as is for b/c reasons
factories = default(dict())

Expand Down Expand Up @@ -198,13 +200,16 @@ def __getitem__(self, name):
try:
self[name] = factory()
except TypeError:
#happens if the factory cannot be called without
#args (e.g. .pt)
#in this case we treat it as a flat file
self[name]=File()
# happens if the factory cannot be called without
# args (e.g. .pt)
# in this case we treat it as a flat file
# XXX: remove try/except and fallback, for
# described case child factories are supposed
# to be used
self[name] = File()
else:
# default
self[name] = File()
self[name] = self.default_file_factory()
return self.storage[name]

@finalize
Expand Down
3 changes: 3 additions & 0 deletions src/node/ext/directory/interfaces.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ class IDirectory(INode, ICallable):
child_directory_factory = Attribute(u"Factory creating concrete node "
u"instances for directory children")

default_file_factory = Attribute(u"Default factory creating concrete node "
u"instances for file children")

file_factories = Attribute(u"Dict containing file names or endings as "
u"keys with the corresponding file node "
u"creating factory.")
Expand Down

0 comments on commit eca6fb0

Please sign in to comment.