Esempio n. 1
0
 def GET(self):
     qdict = web.input()
     if 'substation' not in qdict:
         qdict['substation'] = str(gv.substation_index)
     subid = int(qdict['substation'])
     subprocess.call(['rm', 'static/images/camera_temp.jpg'])
     if process_page_request('view_camera', qdict):
         if gv.plugin_data['ca']['enable_camera'] == 'on':
             subprocess.call(['cp', 'static/images/camera.jpg', 'static/images/camera_temp.jpg'])
         return template_render.camera(0, gv.plugin_data['ca'])
     elif 'substation' not in qdict:
         raise web.seeother('/suslv?head=Cameras&continuation=ca')
     else:
         try:
             subid, data = load_and_save_remote(qdict, [], 'susldr', 'data', {'camera':1, 'cai':1})
             if data['cai']:
                 try:
                     with open('static/images/camera_temp.jpg', mode='wb') as file: # b is important -> binary
                         file.write(base64.b64decode(data['cai']))
                 except Exception as ex:
                     gv.logger.critical('Could not write camera_temp.jpg.  ex: ' + str(ex))
             return template_render.camera(subid, data['camera'])
         except Exception as ex:
             gv.logger.exception('view_camera: No response from slave: ' +
                            gv.plugin_data['su']['subinfo'][subid]['name'] + ' Exception: ' + str(ex))
             gv.plugin_data['su']['subinfo'][subid]['status'] = 'unreachable'
             raise web.seeother('/unreachable')
Esempio n. 2
0
    def GET(self):
        qdict = web.input()
        subid = 0 if 'substation' not in qdict else int(qdict['substation'])
        if process_page_request('change_camera', qdict) or subid == 0:
            checkboxes = ['enable_camera', 'zone_pic', 'current_pic']
            for c in checkboxes:
                if c != 'enable_camera' or gv.plugin_data['ca'][c] != 'missing':
                    if c not in qdict:
                        qdict[c] = 'off'
                else:
                    qdict[
                        c] = 'missing'  # dont change 'missing' attribute of enable_camera

            for c in checkboxes:
                if gv.plugin_data['ca'][c] != qdict[c]:
                    gv.plugin_data['ca'][c] = qdict[c]
                    changed = True

            intparams = ['sleep_time']
            for p in intparams:
                if gv.plugin_data['ca'][p] != int(qdict[p]):
                    gv.plugin_data['ca'][p] = int(qdict[p])
                    changed = True

            sparams = ['resolution']
            for p in sparams:
                if gv.plugin_data['ca'][p] != qdict[p]:
                    gv.plugin_data['ca'][p] = qdict[p]
                    take_picture('camera.jpg', False)
                    changed = True

            if changed:
                with open('./data/camera.json',
                          'w') as f:  # write the settings to file
                    json.dump(gv.plugin_data['ca'], f)
            if 'substation' in qdict:
                web.header('Content-Type', 'application/json')
                return json.dumps([])
        else:
            try:
                subid, data = load_and_save_remote(qdict, [], 'cau',
                                                   'substation', '0')
            except Exception as ex:
                gv.logger.info('change_camera: No response from slave: ' +
                               gv.plugin_data['su']['subinfo'][subid]['name'] +
                               ' Exception: ' + str(ex))
                gv.plugin_data['su']['subinfo'][subid][
                    'status'] = 'unreachable'
                raise web.seeother('/unreachable')
        raise web.seeother('/ca')
Esempio n. 3
0
 def GET(self):
     qdict = web.input()
     subid = 0 if 'substation' not in qdict else int(qdict['substation'])
     if process_page_request('pic', qdict) or subid == 0:
         take_picture('camera.jpg', False)
         if 'substation' in qdict:
             web.header('Content-Type', 'application/json')
             return json.dumps([])
     else:
         try:
             subid, data = load_and_save_remote(qdict, [], 'cap', 'substation', '0')
         except Exception as ex:
             gv.logger.info('pic: No response from slave: ' +
                            gv.plugin_data['su']['subinfo'][subid]['name'] + ' Exception: ' + str(ex))
             gv.plugin_data['su']['subinfo'][subid]['status'] = 'unreachable'
             raise web.seeother('/unreachable')
     raise web.seeother('/ca')
Esempio n. 4
0
    def GET(self):
        qdict = web.input()
        subid = 0 if 'substation' not in qdict else int(qdict['substation'])
        if process_page_request('change_camera', qdict) or subid == 0:
            checkboxes = ['enable_camera', 'zone_pic','current_pic']
            for c in checkboxes:
                if c != 'enable_camera' or gv.plugin_data['ca'][c] != 'missing':
                    if c not in qdict:
                        qdict[c] = 'off'
                else:
                    qdict[c] = 'missing' # dont change 'missing' attribute of enable_camera

            for c in checkboxes:
                if gv.plugin_data['ca'][c] != qdict[c]:
                    gv.plugin_data['ca'][c] = qdict[c]
                    changed = True

            intparams = ['sleep_time']
            for p in intparams:
                if gv.plugin_data['ca'][p] != int(qdict[p]):
                    gv.plugin_data['ca'][p] = int(qdict[p])
                    changed = True

            sparams = ['resolution']
            for p in sparams:
                if gv.plugin_data['ca'][p] != qdict[p]:
                    gv.plugin_data['ca'][p] = qdict[p]
                    take_picture('camera.jpg', False)
                    changed = True

            if changed:
                with open('./data/camera.json', 'w') as f:  # write the settings to file
                    json.dump(gv.plugin_data['ca'], f)
            if 'substation' in qdict:
                web.header('Content-Type', 'application/json')
                return json.dumps([])
        else:
            try:
                subid, data = load_and_save_remote(qdict, [], 'cau', 'substation', '0')
            except Exception as ex:
                gv.logger.info('change_camera: No response from slave: ' +
                               gv.plugin_data['su']['subinfo'][subid]['name'] + ' Exception: ' + str(ex))
                gv.plugin_data['su']['subinfo'][subid]['status'] = 'unreachable'
                raise web.seeother('/unreachable')
        raise web.seeother('/ca')
Esempio n. 5
0
 def GET(self):
     qdict = web.input()
     subid = 0 if 'substation' not in qdict else int(qdict['substation'])
     if process_page_request('pic', qdict) or subid == 0:
         take_picture('camera.jpg', False)
         if 'substation' in qdict:
             web.header('Content-Type', 'application/json')
             return json.dumps([])
     else:
         try:
             subid, data = load_and_save_remote(qdict, [], 'cap',
                                                'substation', '0')
         except Exception as ex:
             gv.logger.info('pic: No response from slave: ' +
                            gv.plugin_data['su']['subinfo'][subid]['name'] +
                            ' Exception: ' + str(ex))
             gv.plugin_data['su']['subinfo'][subid][
                 'status'] = 'unreachable'
             raise web.seeother('/unreachable')
     raise web.seeother('/ca')
Esempio n. 6
0
 def GET(self):
     qdict = web.input()
     if 'substation' not in qdict:
         qdict['substation'] = str(gv.substation_index)
     subid = int(qdict['substation'])
     subprocess.call(['rm', 'static/images/camera_temp.jpg'])
     if process_page_request('view_camera', qdict):
         if gv.plugin_data['ca']['enable_camera'] == 'on':
             subprocess.call([
                 'cp', 'static/images/camera.jpg',
                 'static/images/camera_temp.jpg'
             ])
         return template_render.camera(0, gv.plugin_data['ca'])
     elif 'substation' not in qdict:
         raise web.seeother('/suslv?head=Cameras&continuation=ca')
     else:
         try:
             subid, data = load_and_save_remote(qdict, [], 'susldr', 'data',
                                                {
                                                    'camera': 1,
                                                    'cai': 1
                                                })
             if data['cai']:
                 try:
                     with open(
                             'static/images/camera_temp.jpg',
                             mode='wb') as file:  # b is important -> binary
                         file.write(base64.b64decode(data['cai']))
                 except Exception as ex:
                     gv.logger.critical(
                         'Could not write camera_temp.jpg.  ex: ' + str(ex))
             return template_render.camera(subid, data['camera'])
         except Exception as ex:
             gv.logger.exception(
                 'view_camera: No response from slave: ' +
                 gv.plugin_data['su']['subinfo'][subid]['name'] +
                 ' Exception: ' + str(ex))
             gv.plugin_data['su']['subinfo'][subid][
                 'status'] = 'unreachable'
             raise web.seeother('/unreachable')