]> www.vanbest.org Git - motioneye-debian/commitdiff
config request improvements
authorCalin Crisan <ccrisan@gmail.com>
Wed, 25 Sep 2013 14:35:52 +0000 (17:35 +0300)
committerCalin Crisan <ccrisan@gmail.com>
Wed, 25 Sep 2013 14:35:52 +0000 (17:35 +0300)
doc/todo.txt
src/config.py
src/handlers.py
src/server.py

index 84d9c46ed677c4d33dd4cf1542b2f0dc8fb203bf..0ce229412224c307a33759feefeaa203d1e1ceeb 100644 (file)
@@ -1,4 +1,4 @@
--> move target dir to device config
+-> group @config rules to top
 -> browser compatibility test
 -> hint text next to section titles
 -> authentication
index d7ec91fc94a2dd6b45275169a09d92c0a91ce839..61f945c7c83a32e2024bd5adf1594dd9db105dc9 100644 (file)
@@ -253,15 +253,14 @@ def add_camera(device):
 
     # add the default camera config
     data = OrderedDict()
-    name = 'Camera' + str(camera_id)
-    data['@name'] = name
+    data['@name'] = 'Camera' + str(camera_id)
     data['@proto'] = proto
     data['videodevice'] = device
     
     # write the configuration to file
     set_camera(camera_id, data)
     
-    return camera_id, name, data
+    return camera_id, data
 
 
 def rem_camera(camera_id):
@@ -683,7 +682,7 @@ def _dict_to_conf(lines, data, list_names=[]):
 
 
 def _set_default_motion(data):
-    data.setdefault('@general_enabled', True)
+    data.setdefault('@enabled', True)
     data.setdefault('@show_advanced', False)
     data.setdefault('@admin_username', 'admin')
     data.setdefault('@admin_password', '')
index 870a890648ce6d1e2e9669ca75ffd19cc1c6b43e..655f9586082b8e5aa6422e8a77beefa4d4115f79 100644 (file)
@@ -27,13 +27,22 @@ class MainHandler(BaseHandler):
 
 class ConfigHandler(BaseHandler):
     def get(self, camera_id=None, op=None):
+        if camera_id is not None:
+            camera_id = int(camera_id)
+        
         if op == 'get':
             self.get_config(camera_id)
+            
+        elif op == 'list':
+            self.list_cameras()
         
         else:
             raise HTTPError(400, 'unknown operation')
     
     def post(self, camera_id=None, op=None):
+        if camera_id is not None:
+            camera_id = int(camera_id)
+        
         if op == 'set':
             self.set_config(camera_id)
         
@@ -47,25 +56,21 @@ class ConfigHandler(BaseHandler):
             raise HTTPError(400, 'unknown operation')
     
     def get_config(self, camera_id):
-        general_config = config.get_main()
-        
         if camera_id:
             logging.debug('getting config for camera %(id)s' % {'id': camera_id})
             
-            cameras = general_config.get('cameras', {})
-            if camera_id not in cameras:
+            camera_ids = config.get_camera_ids()
+            if camera_id not in camera_ids:
                 raise HTTPError(404, 'no such camera')
             
             self.finish_json(config.get_camera(camera_id))
             
         else:
-            logging.debug('getting general config')
+            logging.debug('getting main config')
             
-            self.finish_json(general_config)
+            self.finish_json(config.get_main())
     
     def set_config(self, camera_id):
-        general_config = config.get_main()
-        
         try:
             data = json.loads(self.request.body)
             
@@ -77,14 +82,14 @@ class ConfigHandler(BaseHandler):
         if camera_id:
             logging.debug('setting config for camera %(id)s' % {'id': camera_id})
             
-            cameras = general_config.get('cameras', {})
-            if camera_id not in cameras:
+            camera_ids = config.get_camera_ids()
+            if camera_id not in camera_ids:
                 raise HTTPError(404, 'no such camera')
             
             config.set_camera(camera_id, data)
 
         else:
-            logging.debug('setting general config')
+            logging.debug('setting main config')
             
             try:
                 data = json.loads(self.request.body)
@@ -94,14 +99,33 @@ class ConfigHandler(BaseHandler):
                 
                 raise
             
-            general_config.update(data)
-            config.set_main(general_config)
+            config.set_main(data)
+    
+    def list_cameras(self):
+        logging.debug('listing cameras')
+        
+        cameras = []
+        for camera_id in config.get_camera_ids():
+            data = config.get_camera(camera_id)
+            data['@id'] = camera_id
+            cameras.append(data)
+
+        self.finish_json({'cameras': cameras})
     
     def add_camera(self):
         logging.debug('adding new camera')
+        
+        device = self.get_argument('device')
+        camera_id, data = config.add_camera(device)
+        
+        data['@id'] = camera_id
+        
+        self.finish_json(data)
     
     def rem_camera(self, camera_id):
         logging.debug('removing camera %(id)s' % {'id': camera_id})
+        
+        config.rem_camera(camera_id)
 
 
 class SnapshotHandler(BaseHandler):
index 9daeb524158d471c6ee21f0e8ae1b39f1f69ee7d..864507c07039ccde5c00f22875a19f33460e3e94 100644 (file)
@@ -9,9 +9,9 @@ import template
 application = Application(
     [
         (r'^/$', handlers.MainHandler),
-        (r'^/config/general/(?P<op>set|get)/?$', handlers.ConfigHandler),
+        (r'^/config/main/(?P<op>set|get)/?$', handlers.ConfigHandler),
         (r'^/config/(?P<camera_id>\d+)/(?P<op>get|set|rem)/?$', handlers.ConfigHandler),
-        (r'^/config/(?P<op>add)/?$', handlers.ConfigHandler),
+        (r'^/config/(?P<op>add|list)/?$', handlers.ConfigHandler),
         (r'^/snapshot/(?P<camera_id>\d+)/(?P<op>current|list)/?$', handlers.SnapshotHandler),
         (r'^/snapshot/(?P<camera_id>\d+)/(?P<op>download)/(?P<filename>.+)/?$', handlers.SnapshotHandler),
         (r'^/movie/(?P<camera_id>\d+)/(?P<op>list)/?$', handlers.MovieHandler),