3 '''simple example of how to define items in pure python
5 These are the same items as in examples/sample_items.json,
6 but rather than converting them from JSON, they are defined
7 using pure python (actually, the supplied doc/sample_items.json
8 was generated using this module and core.marshall.ItemConverter)
10 breakfast_task_factory is a task factory exactly like the
11 one used in lib/magic.py. If you want to define your items using
12 python rather than JSON, this is a pretty good way to do it
16 from core.bits import *
17 from core.marshal import ItemConverter
18 from digraphtools.predicate import predicate
20 want_coffee = ItemConverter().predicate_string_to_callable(' coffee ')
21 assert want_coffee(['coffee','tv']) == True
22 assert want_coffee(['fish','tv']) == False
31 class make_breakfast(Item):
34 class eat_breakfast(Item):
35 depends = (make_breakfast,)
37 class make_coffee(Item):
39 predicate = want_coffee
41 class drink_coffee(Item):
42 depends = (make_coffee,)
43 predicate = want_coffee
45 class have_breakfast(Group):
47 contains = (eat_breakfast, drink_coffee)
49 class walk_out_door(Item):
50 depends = (get_up, have_breakfast)
52 class go_to_work(Item):
53 description = 'Leave to go to work'
54 depends = (walk_out_door,)
58 items = [wake_up, get_up, have_breakfast, make_breakfast, eat_breakfast, make_coffee, drink_coffee, walk_out_door, go_to_work]
59 breakfast_task_factory = lib.loaders.TaskFactory(items)