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

I find two questions in the codes. #59

Closed
Cryin opened this issue Jul 5, 2016 · 4 comments
Closed

I find two questions in the codes. #59

Cryin opened this issue Jul 5, 2016 · 4 comments

Comments

@Cryin
Copy link

Cryin commented Jul 5, 2016

When I try to store files and folders info in the tree structure, the file name or folder name assignment identifier, but there may have same files or folders in different paths, i think this may be a problem, at least when try to store folders or URLs in the tree structure.
For example:
Root
|___ home
| |___ dev
| |___ mysql
| |___ python
|___ etc
|___ dev
| |___ mysql
Another problem is that I need to query a depth for a specific number of all nodes of the identifier ,i find that there is no such interface. So I codeing this function myself. I think it is necessary to add this interface, if there is a need I can paste my code.eg:
Root
|___ home
| |___ dev
| |___ mysql
| |___ python
|___ etc
|___ dev
| |___ mysql
give the layer=3,return a list [ dev,mysql]
Finally, I would like to say that your program is very good.

@caesar0301
Copy link
Owner

Thanks Cryin! You can solve the first problem by leaving the identifier parameter empty when creating a node. By default, a UUID (theoretically low probability to conflict) will be assigned when identifier is not present.

For the second, it is still absent in the library. Please feel free to add and give me a PR. Cheers!

@Cryin
Copy link
Author

Cryin commented Aug 19, 2016

Yes, you are right,i solve the first problem by store the full url path assignment identifier;

The second problem,In order to maintain the integrity of the treellib and can be maintained and upgraded.I write this function in my own code.So I put it up here:

def search_url_list(self,host,layers,filetype=''):
        self.link_list=[]
        for node in self.link_tree.children(self.root_node):
            if node.identifier == host:
                nodetmp=node
                self.foreach_same_layers(nodetmp,layers)
            #print x.identifier
            #print x.identifier
        return self.link_list

def foreach_same_layers(self, node, layers):
        if layers == 1:
            if node.data.url.strip():
                #print 'ret: '+node.identifier
                self.link_list.append(node)
                return node 
        ret=''
        #self.link_list=[]
        for subnode in self.link_tree.children(node.identifier):
            ret = self.foreach_same_layers(subnode, layers-1)
        return ret

use by search_url_list('subhost.host.com',3,None),
This will be able to get all of the depth of 3 node,i am sorry the code May not be easy to read ,just for reference.

@c0fec0de
Copy link
Contributor

I also looked into that topic some months ago. At the end of the day, the problem is the Tree object. But changing this would break everything.
This might be of interest for you http://anytree.readthedocs.io/en/latest/

@liamlundy
Copy link
Collaborator

Closing due to inactivity - also seems mostly solved?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants