annotate pyikriam/lazy/www/work/__init__.py @ 227:f41ee87f4f7a

merged
author "Rex Tsai <chihchun@kalug.linux.org.tw>"
date Tue, 04 Nov 2008 23:44:48 +0800
parents a4c364888197
children 60c4b4b78a01
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):
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
24 self.serial_number += 1
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
25 self.worker = new_worker
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
26
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
27 def is_fetcher(self, obj):
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
28 if obj is not None: return True
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
29
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
30 def get(self, data = {} ):
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
31 if not self.is_fetcher(self.worker) :
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
32 self.change_worker( Fetcher(self.working_product) )
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
33
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
34 self.working_product.content = self.worker.get(data)
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
35 return self
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
36
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
37 def post(self, data = {} ):
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
38 if not self.is_fetcher(self.worker):
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
39 self.change_worker( Fetcher(self.working_product) )
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
40
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
41 self.working_product.content = self.worker.post(data)
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
42 return self
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
43
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
44 def is_finder(self, obj):
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
45 if obj is not None: return True
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
46
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
47 def find(self, express):
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
48 #if not self.is_finder(self.worker):
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
49 self.worker = Finder(self.working_product)
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
50 self.working_product.content = self.worker.find(express)
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
51
a4c364888197 add ikriam game binding lib python version
hychen@mluna
parents:
diff changeset
52 return self