GithubHelp home page GithubHelp logo

Comments (3)

lavagetto avatar lavagetto commented on July 29, 2024

That's because .children already does recursion for you. EtcdResult.children should give you all the non-dir children of the prefix you entered.

Not sure of what you wanted to do though, I'll try to wrap my head around that in the afternoon.

from python-etcd.

sigmunau avatar sigmunau commented on July 29, 2024

Note that I'm not doing a recursive read. I'm just reading a folder and want to iterate over it's content. My example code was doing recursion manually, but there could be cases where you want to list entries within a folder anyway, for instance if you were implementing an etcd browser

from python-etcd.

lavagetto avatar lavagetto commented on July 29, 2024

Sorry for this taking me so long to answer; the problem resides in how get_subtree() works.

You want to do this:

import etcd                                                                                                                                                                                                       
def find_empty(cl, key):                                                                                                                                                                                          
    print "Called with " + key                                                                                                                                                                                    
    r = cl.read(key)                                                                                                                                                                                              
    if not r.dir:                                                                                                                                                                                                 
        return []                                                                                                                                                                                                 
    children = set([el.key for el in r.get_subtree() if el.dir and el.key != key])                                                                                                                                
    if not children:                                                                                                                                                                                              
        print "Empty folder found: " + key                                                                                                                                                                        
    for k in children:                                                                                                                                                                                            
        find_empty(cl, k)                                                                                                                                                                                         

c = etcd.Client()                                                                                                                                                                                                 
find_empty(c, '/hiera')

from python-etcd.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.