initialise repo
[debian/make-magic.git] / tests / breakfast.py
1 #!/usr/bin/env python
2
3 '''simple example of how to define items in pure python'''
4
5 import lib.loaders
6 from core.bits import *
7 from core.marshal import ItemConverter
8 from digraphtools.predicate import predicate
9
10 want_coffee = ItemConverter().predicate_string_to_callable(' coffee ')
11 assert want_coffee(['coffee','tv']) == True
12 assert want_coffee(['fish','tv']) == False
13
14 # Items 
15 class wake_up(Item):
16         pass
17
18 class get_up(Item):
19         depends = (wake_up,)
20
21 class make_breakfast(Item):
22         depends = (get_up,)
23
24 class eat_breakfast(Item):
25         depends = (make_breakfast,)
26
27 class make_coffee(Item):
28         depends = (get_up,)
29         predicate = want_coffee
30
31 class drink_coffee(Item):
32         depends = (make_coffee,)
33         predicate = want_coffee
34
35 class walk_out_door(Item):
36         depends = (get_up, eat_breakfast, make_coffee)
37
38 class go_to_work(Item):
39         description = 'Leave to go to work'
40         depends = (walk_out_door, eat_breakfast, drink_coffee)
41
42 # Tasks
43
44 items = [wake_up, get_up, make_breakfast, eat_breakfast, make_coffee, drink_coffee, walk_out_door, go_to_work]
45 breakfast_task_factory = lib.loaders.TaskFactory(items)