| Total Complexity | 6 |
| Total Lines | 25 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | #!/usr/bin/env python |
||
| 10 | class WebServer(object): |
||
| 11 | |||
| 12 | service = None |
||
| 13 | |||
| 14 | def __init__(self, service): |
||
| 15 | self.service = service |
||
| 16 | |||
| 17 | @cherrypy.expose |
||
| 18 | def index(self): |
||
| 19 | return "cctv-gif-buffer v%s" % (version()) |
||
| 20 | |||
| 21 | @cherrypy.expose |
||
| 22 | def gif(self, camera): |
||
| 23 | if camera not in self.service.cameras.keys(): |
||
| 24 | raise cherrypy.HTTPError(404, "Camera not found") |
||
| 25 | camobject = self.service.cameras[camera] |
||
| 26 | # obtain a temporary lock to copy the buffer |
||
| 27 | with camobject["lock"]: |
||
| 28 | x = copy.copy(camobject["buffer"]) |
||
| 29 | imageio.mimsave("test.gif", x, 'GIF', duration=2) |
||
| 30 | return self.service.cameras.keys() |
||
| 31 | |||
| 32 | def start(self): |
||
| 33 | cherrypy.server.socket_host = '0.0.0.0' |
||
| 34 | cherrypy.quickstart(self) |
||
| 35 |