# Path: kano_settings/config_file.py
# def get_setting(variable):
# 
#     try:
#         value = read_json(settings_file)[variable]
#     except Exception:
#         if variable not in DEFAULTS:
#             logger.info("Defaults not found for variable: {}".format(variable))
#         value = DEFAULTS[variable]
#     return value
# 
# def set_setting(variable, value):
# 
#     if username == 'root':
#         return
# 
#     logger.debug(u"config_file / set_setting: {} {}".format(variable, value))
# 
#     data = read_json(settings_file)
#     if not data:
#         data = dict()
# 
#     data[variable] = value
#     write_json(settings_file, data)
#     chown_path(settings_file)


from kano.logging import logger
from kano.utils.shell import run_cmd
from kano.utils.file_operations import sed
from kano_settings.config_file import get_setting, set_setting
import kano_settings.system.keyboard_layouts as keyboard_layouts
import kano_settings.system.locale as locale
        if variant_desc == variant or variant_id == variant:
            found = True
            break

    variant_idx = idx if found else 0

    update_settings_keyboard_conf(
        continent_idx,
        country_idx,
        variant_idx,
        continent,
        country,
        variant
    )


def set_keyboard(locale_code, variant, save=False):
    if variant == 'generic':
        variant = ''

    # Notify and apply changes to the XServer
    run_cmd("setxkbmap {} {}".format(locale_code, variant))
    set_keyboard_config(locale.split_locale(locale_code)[0], variant)
    run_cmd("ACTIVE_CONSOLE=guess /bin/setupcon -k </dev/tty1")

    if save:
        save_keyboard_settings(locale_code, variant)


def set_saved_keyboard():

# Path: kano_settings/config_file.py
# def get_setting(variable):
# 
#     try:
#         value = read_json(settings_file)[variable]
#     except Exception:
#         if variable not in DEFAULTS:
#             logger.info("Defaults not found for variable: {}".format(variable))
#         value = DEFAULTS[variable]
#     return value
# 
# def set_setting(variable, value):
# 
#     if username == 'root':
#         return
# 
#     logger.debug(u"config_file / set_setting: {} {}".format(variable, value))
# 
#     data = read_json(settings_file)
#     if not data:
#         data = dict()
# 
#     data[variable] = value
#     write_json(settings_file, data)
#     chown_path(settings_file)


# Path: kano_settings/system/keyboard_config.py
from kano.logging import logger
from kano.utils.shell import run_cmd
from kano.utils.file_operations import sed
from kano_settings.config_file import get_setting, set_setting
import kano_settings.system.keyboard_layouts as keyboard_layouts
import kano_settings.system.locale as locale

        if variant_desc == variant or variant_id == variant:
            found = True
            break

    variant_idx = idx if found else 0

    update_settings_keyboard_conf(
        continent_idx,
        country_idx,
        variant_idx,
        continent,
        country,
        variant
    )


def set_keyboard(locale_code, variant, save=False):
    if variant == 'generic':
        variant = ''

    # Notify and apply changes to the XServer
    run_cmd("setxkbmap {} {}".format(locale_code, variant))
    set_keyboard_config(locale.split_locale(locale_code)[0], variant)
    run_cmd("ACTIVE_CONSOLE=guess /bin/setupcon -k </dev/tty1")

    if save:
        save_keyboard_settings(locale_code, variant)


def set_saved_keyboard():

    continent = get_setting('Keyboard-continent-human')