-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathtemplate-poly.py
executable file
·64 lines (59 loc) · 1.92 KB
/
template-poly.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
#!/usr/bin/env python
"""
This is a NodeServer template for Polyglot v2 written in Python2/3
by Einstein.42 (James Milne) [email protected]
"""
try:
import polyinterface
except ImportError:
import pgc_interface as polyinterface
import sys
"""
Import the polyglot interface module. This is in pypy so you can just install it
normally. Replace pip with pip3 if you are using python3.
Virtualenv:
pip install polyinterface
Not Virutalenv:
pip install polyinterface --user
*I recommend you ALWAYS develop your NodeServers in virtualenv to maintain
cleanliness, however that isn't required. I do not condone installing pip
modules globally. Use the --user flag, not sudo.
"""
LOGGER = polyinterface.LOGGER
"""
polyinterface has a LOGGER that is created by default and logs to:
logs/debug.log
You can use LOGGER.info, LOGGER.warning, LOGGER.debug, LOGGER.error levels as needed.
"""
""" Grab My Controller Node """
from nodes import TemplateController
if __name__ == "__main__":
try:
polyglot = polyinterface.Interface('PythonTemplate')
"""
Instantiates the Interface to Polyglot.
The name doesn't really matter unless you are starting it from the
command line then you need a line Template=N
where N is the slot number.
"""
polyglot.start()
"""
Starts MQTT and connects to Polyglot.
"""
control = TemplateController(polyglot)
"""
Creates the Controller Node and passes in the Interface
"""
control.runForever()
"""
Sits around and does nothing forever, keeping your program running.
"""
except (KeyboardInterrupt, SystemExit):
LOGGER.warning("Received interrupt or exit...")
"""
Catch SIGTERM or Control-C and exit cleanly.
"""
polyglot.stop()
except Exception as err:
LOGGER.error('Excption: {0}'.format(err), exc_info=True)
sys.exit(0)