示例#1
0
def cfg_keyvalue(key, value):
    global powermanagement

    # Depending on PUT/GET we will either change or read
    # values. If key is unknown, then this call fails with 404
    if key is not None:
        if settings.getUser(key) is None:
            abort(404)
            return

    if request.method == 'PUT':
        status = True
        if key == "keywords":
            # Keywords has its own API
            abort(404)
            return
        settings.setUser(key, value)
        if key in ['display-driver']:
            drv = settings.getUser('display-driver')
            if drv == 'none':
                drv = None
            special = drivers.activate(drv)
            if special is None:
                settings.setUser('display-driver', 'none')
                settings.setUser('display-special', None)
                status = False
            else:
                settings.setUser('display-special', special)
        if key in ['timezone']:
            # Make sure we convert + to /
            settings.setUser('timezone', value.replace('+', '/'))
            helper.timezoneSet(settings.getUser('timezone'))
        if key in ['resolution', 'tvservice']:
            width, height, tvservice = display.setConfiguration(
                value, settings.getUser('display-special'))
            settings.setUser('tvservice', tvservice)
            settings.setUser('width', width)
            settings.setUser('height', height)
            display.enable(True, True)
        if key in ['display-on', 'display-off']:
            timekeeper.setConfiguration(settings.getUser('display-on'),
                                        settings.getUser('display-off'))
        if key in ['autooff-lux', 'autooff-time']:
            timekeeper.setAmbientSensitivity(settings.getUser('autooff-lux'),
                                             settings.getUser('autooff-time'))
        if key in ['powersave']:
            timekeeper.setPowermode(settings.getUser('powersave'))
        if key in ['shutdown-pin']:
            powermanagement.stopmonitor()
            powermanagement = shutdown(settings.getUser('shutdown-pin'))
        settings.save()
        return jsonify({'status': status})

    elif request.method == 'GET':
        if key is None:
            return jsonify(settings.getUser())
        else:
            return jsonify({key: settings.getUser(key)})
    abort(404)
示例#2
0
    def handle(self, app, key, value):
        # Depending on PUT/GET we will either change or read
        # values. If key is unknown, then this call fails with 404
        if key is not None:
            if self.settingsMgr.getUser(key) is None:
                self.abort(404)
                return

        if self.getRequest().method == 'PUT':
            status = True
            if key == "keywords":
                # Keywords has its own API
                self.setAbort(404)
                return
            self.settingsMgr.setUser(key, value)
            if key in ['display-driver']:
                drv = self.settingsMgr.getUser('display-driver')
                if drv == 'none':
                    drv = None
                special = self.driverMgr.activate(drv)
                if special is None:
                    self.settingsMgr.setUser('display-driver', 'none')
                    self.settingsMgr.setUser('display-special', None)
                    status = False
                else:
                    self.settingsMgr.setUser('display-special', special)
            if key in ['timezone']:
                # Make sure we convert + to /
                self.settingsMgr.setUser('timezone', value.replace('+', '/'))
                helper.timezoneSet(self.settingsMgr.getUser('timezone'))
            if key in ['resolution', 'tvservice']:
                width, height, tvservice = self.display.setConfiguration(
                    value, self.settingsMgr.getUser('display-special'))
                self.settingsMgr.setUser('tvservice', tvservice)
                self.settingsMgr.setUser('width', width)
                self.settingsMgr.setUser('height', height)
                self.display.enable(True, True)
                self.cachemgr.empty()
            if key in ['display-on', 'display-off']:
                self.timekeeper.setConfiguration(
                    self.settingsMgr.getUser('display-on'),
                    self.settingsMgr.getUser('display-off'))
            if key in ['autooff-lux', 'autooff-time']:
                self.timekeeper.setAmbientSensitivity(
                    self.settingsMgr.getUser('autooff-lux'),
                    self.settingsMgr.getUser('autooff-time'))
            if key in ['powersave']:
                self.timekeeper.setPowermode(
                    self.settingsMgr.getUser('powersave'))
            if key in ['shutdown-pin']:
                self.powermanagement.stopmonitor()
                self.powermanagement = shutdown(
                    self.settingsMgr.getUser('shutdown-pin'))
            if key in ['imagesizing', 'randomize_images']:
                self.slideshow.createEvent("settingsChange")
            self.settingsMgr.save()
            return self.jsonify({'status': status})

        elif self.getRequest().method == 'GET':
            if key is None:
                return self.jsonify(self.settingsMgr.getUser())
            else:
                return self.jsonify({key: self.settingsMgr.getUser(key)})
        self.setAbort(404)