-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfactory.py
29 lines (21 loc) · 866 Bytes
/
factory.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
"""Simple web server for the factory.
"""
import subprocess
import traceback
import tornado.web
FACTORY_SH = ['factory_status.sh']
class FactoryHandler(tornado.web.RequestHandler):
"""Display information about the device, useful in manufacturing."""
def get(self): # pylint: disable=g-bad-name
try:
script = subprocess.Popen(FACTORY_SH, stdout=subprocess.PIPE)
factory_output, _ = script.communicate(None)
self.write(factory_output)
except (IOError, OSError, subprocess.CalledProcessError):
print 'Unable to invoke %s' % FACTORY_SH
print traceback.print_exc()
self.write('script invocation failed')
self.set_header('Content-Type', 'text/plain')
def FactoryFactory():
"""I'm sorry. I couldn't resist. I'm sorry. Sorry, sorry, sorry."""
return tornado.web.Application([(r'/factory', FactoryHandler)])