Skip to content

Commit

Permalink
Doc fixes, plus Tree now has discover method.
Browse files Browse the repository at this point in the history
  • Loading branch information
dotsdl committed Mar 20, 2016
1 parent 9815724 commit 3939580
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
8 changes: 4 additions & 4 deletions docs/Tags-Categories.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,16 +31,16 @@ analysis code. For example, if we have Treants with different shades of bark
(say, "dark" and "light"), we can make a category that reflects this. In this
case, we categorize ``sprout`` as "dark" ::
>>> s.categories['roots'] = 'dark'
>>> s.categories['bark'] = 'dark'
>>> s.categories
<Categories({'roots': 'shallow'})>
<Categories({'bark': 'dark'})>

Perhaps we've written some analysis code that will take both "dark" and "light"
Treants as input but needs to handle them differently. It can see what variety
of **Treant** it is working with using ::

>>> s.categories['roots']
'shallow'
>>> s.categories['bark']
'dark'

The keys for categories must be strings, but the values may be strings, numbers
(floats, ints), or booleans (``True``, ``False``). ``None`` may not be used since
Expand Down
4 changes: 2 additions & 2 deletions docs/Trees.rst
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ Paths that resolve as being inside a Tree give `True` for membership tests ::
>>> t['a/file'] in t
True

Note that neither of these items need exist ::
Note that these items need not exist ::

>>> t['a/file'].exists
False

in which case whether a Tree or Leaf is returned is dependent on an ending
``/``. We can create directories and empty files easily enough, though ::
``/``. We can create directories and empty files easily enough, though::

>>> adir = t['a/directory/'].make()
>>> adir.exists
Expand Down
13 changes: 11 additions & 2 deletions src/datreant/core/manipulators.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,9 @@ def discover(dirpath='.', depth=None, treantdepth=None):
Parameters
----------
dirpath : string
Directory within which to search for Treants.
dirpath : string, Tree
Directory within which to search for Treants. May also be an existing
Tree.
depth : int
Maximum directory depth to tolerate while traversing in search of
Treants. ``None`` indicates no depth limit.
Expand All @@ -30,6 +31,14 @@ def discover(dirpath='.', depth=None, treantdepth=None):
"""
from .collections import Bundle
from .trees import Tree

if isinstance(dirpath, Tree):
if not dirpath.exists:
raise OSError("Tree doesn't exist in the filesystem")

dirpath = dirpath.abspath

found = list()

startdepth = len(dirpath.split(os.sep))
Expand Down
3 changes: 3 additions & 0 deletions src/datreant/core/trees.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
from asciitree import LeftAligned

from .util import makedirs
from .manipulators import discover
from . import _TREELIMBS


Expand Down Expand Up @@ -358,6 +359,8 @@ def children(self):
from .collections import View
return View(self.trees + self.leaves + self.hidden)

discover = discover

@property
def treants(self):
"""Bundle of all Treants found within this Tree.
Expand Down

0 comments on commit 3939580

Please sign in to comment.