Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 10 additions & 7 deletions src/etcd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,13 +49,14 @@ def parse_headers(self, response):
self.etcd_index = int(headers.get('x-etcd-index', 1))
self.raft_index = int(headers.get('x-raft-index', 1))

def get_subtree(self, leaves_only=False):
def get_subtree(self, leaves_only=False, as_tree=False):
"""
Get all the subtree resulting from a recursive=true call to etcd.

Args:
leaves_only (bool): if true, only value nodes are returned

as_tree (bool): if true, only value nodes are returned and
no flat children contents will be returned

"""
if not self._children:
Expand All @@ -64,11 +65,14 @@ def get_subtree(self, leaves_only=False):
return
for n in self._children:
node = EtcdResult(None, n)
if not leaves_only:
#Return also dirs, not just value nodes
if as_tree:
yield node
for child in node.get_subtree(leaves_only=leaves_only):
yield child
else:
if not leaves_only:
#Return also dirs, not just value nodes
yield node
for child in node.get_subtree(leaves_only=leaves_only):
yield child
return

@property
Expand Down Expand Up @@ -160,7 +164,6 @@ class EtcdError(object):
201: ValueError,
202: ValueError,
203: ValueError,
209: ValueError,
300: Exception,
301: Exception,
400: Exception,
Expand Down