vcs: added possibility to pre-load attributes for FileNodes.
This commit is contained in:
parent
6951a1ab96
commit
07a595c030
4 changed files with 24 additions and 7 deletions
|
|
@ -393,7 +393,7 @@ class GitCommit(base.BaseCommit):
|
|||
nodes.sort()
|
||||
return nodes
|
||||
|
||||
def get_node(self, path):
|
||||
def get_node(self, path, pre_load=None):
|
||||
if isinstance(path, unicode):
|
||||
path = path.encode('utf-8')
|
||||
path = self._fix_path(path)
|
||||
|
|
@ -415,7 +415,7 @@ class GitCommit(base.BaseCommit):
|
|||
else:
|
||||
node = DirNode(path, commit=self)
|
||||
elif type_ == 'blob':
|
||||
node = FileNode(path, commit=self)
|
||||
node = FileNode(path, commit=self, pre_load=pre_load)
|
||||
else:
|
||||
raise self.no_node_at_path(path)
|
||||
|
||||
|
|
|
|||
|
|
@ -289,7 +289,7 @@ class MercurialCommit(base.BaseCommit):
|
|||
|
||||
return nodes
|
||||
|
||||
def get_node(self, path):
|
||||
def get_node(self, path, pre_load=None):
|
||||
"""
|
||||
Returns `Node` object from the given `path`. If there is no node at
|
||||
the given `path`, `NodeDoesNotExistError` would be raised.
|
||||
|
|
@ -298,7 +298,7 @@ class MercurialCommit(base.BaseCommit):
|
|||
|
||||
if path not in self.nodes:
|
||||
if path in self._file_paths:
|
||||
node = FileNode(path, commit=self)
|
||||
node = FileNode(path, commit=self, pre_load=pre_load)
|
||||
elif path in self._dir_paths:
|
||||
if path == '':
|
||||
node = RootNode(commit=self)
|
||||
|
|
|
|||
|
|
@ -140,7 +140,7 @@ class SubversionCommit(base.BaseCommit):
|
|||
lambda: self.repository.get_commit(commit_id=commit_id),
|
||||
content)
|
||||
|
||||
def get_node(self, path):
|
||||
def get_node(self, path, pre_load=None):
|
||||
path = self._fix_path(path)
|
||||
if path not in self.nodes:
|
||||
|
||||
|
|
@ -152,7 +152,7 @@ class SubversionCommit(base.BaseCommit):
|
|||
if node_type == 'dir':
|
||||
node = nodes.DirNode(path, commit=self)
|
||||
elif node_type == 'file':
|
||||
node = nodes.FileNode(path, commit=self)
|
||||
node = nodes.FileNode(path, commit=self, pre_load=pre_load)
|
||||
else:
|
||||
raise NodeDoesNotExistError(self.no_node_at_path(path))
|
||||
|
||||
|
|
|
|||
|
|
@ -290,8 +290,9 @@ class FileNode(Node):
|
|||
:attribute: commit: if given, first time content is accessed, callback
|
||||
:attribute: mode: stat mode for a node. Default is `FILEMODE_DEFAULT`.
|
||||
"""
|
||||
_filter_pre_load = []
|
||||
|
||||
def __init__(self, path, content=None, commit=None, mode=None):
|
||||
def __init__(self, path, content=None, commit=None, mode=None, pre_load=None):
|
||||
"""
|
||||
Only one of ``content`` and ``commit`` may be given. Passing both
|
||||
would raise ``NodeError`` exception.
|
||||
|
|
@ -308,6 +309,22 @@ class FileNode(Node):
|
|||
self._content = content
|
||||
self._mode = mode or FILEMODE_DEFAULT
|
||||
|
||||
self._set_bulk_properties(pre_load)
|
||||
|
||||
def _set_bulk_properties(self, pre_load):
|
||||
if not pre_load:
|
||||
return
|
||||
pre_load = [entry for entry in pre_load
|
||||
if entry not in self._filter_pre_load]
|
||||
if not pre_load:
|
||||
return
|
||||
|
||||
for attr_name in pre_load:
|
||||
result = getattr(self, attr_name)
|
||||
if callable(result):
|
||||
result = result()
|
||||
self.__dict__[attr_name] = result
|
||||
|
||||
@LazyProperty
|
||||
def mode(self):
|
||||
"""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue