Beispiel #1
0
def set_locale_param(param, locale, skip_check=False):
    # FIXME: Don't use the .xsessionrc file to set the locale
    XSESSION_RC_FILE = os.path.join(get_home_by_username(get_user_unsudoed()),
                                    '.xsessionrc')
    if not skip_check and not is_locale_installed(locale):
        install_locale(locale)

    param_found = False
    new_param_line = 'export {}={}'.format(param, locale)
    new_config_file = []

    if os.path.exists(XSESSION_RC_FILE):
        xsession_file = read_file_contents_as_lines(XSESSION_RC_FILE)

        for line in xsession_file:
            if param in line:
                line = new_param_line
                param_found = True

            new_config_file.append(line)

    if not param_found:
        new_config_file.append(new_param_line)

    with open(XSESSION_RC_FILE, 'w') as conf_file:
        conf_file.write('\n'.join(new_config_file))

    chown_path(XSESSION_RC_FILE)
Beispiel #2
0
def set_locale_param(param, locale, skip_check=False):
    # FIXME: Don't use the .xsessionrc file to set the locale
    XSESSION_RC_FILE = os.path.join(get_home_by_username(get_user_unsudoed()),
                                    '.xsessionrc')
    if not skip_check and not is_locale_installed(locale):
        install_locale(locale)

    param_found = False
    new_param_line = 'export {}={}'.format(param, locale)
    new_config_file = []

    if os.path.exists(XSESSION_RC_FILE):
        xsession_file = read_file_contents_as_lines(XSESSION_RC_FILE)

        for line in xsession_file:
            if param in line:
                line = new_param_line
                param_found = True

            new_config_file.append(line)

    if not param_found:
        new_config_file.append(new_param_line)

    with open(XSESSION_RC_FILE, 'w') as conf_file:
        conf_file.write('\n'.join(new_config_file))

    chown_path(XSESSION_RC_FILE)
Beispiel #3
0
from kano.utils import get_home_by_username

LOG_ENV = "LOG_LEVEL"
OUTPUT_ENV = "OUTPUT_LEVEL"
FORCE_FLUSH_ENV = "KLOG_FORCE_FLUSH"
SYSTEM_LOGS_DIR = "/var/log/kano/"

# The length to which will the log files be cut to when cleaned up
TAIL_LENGTH = 500

# get_user_unsudoed() cannot be used due to a circular dependency
is_sudoed = 'SUDO_USER' in os.environ
usr = os.getenv("SUDO_USER") if is_sudoed else pwd.getpwuid(os.getuid())[0]

try:
    home_folder = get_home_by_username(usr)
except KeyError:  # user doesn't exist
    if is_sudoed:
        # something weird happened with sudo
        # fall back to the root user
        usr = "******"
        home_folder = "/root/"
    else:
        raise

USER_LOGS_DIR = os.path.join(home_folder, '.kano-logs')

CONF_FILE = "/etc/kano-logs.conf"

LEVELS = {
    "none": 0,
#!/usr/bin/env python
# This file needs to be prepended to tutorial files, for
# them to work

import os
import sys

from kano.utils import get_user_unsudoed, get_home_by_username
DIR_PATH = os.path.join(get_home_by_username(get_user_unsudoed()),
                        'make-light')

if __name__ == '__main__' and __package__ is None:
    if DIR_PATH != '/usr':
        sys.path.insert(1, DIR_PATH)

from make_light.boards.base.aliases import *
from time import *
import time
from datetime import datetime
import datetime
from random import *
import random
from math import *
import math
import os

debug = False
simulation = False
token = ''

if 'POWERUP_DEBUG' in os.environ:
Beispiel #5
0
from kano.utils import get_home_by_username

LOG_ENV = "LOG_LEVEL"
OUTPUT_ENV = "OUTPUT_LEVEL"
FORCE_FLUSH_ENV = "KLOG_FORCE_FLUSH"
SYSTEM_LOGS_DIR = "/var/log/kano/"

# The length to which will the log files be cut to when cleaned up
TAIL_LENGTH = 500

# get_user_unsudoed() cannot be used due to a circular dependency
is_sudoed = 'SUDO_USER' in os.environ
usr = os.getenv("SUDO_USER") if is_sudoed else pwd.getpwuid(os.getuid())[0]

try:
    home_folder = get_home_by_username(usr)
except KeyError:  # user doesn't exist
    if is_sudoed:
        # something weird happened with sudo
        # fall back to the root user
        usr = "******"
        home_folder = "/root/"
    else:
        raise

USER_LOGS_DIR = os.path.join(home_folder, '.kano-logs')

CONF_FILE = "/etc/kano-logs.conf"

LEVELS = {"none": 0, "error": 1, "warning": 2, "info": 3, "debug": 4}
Beispiel #6
0
#!/usr/bin/env python

# paths.py
#
# Copyright (C) 2014, 2015 Kano Computing Ltd.
# License: http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
#

import os

from kano.logging import logger
from kano.utils import get_user_unsudoed, get_home_by_username

linux_user = get_user_unsudoed()
home_directory = get_home_by_username(linux_user)

# setting up directories
dir_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))

# rules path
rules_local = os.path.join(dir_path, 'rules')
rules_usr = '******'
if os.path.exists(rules_local):
    rules_dir = rules_local
elif os.path.exists(rules_usr):
    rules_dir = rules_usr
else:
    logger.warn('Neither local nor usr rules found!')

# bin path
bin_local = os.path.join(dir_path, 'bin')
Beispiel #7
0
#!/usr/bin/env python
# This file needs to be prepended to tutorial files, for
# them to work

import os
import sys

from kano.utils import get_user_unsudoed, get_home_by_username
DIR_PATH = os.path.join(
    get_home_by_username(get_user_unsudoed()), 'make-light'
)

if __name__ == '__main__' and __package__ is None:
    if DIR_PATH != '/usr':
        sys.path.insert(1, DIR_PATH)

from make_light.boards.base.aliases import *
from time import *
import time
from datetime import datetime
import datetime
from random import *
import random
from math import *
import math
import os

debug = False
simulation = False
token = ''
Beispiel #8
0
#!/usr/bin/env python

# paths.py
#
# Copyright (C) 2014, 2015 Kano Computing Ltd.
# License: http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2
#

import os

from kano.logging import logger
from kano.utils import get_user_unsudoed, get_home_by_username

linux_user = get_user_unsudoed()
home_directory = get_home_by_username(linux_user)

# setting up directories
dir_path = os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))

# rules path
rules_local = os.path.join(dir_path, 'rules')
rules_usr = '******'
if os.path.exists(rules_local):
    rules_dir = rules_local
elif os.path.exists(rules_usr):
    rules_dir = rules_usr
else:
    logger.warn("Neither local nor usr rules found!")

# bin path
bin_local = os.path.join(dir_path, 'bin')

# TODO: Make this safety measure cleaner
if not hasattr(__builtins__, '_'):
    def _(s):
        return s

import re
import os
from kano.utils import run_cmd, read_file_contents, sed, enforce_root, \
    read_file_contents_as_lines, get_user_unsudoed, get_home_by_username, \
    chown_path

SUPPORTED_LIST_FILE = '/usr/share/i18n/SUPPORTED'
LOCALE_GEN_FILE = '/etc/locale.gen'
XSESSION_RC_FILE = os.path.join(get_home_by_username(get_user_unsudoed()),
                                '.xsessionrc')
LOCALE_PARAMS = [
    # 'LANG',  # Determines the default locale in the absence of other locale related environment variables
    'LANGUAGE',  #
    'LC_ADDRESS',  # Convention used for formatting of street or postal addresses
    'LC_COLLATE',  # Collation order
    'LC_CTYPE',  # Character classification and case conversion
    'LC_MONETARY',  # Monetary formatting
    'LC_MEASUREMENT',  # Default measurement system used within the region
    'LC_MESSAGES',  # Format of interactive words and responses
    'LC_NUMERIC',  # Numeric formatting
    'LC_PAPER',  # Default paper size for region
    'LC_RESPONSE',  # Determines how responses (such as Yes and No) appear in the local language
    'LC_TELEPHONE',  # Conventions used for representation of telephone numbers
    'LC_TIME'  # Date and time formats