My favorites | Sign in
Project Home Downloads Wiki Issues Source
Repository:
Checkout   Browse   Changes   Clones    
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
#!/usr/bin/env python
#
# Library: pyflowctrl
# Module: treewalker2
# Dependency: core3
# Examples:
#

import os
from core3 import WAITING, PROCESSING
from core3 import EmptyStream, Stream, Process

class TreeWalker(Process):
''' Tree Walker '''
def __init__(self):
''' __init__ '''
super(TreeWalker, self).__init__()
self.io = {
# directory_path - source directory
'input': Stream(data_type='path'),
# name - filename or directory name
'output': Stream(data_type='path'),
}

def __walktree(self, top):
""" Directory walker """
names = os.listdir(top)
for name in names:
if os.path.isdir(os.path.join(top, name)):
for (newtop, children) in self.__walktree(os.path.join(top, name)):
yield newtop, children
yield top, names

def main(self):
while True:
try:
path = self.io['input'].get()
except EmptyStream:
yield WAITING
continue

if not os.path.exists(path):
raise IOError("%s does not exist" % path)
self.io['output'].put(path)
for path, names in self.__walktree(path):
for name in names:
self.io['output'].put(os.path.join(path, name))
yield PROCESSING

Change log

0c95c67ab88b by ownport <ownport> on Aug 14, 2011   Diff
pyflowctrl: processes FileReader,
HTMLSpecials, TextProcessing, TreeWalker
migrated to core3
Go to: 
Project members, sign in to write a code review

Older revisions

All revisions of this file

File info

Size: 1492 bytes, 49 lines
Powered by Google Project Hosting