From 761b20799f130d11850740634f6a3c7cd409aa83 Mon Sep 17 00:00:00 2001 From: Calin Crisan Date: Sat, 21 Sep 2013 14:56:29 +0300 Subject: [PATCH] added more urls and handlers --- doc/requirements.txt | 1 - doc/todo.txt | 7 ++++ src/handlers.py | 87 +++++++++++++++++++++++++++++++++++++++++++- src/server.py | 6 +++ temp/.gitkeep | 1 + 5 files changed, 100 insertions(+), 2 deletions(-) create mode 100644 doc/todo.txt create mode 100644 temp/.gitkeep diff --git a/doc/requirements.txt b/doc/requirements.txt index 12bb981..c89b277 100644 --- a/doc/requirements.txt +++ b/doc/requirements.txt @@ -4,6 +4,5 @@ jinja2 ffmpeg motion -nginx v4l-utils smbclient diff --git a/doc/todo.txt b/doc/todo.txt new file mode 100644 index 0000000..ee68a78 --- /dev/null +++ b/doc/todo.txt @@ -0,0 +1,7 @@ +-> browser compatibility test +-> authentication +-> proxy for slave motioneyes +-> add a view log functionality +-> click to zoom on cameras +-> add a previewer for movies +-> add a previewer for snapshots diff --git a/src/handlers.py b/src/handlers.py index cd84cbf..cd78db6 100644 --- a/src/handlers.py +++ b/src/handlers.py @@ -1,5 +1,8 @@ -from tornado.web import RequestHandler +import json +import logging + +from tornado.web import RequestHandler, HTTPError import template @@ -10,8 +13,90 @@ class BaseHandler(RequestHandler): content = template.render(template_name, **context) self.finish(content) + + def finish_json(self, data={}): + self.set_header('Content-Type', 'application/json') + self.finish(json.dumps(data)) class MainHandler(BaseHandler): def get(self): self.render('main.html') + + +class ConfigHandler(BaseHandler): + def get(self, camera_id=None, op=None): + if op == 'get': + self.get_config(camera_id) + + else: + raise HTTPError(400, 'unknown operation') + + def post(self, camera_id=None, op=None): + if op == 'set': + self.set_config(camera_id) + + elif op == 'add': + self.add_camera() + + elif op == 'rem': + self.rem_camera(camera_id) + + else: + raise HTTPError(400, 'unknown operation') + + def get_config(self, camera_id): + logging.debug('getting config for camera %(id)s' % {'camera': camera_id}) + + def set_config(self, camera_id): + logging.debug('setting config for camera %(id)s' % {'camera': camera_id}) + + def add_camera(self): + logging.debug('adding new camera') + + def rem_camera(self, camera_id): + logging.debug('removing camera %(id)s' % {'camera': camera_id}) + + +class SnapshotHandler(BaseHandler): + def get(self, camera_id, op, filename=None): + if op == 'current': + self.current() + + elif op == 'list': + self.list(camera_id) + + elif op == 'download': + self.download(filename) + + else: + raise HTTPError(400, 'unknown operation') + + def current(self): + pass + + def list(self, camera_id): + logging.debug('listing snapshots for camera %(id)s' % {'camera': camera_id}) + + def download(self, camera_id, filename): + logging.debug('downloading snapshot %(filename)s of camera %(id)s' % { + 'filename': filename, 'camera': camera_id}) + + +class MovieHandler(BaseHandler): + def get(self, camera_id, op, filename=None): + if op == 'list': + self.list(camera_id) + + elif op == 'download': + self.download(camera_id, filename) + + else: + raise HTTPError(400, 'unknown operation') + + def list(self, camera_id): + logging.debug('listing movies for camera %(id)s' % {'camera': camera_id}) + + def download(self, camera_id, filename): + logging.debug('downloading movie %(filename)s of camera %(id)s' % { + 'filename': filename, 'camera': camera_id}) diff --git a/src/server.py b/src/server.py index 6c5507c..8d7b86b 100644 --- a/src/server.py +++ b/src/server.py @@ -9,6 +9,12 @@ import template application = Application( [ (r'^/$', handlers.MainHandler), + (r'^/config/(?P\w+)/(?Pget|set|rem)/?$', handlers.ConfigHandler), + (r'^/config/(?Padd)/?$', handlers.ConfigHandler), + (r'^/snapshot/(?P\w+)/(?Pcurrent|list)/?$', handlers.SnapshotHandler), + (r'^/snapshot/(?P\w+)/(?Pdownload)/(?P.+)/?$', handlers.SnapshotHandler), + (r'^/movie/(?P\w+)/(?Plist)/?$', handlers.MovieHandler), + (r'^/movie/(?P\w+)/(?Pdownload)/(?P.+)/?$', handlers.MovieHandler), ], debug=settings.DEBUG, static_path=settings.STATIC_PATH, diff --git a/temp/.gitkeep b/temp/.gitkeep new file mode 100644 index 0000000..18d93d2 --- /dev/null +++ b/temp/.gitkeep @@ -0,0 +1 @@ +this directory contains (at runtime) temporary config files for motion \ No newline at end of file -- 2.39.5