Пример #1
0
def _set_streameye_enabled(enabled):
    global _streameye_enabled
    
    if enabled:
        logging.debug('removing all cameras from cache')
        config._camera_config_cache = {}
        config._camera_ids_cache = []
        
        logging.debug('disabling all cameras in motion.conf')
        cmd = 'sed -r -i "s/^thread (.*)/#thread \1/" /data/etc/motion.conf &>/dev/null'
        if os.system(cmd):
            logging.error('failed to disable cameras in motion.conf')
        
        logging.debug('renaming thread files')
        for name in os.listdir(settings.CONF_PATH):
            if re.match('^thread-\d+.conf$', name):
                os.rename(os.path.join(settings.CONF_PATH, name), os.path.join(settings.CONF_PATH, name + '.bak'))

        logging.debug('adding simple mjpeg camera')
        
        streameye_settings = _get_streameye_settings(1)
        main_config = config.get_main()
        
        device_details = {
            'proto': 'mjpeg',
            'host': '127.0.0.1',
            'port': streameye_settings['sePort'],
            'username': '',
            'password': '',
            'scheme': 'http',
            'uri': '/'
        }

        if streameye_settings['seAuthMode'] == 'basic':
            device_details['username'] = main_config['@normal_username']
            device_details['password'] = main_config['@normal_password']

        _streameye_enabled = True
        config._additional_structure_cache = {}
        camera_config = config.add_camera(device_details)
        
        # call set_camera again so that the streamEye-related defaults are saved
        config.set_camera(camera_config['@id'], camera_config)
        
        _set_motioneye_add_remove_cameras(False)

    else: # disabled
        logging.debug('removing simple mjpeg camera')
        for camera_id in config.get_camera_ids():
            camera_config = config.get_camera(camera_id)
            if camera_config.get('@proto') == 'mjpeg':
                config.rem_camera(camera_id)

        logging.debug('renaming thread files')
        for name in os.listdir(settings.CONF_PATH):
            if re.match('^thread-\d+.conf.bak$', name):
                os.rename(os.path.join(settings.CONF_PATH, name), os.path.join(settings.CONF_PATH, name[:-4]))
        
        _streameye_enabled = False
        config.invalidate()

        logging.debug('enabling all cameras')
        for camera_id in config.get_camera_ids():
            camera_config = config.get_camera(camera_id)
            camera_config['@enabled'] = True
            config.set_camera(camera_id, camera_config)
            
        _set_motioneye_add_remove_cameras(True)
Пример #2
0
def _set_streameye_enabled(enabled):
    global _streameye_enabled
    
    if enabled:
        logging.debug('removing all cameras from cache')
        config._camera_config_cache = {}
        config._camera_ids_cache = []
        
        logging.debug('disabling all cameras in motion.conf')
        cmd = 'sed -r -i "s/^camera (.*)/#camera \\1/" /data/etc/motion.conf &>/dev/null'
        if os.system(cmd):
            logging.error('failed to disable cameras in motion.conf')
        
        logging.debug('renaming camera files')
        for name in os.listdir(settings.CONF_PATH):
            if re.match('^camera-\d+.conf$', name):
                os.rename(os.path.join(settings.CONF_PATH, name), os.path.join(settings.CONF_PATH, name + '.bak'))

        logging.debug('adding simple mjpeg camera')
        
        streameye_settings = _get_streameye_settings(1)
        main_config = config.get_main()
        
        device_details = {
            'proto': 'mjpeg',
            'host': '127.0.0.1',
            'port': streameye_settings['sePort'],
            'username': '',
            'password': '',
            'scheme': 'http',
            'path': '/'
        }

        if streameye_settings['seAuthMode'] == 'basic':
            device_details['username'] = main_config['@normal_username']
            device_details['password'] = main_config['@normal_password']

        _streameye_enabled = True
        config._additional_structure_cache = {}
        camera_config = config.add_camera(device_details)
        
        # call set_camera again so that the streamEye-related defaults are saved
        config.set_camera(camera_config['@id'], camera_config)
        
        _set_motioneye_add_remove_cameras(False)

    else: # disabled
        logging.debug('removing simple mjpeg camera')
        for camera_id in config.get_camera_ids():
            camera_config = config.get_camera(camera_id)
            if camera_config.get('@proto') == 'mjpeg':
                config.rem_camera(camera_id)

        logging.debug('renaming camera files')
        for name in os.listdir(settings.CONF_PATH):
            if re.match('^camera-\d+.conf.bak$', name):
                os.rename(os.path.join(settings.CONF_PATH, name), os.path.join(settings.CONF_PATH, name[:-4]))
        
        _streameye_enabled = False
        config.invalidate()

        logging.debug('enabling all cameras')
        for camera_id in config.get_camera_ids():
            camera_config = config.get_camera(camera_id)
            camera_config['@enabled'] = True
            config.set_camera(camera_id, camera_config)
            
        _set_motioneye_add_remove_cameras(True)