Skip to content

Commit

Permalink
Views no longer build new Trees, Leaves if not necessary.
Browse files Browse the repository at this point in the history
Views used to just store absolute paths internally and build Trees and
Leaves as needed. Now they just store the Trees and Leaves.
  • Loading branch information
dotsdl committed Mar 16, 2016
1 parent 248188b commit f24675e
Showing 1 changed file with 15 additions and 27 deletions.
42 changes: 15 additions & 27 deletions src/datreant/core/collections.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,61 +224,49 @@ def add(self, *vegs):
elif isinstance(veg, (list, tuple)):
self.add(*veg)
elif isinstance(veg, View):
self.add(*veg.abspaths)
self.add(*list(veg))
elif isinstance(veg, Veg):
outconts.append(veg.abspath)
outconts.append(veg)
elif (isinstance(veg, string_types) and
(os.path.isdir(veg) or veg.endswith(os.sep))):
tre = Tree(veg)
outconts.append(tre.abspath)
outconts.append(tre)
elif isinstance(veg, string_types):
tre = Leaf(veg)
outconts.append(tre.abspath)
outconts.append(tre)
else:
raise TypeError("'{}' not a valid input "
"for View".format(veg))

self._add_members(*outconts)

def _add_members(self, *abspaths):
def _add_members(self, *members):
"""Add many members at once.
:Arguments:
*abspaths*
list of abspaths
*members*
list of Trees and Leaves
"""
for abspath in abspaths:
self._add_member(abspath)
for member in members:
self._add_member(member)

def _add_member(self, abspath):
def _add_member(self, member):
"""Add a member to the View.
:Arguments:
*abspath*
absolute path of new member
*member*
Tree or Leaf to add
"""
# check if uuid already present
paths = [member for member in self._state]

if abspath not in paths:
self._state.append(abspath)
if member not in self._state:
self._state.append(member)

def _list(self):
"""Return a list of members.
"""
from .trees import Leaf, Tree

outlist = []
for abspath in self._state:
if os.path.isdir(abspath) or abspath.endswith(os.sep):
outlist.append(Tree(abspath))
else:
outlist.append(Leaf(abspath))

return outlist
return list(self._state)

@property
def names(self):
Expand Down

0 comments on commit f24675e

Please sign in to comment.