Esempio n. 1
0
def edit_hosts_file(path, new_hostname):
    try:
        hosts = read_file_contents(path)
        hosts += '\n' + hosts_mod_comment + '\n'
        hosts += '127.0.0.1\t{}\n'.format(new_hostname)
        write_file_contents(path, hosts)
    except:
        logger.error("exception while changing change {}".format(path))
Esempio n. 2
0
    def _ensure_netifnames(self):
        """Add the kernel option ``net.ifnames=0`` to preserve old network
        naming convention"""

        data = read_file_contents(CMDLINE_TXT_PATH)

        if 'net.ifnames=' not in data:
            data = data + ' net.ifnames=0'

        write_file_contents(CMDLINE_TXT_PATH, data)
Esempio n. 3
0
    def _ensure_netifnames(self):
        """Add the kernel option ``net.ifnames=0`` to preserve old network
        naming convention"""

        data = read_file_contents(CMDLINE_TXT_PATH)

        if 'net.ifnames=' not in data:
            data = data + ' net.ifnames=0'

        write_file_contents(CMDLINE_TXT_PATH, data)
Esempio n. 4
0
def save_kano_version():
    """Saves a dict of os-version: time values,
    to keep track of the users update process"""

    updates = load_app_state_variable('kano-tracker', 'versions')
    if not updates:
        updates = dict()

    version_now = read_file_contents('/etc/kanux_version')
    if not version_now:
        return

    version_now = version_now.replace('.', '_')

    time_now = datetime.datetime.utcnow().isoformat()
    updates[version_now] = time_now

    save_app_state_variable('kano-tracker', 'versions', updates)
Esempio n. 5
0
def save_kano_version():
    """Saves a dict of os-version: time values,
    to keep track of the users update process"""

    updates = load_app_state_variable('kano-tracker', 'versions')
    if not updates:
        updates = dict()

    version_now = read_file_contents('/etc/kanux_version')
    if not version_now:
        return

    version_now = version_now.replace('.', '_')

    time_now = datetime.datetime.utcnow().isoformat()
    updates[version_now] = time_now

    save_app_state_variable('kano-tracker', 'versions', updates)
Esempio n. 6
0
def set_parental_enabled(setting, _password):
    logger.debug('set_parental_enabled: {}'.format(setting))

    # turning on
    if setting:
        logger.debug('enabling')

        logger.debug('setting password')
        write_file_contents(password_file, encrypt_password(_password))

        logger.debug('making the file root read-only')
        os.chmod(password_file, 0400)

        logger.debug('enabling parental controls')
        set_parental_level(get_parental_level())

        msg = N_("Parental lock enabled!")
        logger.debug(msg)

        return True, _(msg)

    # turning off
    else:
        # password matches
        if read_file_contents(password_file) == encrypt_password(_password):
            logger.debug('password accepted, disabling')

            logger.debug('clearing password')
            os.remove(password_file)

            logger.debug('disabling parental controls')
            set_parental_level(-1)

            msg = N_("Parental lock disabled!")
            logger.debug(msg)

            return True, _(msg)

        # password doesn't match
        else:
            msg = N_("Password doesn't match\nleaving parental lock enabled!")
            logger.debug(msg)

            return False, _(msg)
Esempio n. 7
0
import time
from uuid import uuid1, uuid5

from kano.utils.hardware import get_cpu_id
from kano.utils.file_operations import read_file_contents, chown_path
from kano.logging import logger
from kano_profile.tracker.tracker_token import TOKEN
from kano_profile.paths import tracker_dir, tracker_events_file, \
    PAUSED_SESSIONS_FILE
from kano_profile.tracker.tracking_session import TrackingSession
from kano_profile.tracker.tracking_utils import open_locked, get_utc_offset


CPU_ID = str(get_cpu_id())
LANGUAGE = (os.getenv('LANG') or '').split('.', 1)[0]
OS_VERSION = str(read_file_contents('/etc/kanux_version'))
os_variant = read_file_contents('/etc/kanux_version_variant')
OS_VERSION += '-' + os_variant if os_variant else ''


def list_sessions():
    return [  # noqa
        f for f in os.listdir(tracker_dir)  # noqa
        if os.path.isfile(os.path.join(tracker_dir, f)) and  # noqa
        os.path.join(tracker_dir, f) != PAUSED_SESSIONS_FILE  # noqa
    ]  # noqa


def get_open_sessions():
    open_sessions = []
def _first_boot():
    track_data(
        'first-boot', {
            'language': (os.getenv('LANG') or '').split('.', 1)[0],
            'variant': read_file_contents('/etc/kanux_version_variant')
        })
def _first_boot():
    track_data('first-boot', {
        'language': (os.getenv('LANG') or '').split('.', 1)[0],
        'variant': read_file_contents('/etc/kanux_version_variant')
    })
Esempio n. 10
0
def authenticate_parental_password(passwd):
    return read_file_contents(password_file) == encrypt_password(passwd)