Exemple #1
0
def set_lang():
    lang = 'it'
    if request.args.get('lang'):
        lang = request.args.get('lang')

    logger.write(Logging.DEB, "Setting language to: " + lang)
    config_data = {'lang': lang}
    FileManagement.update_json(config_path, config_data, log_path)

    return redirect('/')
Exemple #2
0
def submit():
    logger.write(Logging.INF, "Applying config")
    if 'apply' in request.form:
        try:
            colour = request.form.get('colour-picker')
            pattern_type = request.form.getlist('pattern-options')
            brightness = request.form.get('colour-brightness')

            if pattern_type is not None and len(pattern_type) > 0:
                pattern_type = pattern_type[0]

            logger.write(
                Logging.DEB, "Config change: " + colour + ", " + pattern_type +
                ", " + brightness)
            config_data = {
                colour_key: colour,
                pattern_key: pattern_type,
                'brightness': brightness,
                'ip': ip
            }

            FileManagement.update_json(config_path, config_data, log_path)
        except Exception as e:
            logger.write(Logging.ERR,
                         "Error when saving config change: " + str(e))
            config_data = DataExtraction.fix_config_data(
                FileManagement.read_json(config_path, log_path), colour_key,
                pattern_key, brightness_key, config_path, log_path)

            translation_json = {}
            if config_data['lang'] in language_set:
                translation_json = FileManagement.read_json(
                    translations_dir_path + config_data['lang'] + '.json',
                    log_path)

            translations_config_fail = {'TITLE': "", 'MESSAGE': ""}

            if 'TITLE_CONFIG_FAIL' in translation_json:
                translations_config_fail['TITLE'] = translation_json[
                    'TITLE_CONFIG_FAIL']

            if 'MESSAGE_CONFIG_FAIL' in translation_json:
                translations_config_fail['MESSAGE'] = translation_json[
                    'MESSAGE_CONFIG_FAIL']

            return render_template('/sub_page.html',
                                   translations=translations_config_fail,
                                   lang=config_data['lang'],
                                   have_home=True), 500

    elif 'cancel' in request.form:
        logger.write(Logging.DEB, "Cancel clicked, so reseting page")

    return redirect('/')
Exemple #3
0
def libra():
    logger.write(Logging.DEB, "Libra page")
    config_data = DataExtraction.fix_config_data(
        FileManagement.read_json(config_path, log_path), colour_key,
        pattern_key, brightness_key, config_path, log_path)

    if 'lang' not in config_data or not config_data['lang']:
        config_data['lang'] = 'it'
        FileManagement.update_json(config_path, config_data, log_path)

    translation_json = {}
    if config_data['lang'] in language_set:
        translation_json = FileManagement.read_json(
            translations_dir_path + config_data['lang'] + '.json', log_path)

    return render_template('/libra.html',
                           colour_key=colour_key,
                           config_data=config_data,
                           translations=translation_json)
Exemple #4
0
                ip = sys.argv[1]
                logger.write(Logging.INF,
                             "IP address passed from rc.local: " + ip)

    for file in os.listdir(translations_dir_path):
        if file.endswith('.json'):
            language_set.add(os.path.splitext(file)[0])

    if ip is None:
        for attempt in range(10):
            try:
                ip = get_ip()
                if ip is not None:
                    logger.write(Logging.INF, "IP address found socket: " + ip)

                    FileManagement.update_json(config_path, {'ip': ip},
                                               log_path)
                    app.run(debug=True, host='0.0.0.0')

                    break

            except Exception as e:
                logger.write(Logging.ERR,
                             "Unable to get Hostname and IP: " + str(e))

            time.sleep(1)

        if ip is None:
            FileManagement.update_json(config_path, {'ip': ''}, log_path)


def exit_handler():