Exemplo n.º 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)
Exemplo n.º 2
0
    def __init__(self, cmdline):
        self.void = open(os.devnull, 'wb')
        random.seed(long(time.clock()))

        self.emulator = cmdline.emulate
        if self.emulator:
            self.enableEmulation()
        if cmdline.basedir is not None:
            self.changeRoot(cmdline.basedir)
        if not path().validate():
            sys.exit(255)

        self.cacheMgr = CacheManager()
        self.settingsMgr = settings()
        self.driverMgr = drivers()
        self.displayMgr = display(self.emulator)
        self.serviceMgr = ServiceManager(self.settingsMgr, self.cacheMgr)

        self.colormatch = colormatch(
            self.settingsMgr.get('colortemp-script'),
            2700)  # 2700K = Soft white, lowest we'll go
        self.slideshow = slideshow(self.displayMgr, self.settingsMgr,
                                   self.colormatch)
        self.timekeeperMgr = timekeeper(self.displayMgr.enable,
                                        self.slideshow.start)
        self.powerMgr = shutdown(self.settingsMgr.getUser('shutdown-pin'))

        # Validate all settings, prepopulate with defaults if needed
        self.validateSettings()

        self.cacheMgr.validate()
        self.cacheMgr.enableCache(
            self.settingsMgr.getUser('enable-cache') == 1)

        # Tie all the services together as needed
        self.timekeeperMgr.setConfiguration(
            self.settingsMgr.getUser('display-on'),
            self.settingsMgr.getUser('display-off'))
        self.timekeeperMgr.setAmbientSensitivity(
            self.settingsMgr.getUser('autooff-lux'),
            self.settingsMgr.getUser('autooff-time'))
        self.timekeeperMgr.setPowermode(self.settingsMgr.getUser('powersave'))
        self.colormatch.setUpdateListener(self.timekeeperMgr.sensorListener)

        self.slideshow.setQueryPower(self.timekeeperMgr.getDisplayOn)
        self.slideshow.setServiceManager(self.serviceMgr)
        self.slideshow.setCacheManager(self.cacheMgr)
        self.slideshow.setCountdown(cmdline.countdown)

        # Prep the webserver
        self.setupWebserver(cmdline.listen, cmdline.port)

        # Force display to desired user setting
        self.displayMgr.enable(True, True)
Exemplo n.º 3
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)
Exemplo n.º 4
0
# Let the display know the URL to use
display.setConfigPage('http://%s:%d/' % (settings.get('local-ip'), 7777))

# Prep random
random.seed(long(time.clock()))
colormatch = colormatch(settings.get('colortemp-script'),
                        2700)  # 2700K = Soft white, lowest we'll go
slideshow = slideshow(display, settings, colormatch)
timekeeper = timekeeper(display.enable, slideshow.start)
slideshow.setQueryPower(timekeeper.getDisplayOn)
slideshow.setServiceManager(services)

timekeeper.setConfiguration(settings.getUser('display-on'),
                            settings.getUser('display-off'))
timekeeper.setAmbientSensitivity(settings.getUser('autooff-lux'),
                                 settings.getUser('autooff-time'))
timekeeper.setPowermode(settings.getUser('powersave'))
colormatch.setUpdateListener(timekeeper.sensorListener)

powermanagement = shutdown(settings.getUser('shutdown-pin'))

if __name__ == "__main__":
    # This allows us to use a plain HTTP callback
    os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'
    app.secret_key = os.urandom(24)
    slideshow.start()
    app.run(debug=False, port=cmdline.port, host=cmdline.listen)

sys.exit(0)
Exemplo n.º 5
0
def oauthSetToken(token):
    settings.set('oauth_token', token)


oauth = OAuth(settings.get('local-ip'), oauthSetToken, oauthGetToken)

if os.path.exists('/root/oauth.json'):
    with open('/root/oauth.json') as f:
        data = json.load(f)
    if 'web' in data:  # if someone added it via command-line
        data = data['web']
    oauth.setOAuth(data)

# Prep random
random.seed(long(time.clock()))
slideshow = slideshow(display, settings, oauth)
timekeeper = timekeeper(display.enable, slideshow.start)
timekeeper.setConfiguration(settings.getUser('display-on'),
                            settings.getUser('display-off'))
powermanagement = shutdown()

if __name__ == "__main__":
    # This allows us to use a plain HTTP callback
    os.environ['OAUTHLIB_INSECURE_TRANSPORT'] = '1'
    app.secret_key = os.urandom(24)
    slideshow.start()
    app.run(debug=False, port=cmdline.port, host=cmdline.listen)

sys.exit(0)