python-etcd icon indicating copy to clipboard operation
python-etcd copied to clipboard

EtcdResult if the current result is a leaf should return none not self

Open xdays opened this issue 9 years ago • 4 comments

In my opinion, if the node(dir) has no child or leave, then the children or leaves attribute should be None

xdays avatar Jul 29 '15 07:07 xdays

+1

ehooi avatar Aug 12 '15 19:08 ehooi

+1 But that change would certainly break my code that uses this library.

lechat avatar Aug 13 '15 12:08 lechat

@lechat that's exactly why I didn't merge this. I am thinking of making this behaviour activable with a flag, still I have no time to work on this for the next week at least.

lavagetto avatar Aug 13 '15 13:08 lavagetto

+1 by the way could you add a list dir function to Client?

I'm using following code,now.

def list_etcd_dir(client, path):
    if not is_alive(etcd_client):
        logger.error("can't connected to etcd server")

    try:
        result = client.read(path)
        if not result.dir:
            logger.error("not a dir")
            return []
        else:
            if result.children.next() != result:
                f = lambda x:x.split('/')[-1]
                return [f(i.key) for i in result.children]
            else:
                return []
    except:
        logger.error(error)
        return []

Mithrilwoodrat avatar Oct 31 '15 13:10 Mithrilwoodrat