Update Delete to recursive method

This commit is contained in:
Joshua Boniface 2021-05-31 00:13:13 -04:00
parent ede3e88cd7
commit 8625e9bd3e
1 changed files with 14 additions and 4 deletions

View File

@ -211,13 +211,23 @@ class ZKHandler(object):
self.log("ZKHandler error: Failed to commit transaction: {}".format(e), state='e') self.log("ZKHandler error: Failed to commit transaction: {}".format(e), state='e')
return False return False
def delete(self, key, recursive=True): def delete(self, keys, recursive=True):
""" """
Delete a key (defaults to recursive) Delete a key or list of keys (defaults to recursive)
""" """
if self.zk_conn.delete(key, recursive=recursive): if type(keys) is not list:
keys = [keys]
transaction = self.zk_conn.transaction()
for key in keys:
transaction.delete(key, recursive=recursive)
try:
transaction.commit()
return True return True
else: except Exception as e:
self.log("ZKHandler error: Failed to commit transaction: {}".format(e), state='e')
return False return False
def children(self, key): def children(self, key):