337
337
This may be faster than iter_entries.
339
def accum(dir_ie, dir_path, a):
340
def descend(dir_ie, dir_path):
340
341
kids = dir_ie.children.items()
342
343
for name, ie in kids:
343
344
child_path = os.path.join(dir_path, name)
344
a.append((child_path, ie))
345
accum.append((child_path, ie))
345
346
if ie.kind == 'directory':
346
accum(ie, child_path, a)
347
descend(ie, child_path)
349
accum(self.root, '', a)
349
descend(self.root, '')
353
353
def directories(self):
354
"""Return (path, entry) pairs for all directories.
354
"""Return (path, entry) pairs for all directories, including the root.
356
def descend(parent_ie):
357
parent_name = parent_ie.name
358
yield parent_name, parent_ie
360
# directory children in sorted order
362
for ie in parent_ie.children.itervalues():
363
if ie.kind == 'directory':
364
dn.append((ie.name, ie))
357
def descend(parent_ie, parent_path):
358
accum.append((parent_path, parent_ie))
367
for name, child_ie in dn:
368
for sub_name, sub_ie in descend(child_ie):
369
yield appendpath(parent_name, sub_name), sub_ie
360
kids = [(ie.name, ie) for ie in parent_ie.children.itervalues() if ie.kind == 'directory']
371
for name, ie in descend(self.root):
363
for name, child_ie in kids:
364
child_path = os.path.join(parent_path, name)
365
descend(child_ie, child_path)
366
descend(self.root, '')