-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathstate_change_listener.py
60 lines (43 loc) · 1.64 KB
/
state_change_listener.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
# Copyright (C) 2018 O.S. Systems Software LTDA.
"""
Sample script that cancels the update download action after receiving the
"enter download" state.
"""
import signal
import sys
import updatehub.listener
SCL = updatehub.listener.StateChange()
def signal_handler(*args): # pylint: disable=unused-argument
SCL.stop()
sys.exit(0)
def download_callback(_state, handler):
print("function called when starting the Download state")
print("it will cancel the transition")
handler.cancel()
def prepare_local_install_callback(_state, handler):
print("function called when starting the Prepare local install state")
print("it will cancel the transition")
handler.cancel()
def install_callback(_state, handler):
print("function called when starting the Install state")
handler.proceed()
def rebooting_callback(_state, _handler):
print("function called when starting the reboot state")
SCL.stop()
sys.exit(0)
def main():
"""
Main method. Instantiates a StateChange, adds callbacks to the
download state, prepare local install state, install state,
reboot state and then starts the listener.
"""
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGQUIT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
SCL.on_state(updatehub.listener.State.DOWNLOAD, download_callback)
SCL.on_state(updatehub.listener.State.PREPARE_LOCAL_INSTALL, prepare_local_install_callback)
SCL.on_state(updatehub.listener.State.INSTALL, install_callback)
SCL.on_state(updatehub.listener.State.REBOOT, rebooting_callback)
SCL.start()
if __name__ == '__main__':
main()