annotate pyikriam/lazy/www/work/__init__.py @ 377:5d6f429e5f19 tip

fixed a typo.
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Tue, 14 Apr 2009 17:16:43 +0800
parents 60c4b4b78a01
children
rev   line source
62
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
1 from lazy.www.work.fetch import Fetcher
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
2 from lazy.www.work.find import Finder
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
3 from lazy.www.core import SemiProduct
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
4 class WorkFlow:
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
5
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
6 serial_number = 0
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
7 working_product = None
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
8 worker = None
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
9
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
10 def __init__(self, worker):
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
11 self.set_worker(worker)
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
12
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
13 def set_worker(self, worker):
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
14 self.worker = worker
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
15 if self.worker.working_product is None:
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
16 self.working_product = SemiProduct()
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
17 else:
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
18 self.working_product = self.worker.working_product
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
19
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
20 def get_content(self):
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
21 return self.working_product.content
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
22
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
23 def change_worker(self, new_worker):
246
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
24 self.serial_number += 1
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
25 self.last_work = self
62
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
26 self.worker = new_worker
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
27
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
28 def is_fetcher(self, obj):
246
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
29 if obj.__class__.__name__ == 'Fetcher': return True
62
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
30
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
31 def get(self, data = {} ):
246
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
32 if self.worker.__class__.__name__ != 'FileStorager' and not self.is_fetcher(self.worker) :
62
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
33 self.change_worker( Fetcher(self.working_product) )
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
34
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
35 self.working_product.content = self.worker.get(data)
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
36 return self
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
37
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
38 def post(self, data = {} ):
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
39 if not self.is_fetcher(self.worker):
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
40 self.change_worker( Fetcher(self.working_product) )
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
41
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
42 self.working_product.content = self.worker.post(data)
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
43 return self
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
44
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
45 def is_finder(self, obj):
246
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
46 if obj.__class__.__name__ == 'Finder': return True
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
47
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
48 def findall(self, expresses):
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
49 if not self.is_finder(self.worker):
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
50 self.change_worker( Finder(self.working_product) )
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
51
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
52 ret = {}
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
53 for e in expresses.keys():
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
54 try:
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
55 ret[e] = self.worker.find(expresses[e])
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
56 except:
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
57 pass
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
58
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
59 self.working_product.content = ret
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
60
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
61 return self
62
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
62
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
63 def find(self, express):
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
64 #if not self.is_finder(self.worker):
246
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
65 self.change_worker( Finder(self.working_product) )
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
66 self.last_working_product = self.working_product
62
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
67 self.working_product.content = self.worker.find(express)
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
68
246
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
69 return self
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
70
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
71 def process(self, fn):
60c4b4b78a01 code clean
"Hisn Yi, Chen <ossug.hychen@gmail.com>"
parents: 62
diff changeset
72 self.working_product.content = fn(self.working_product.content)
62
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
73 return self