-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample_procedure.py
154 lines (125 loc) · 5.11 KB
/
example_procedure.py
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import click
from kmexpert.base.execution_context import ExecCtx
from kmexpert.config import register_procedure, tag
from kmexpert.base.step_based_procedure import StepBasedProcedure
from kmexpert.base.common_steps import EndIteration, StoreHistory
from kmexpert.base.step_base import StepBase
from kmexpert.base.blocks import Notification
from kmexpert.base.step_blocks import StepPromptBool, StepPromptYes, StepPromptNo
from kmexpert.base.input_handlers import NotifyOnHandler
from kmexpert.base.input_converters import YES, NO
from kmexpert.base.tooling import bold
@register_procedure
class DiagnosePrinter(StepBasedProcedure):
"""
Printer troubleshooting procedure
"""
def start_step(self):
return DiagnosePrinter.Start(self)
class Start(StepBase):
@classmethod
def Graph(cls):
return {'next': DiagnosePrinter.CheckPower}
def evaluate(s):
click.echo("\n")
Notification(click.style(s.procedure.name(), bold=True)).run()
click.echo("\n")
s.create_next_step(s.Graph()['next'])
class CheckPower(StepBase):
@classmethod
def Help(cls):
return {'h1': ["The printer power cable connection is located on its back",
"The power cable is a black cable connected to the socket marked AC"],}
@classmethod
def Graph(cls):
return {'next': DiagnosePrinter.CheckPaper}
def evaluate(s):
msg = 'Does your printer is turned on and has power?'
StepPromptYes(step=s, msg=msg, help=s.Help()['h1'],
handlers=[NotifyOnHandler(on=NO, msg="Please connect your printor to a socket and turn it on.")]
).run()
s.create_next_step(s.Graph()['next'])
class CheckPaper(StepBase):
@classmethod
def Graph(cls):
return {'yes': DiagnosePrinter.DiagnoseConnection,
'no': DiagnosePrinter.AddPaper}
def evaluate(s):
msg = 'Do you have paper in the paper tray?'
if StepPromptBool(step=s, msg=msg, help=[]).run():
s.create_next_step(s.Graph()['yes'])
else:
s.create_next_step(s.Graph()['no'])
class AddPaper(StepBase):
@classmethod
def Help(cls):
return {'h1': ["Paper tray is located on bottow-front of your printer",
"Some thorough instructions for adding paper"],}
@classmethod
def Graph(cls):
return {'next': DiagnosePrinter.DiagnoseConnection}
def evaluate(s):
msg = 'Added paper?'
StepPromptYes(step=s, msg=msg, help=s.Help()['h1'],
handlers=[NotifyOnHandler(on=NO, msg="Please add paper.")]
).run()
s.create_next_step(s.Graph()['next'])
class DiagnoseConnection(StepBase):
@classmethod
def Graph(cls):
return {'next': DiagnosePrinter.StoreHistory}
def evaluate(s):
execution_context = ExecCtx()
procedure = DiagnoseConnection(execution_context=execution_context)
procedure.run()
print('Finished running: %s' % procedure.name())
s.create_next_step(s.Graph()['next'])
class FinishedSuccessfully(StepBase):
@classmethod
def Graph(cls):
return {'yes': DiagnosePrinter.StoreHistory,
'no': DiagnosePrinter.CallSupport}
def evaluate(s):
msg = 'Do you have paper in the paper tray.'
if StepPromptBool(step=s, msg=msg, help=[]).run():
s.create_next_step(s.Graph()['yes'])
else:
s.create_next_step(s.Graph()['no'])
class CallSupport(StepBase):
@classmethod
def Graph(cls):
return {'next': DiagnosePrinter.StoreHistory}
def evaluate(s):
Notification(click.style("Please call support: 222-222-222", bold=True)).run()
s.create_next_step(s.Graph()['next'])
class StoreHistory(StoreHistory):
def evaluate(s):
s.store_history()
s.create_next_step(EndIteration)
@register_procedure
class DiagnoseConnection(StepBasedProcedure):
"""
Diagnose printer connections
"""
def start_step(self):
return DiagnoseConnection.Start(self)
class Start(StepBase):
@classmethod
def Graph(cls):
return {'next': DiagnoseConnection.MoreSteps}
def evaluate(s):
click.echo("\n")
Notification(click.style(s.procedure.name(), bold=True)).run()
click.echo("\n")
s.create_next_step(s.Graph()['next'])
class MoreSteps(StepBase):
@classmethod
def Graph(cls):
return {'next': DiagnoseConnection.StoreHistory}
def evaluate(s):
Notification("\nYou can add %s steps here\n" % bold('MORE')).run()
s.create_next_step(s.Graph()['next'])
class StoreHistory(StoreHistory):
def evaluate(s):
s.store_history()
s.create_next_step(EndIteration)