Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return nodes for a dir as a tree #94

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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