Exemple #1
0
def cfg_keyvalue(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 settings.getUser(key) is None:
            abort(404)
            return

    if request.method == 'PUT':
        if key == "keywords":
            # Keywords has its own API
            abort(404)
            return
        settings.setUser(key, value)
        settings.save()
        if key in ['width', 'height', 'depth', 'tvservice']:
            display.setConfiguration(settings.getUser('width'),
                                     settings.getUser('height'),
                                     settings.getUser('depth'),
                                     settings.getUser('tvservice'))
            display.enable(True, True)
        if key in ['display-on', 'display-off']:
            timekeeper.setConfiguration(settings.getUser('display-on'),
                                        settings.getUser('display-off'))
        return jsonify({'status': True})

    elif request.method == 'GET':
        if key is None:
            return jsonify(settings.getUser())
        else:
            return jsonify({key: settings.getUser(key)})
    abort(404)
Exemple #2
0
def upload(item):
    retval = {'status': 200, 'return': {}}

    if request.method == 'POST':
        # check if the post request has the file part
        if 'filename' not in request.files:
            logging.error('No file part')
            abort(405)
        file = request.files['filename']
        if item == 'driver':
            # if user does not select file, browser also
            # submit an empty part without filename
            if file.filename == '' or not file.filename.lower().endswith(
                    '.zip'):
                logging.error('No filename or invalid filename')
                abort(405)
        filename = os.path.join('/tmp/', secure_filename(file.filename))
        file.save(filename)

        if item == 'driver':
            result = drivers.install(filename)
            if result is not False:
                # Check and see if this is the driver we're using
                if result['driver'] == settings.getUser('display-driver'):
                    # Yes it is, we need to activate it and return info about restarting
                    special = drivers.activate(result['driver'])
                    if special is None:
                        settings.setUser('display-driver', 'none')
                        settings.setUser('display-special', None)
                        retval['status'] = 500
                    else:
                        settings.setUser('display-special', special)
                        retval['return'] = {'reboot': True}
                else:
                    retval['return'] = {'reboot': False}

        try:
            os.remove(filename)
        except:
            pass
        if retval['status'] == 200:
            return jsonify(retval['return'])
        abort(retval['status'])
    abort(405)
Exemple #3
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)
            CacheManager.empty(settings.CACHEFOLDER)
        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'))
        if key in ['imagesizing', 'randomize_images']:
            slideshow.createEvent("settingsChange")
        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)
Exemple #4
0
settings = settings()
drivers = drivers()

m = re.search('([0-9]+)x([0-9]+)', cmdline.size)
if m is None:
    logging.error('--size has to be WIDTHxHEIGHT')
    sys.exit(1)

display = display(cmdline.emulate, int(m.group(1)), int(m.group(2)))

if not settings.load():
    # First run, grab display settings from current mode
    current = display.current()
    if current is not None:
        logging.info('No display settings, using: %s' % repr(current))
        settings.setUser('tvservice',
                         '%s %s HDMI' % (current['mode'], current['code']))
        settings.save()
    else:
        logging.info('No display attached?')
if settings.getUser('timezone') == '':
    settings.setUser('timezone', helper.timezoneCurrent())
    settings.save()

width, height, tvservice = display.setConfiguration(
    settings.getUser('tvservice'), settings.getUser('display-special'))
settings.setUser('tvservice', tvservice)
settings.setUser('width', width)
settings.setUser('height', height)
settings.save()

# Force display to desired user setting
Exemple #5
0
        return app.send_static_file(file)


@app.route('/template/<file>')
@auth.login_required
def web_template(file):
    return app.send_static_file('template/' + file)


settings = settings()
if not settings.load():
    # First run, grab display settings from current mode
    current = display.current()
    logging.info('No display settings, using: %s' % repr(current))
    settings.setUser(
        'tvservice',
        '%s %s %s' % (current['group'], current['mode'], current['drive']))
    settings.setUser('width', int(current['width']))
    settings.setUser('height', int(current['height']))
    settings.save()

display = display(settings.getUser('width'), settings.getUser('height'),
                  settings.getUser('depth'), settings.getUser('tvservice'))

# Force display to desired user setting
display.enable(True, True)

# Spin until we have internet, check every 10s
while True:
    settings.set('local-ip', helper.getIP())