# HG changeset patch # User Jeff Hammel # Date 1375838802 25200 # Node ID 5417eb6364ee153f4caa38e6f970d5cfd7768762 # Parent d214e0f38ab181042e5207b180c1c19fcf362019 stubbing diff -r d214e0f38ab1 -r 5417eb6364ee python/tree.py --- a/python/tree.py Tue Aug 06 16:04:28 2013 -0700 +++ b/python/tree.py Tue Aug 06 18:26:42 2013 -0700 @@ -5,6 +5,8 @@ tree in python """ +# TODO: script2package + import optparse import os import sys @@ -23,6 +25,7 @@ 'last_child' : '└' } + def depth(directory): """returns the integer depth of a directory or path relative to '/' """ @@ -35,6 +38,36 @@ break return level + +### stuff for tree generalization + +class Tree(object): + """tree structure in python""" + + def __init__(self, parent=None): + self.parent = parent + + def children(self): + """returns children of the tree""" + + def add(self, item): + """add a child to the tree root""" + + def update(self, tree): + """add a subtree to the tree""" + self.add(tree) + tree.parent = self # XXX .add should probably do this for scary reasons + + def output(self, serializer): + """output the tree via the given serializer""" + # XXX or should this method exist at all and instead the + # __call__ method of serializers take a Tree object? + +class DirectoryTree(Tree): + """directory structure as a tree""" + +### + def tree(directory, item_marker=unicode_delimeters['item_marker'], vertical_line=unicode_delimeters['vertical_line'],