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

Commit

Permalink
Added recursive_delete method to KazooClient
Browse files Browse the repository at this point in the history
  • Loading branch information
labisso committed Feb 27, 2012
1 parent 39e310b commit b9fbe49
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
14 changes: 13 additions & 1 deletion kazoo/client.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import logging

from kazoo.zkclient import ZooKeeperClient, WatchedEvent, KeeperState,\
EventType, NodeExistsException
EventType, NodeExistsException, NoNodeException
from kazoo.retry import KazooRetry

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -211,6 +211,18 @@ def ensure_path(self, path):
# someone else created the node. how sweet!
pass

def recursive_delete(self, path):
"""Recursively delete a ZNode and all of its children
"""
children = self.get_children(path)
if children:
for child in children:
self.recursive_delete(path + "/" + child)
try:
self.delete(path)
except NoNodeException:
pass

def with_retry(self, func, *args, **kwargs):
"""Run a method repeatedly in the face of transient ZK errors
"""
Expand Down
6 changes: 3 additions & 3 deletions kazoo/zkclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,16 @@ class WatchedEvent(namedtuple('WatchedEvent', ('type', 'state', 'path'))):
"""

class ZooKeeperClient(object):

DEFAULT_TIMEOUT = 10000

"""A gevent-friendly wrapper of the Apache ZooKeeper zkpython client
TODO lots to do:
* better handling of ZK client session events
* disconnected state handling
* the rest of the operations
"""

DEFAULT_TIMEOUT = 10000

def __init__(self, hosts, watcher=None, timeout=10000):
self._hosts = hosts
self._watcher = watcher
Expand Down

0 comments on commit b9fbe49

Please sign in to comment.