Example #1
0
    def _write_char_log_file(self, fname):
        """ Creates a file that includes the avatar configuration used when
        the rest of the assets where created as a label. The purpose of this
        file is to avoid the time consuming process of recreating assets that
        are already present and updated.
        :param fname: filename for the configuration file to be created
        :returns: False iff some error occurs
        :rtype: Boolean
        """
        if self._sel_char is None:
            logger.warn(
                "Character not selected, will abandon writing log file")
            return False

        if self._sel_env is None:
            logger.warn(
                "Environment not selected, will abandon writing log file")
            return False

        created_file = False
        with open(fname, 'w') as fp:
            obj_av = {}
            # ensure that environments is not present in this dict
            items = self.selected_items_per_cat()
            items.pop(self.env_label, None)
            obj_av['avatar'] = [self._sel_char.get_id(), items]
            obj_av['environment'] = self._sel_env.get_id()
            obj_av['date_created'] = get_date_now()
            dump(obj_av, fp)
            created_file = True

        return created_file
Example #2
0
def save_app_state_variable_all_users(app, variable, value):
    if os.environ['LOGNAME'] != 'root':
        logger.error("Error: save_app_state_variable_all_users must be executed with root privileges")
        return

    users = get_all_users()

    for user in users:
        dir_path = os.path.join(
            "/home", user, ".kanoprofile", "apps", app
        )
        if not os.path.exists(dir_path):
            os.makedirs(dir_path)
            chown_path(dir_path, user, user)

        state_path = os.path.join(dir_path, "state.json")
        data = {variable: value}
        data['save_date'] = get_date_now()
        write_json(state_path, data)
        chown_path(state_path, user, user)
Example #3
0
def save_profile(data):
    ''' Write profile data to file
    :param data: JSON serialisable data about the profile
    '''
    logger.debug('save_profile')

    data.pop('cpu_id', None)
    data.pop('mac_addr', None)
    data['save_date'] = get_date_now()
    ensure_dir(profile_dir)
    write_json(profile_file, data)

    if 'SUDO_USER' in os.environ:
        chown_path(kanoprofile_dir)
        chown_path(profile_dir)
        chown_path(profile_file)

    if os.path.exists('/usr/bin/kdesk') and not is_running('kano-sync'):
        logger.info('refreshing kdesk from save_profile')
        run_bg('kdesk -a profile')
Example #4
0
def save_app_state_variable_all_users(app, variable, value):
    if os.environ['LOGNAME'] != 'root':
        logger.error(
            "Error: save_app_state_variable_all_users must be executed with root privileges"
        )
        return

    users = get_all_users()

    for user in users:
        dir_path = os.path.join("/home", user, ".kanoprofile", "apps", app)
        if not os.path.exists(dir_path):
            os.makedirs(dir_path)
            chown_path(dir_path, user, user)

        state_path = os.path.join(dir_path, "state.json")
        data = {variable: value}
        data['save_date'] = get_date_now()
        write_json(state_path, data)
        chown_path(state_path, user, user)
def save_app_state(app_name, data):
    """ Save a state of an application to the user's Kano profile.

        :param app_name: The application that this data are associated with.
        :type app_name: str

        :param data: The data to be stored.
        :type data: dict
    """

    logger.debug('save_app_state {}'.format(app_name))

    app_state_file = get_app_state_file(app_name)
    data['save_date'] = get_date_now()
    ensure_dir(get_app_dir(app_name))
    write_json(app_state_file, data)
    if 'SUDO_USER' in os.environ:
        chown_path(kanoprofile_dir)
        chown_path(apps_dir)
        chown_path(get_app_dir(app_name))
        chown_path(app_state_file)
Example #6
0
def save_app_state(app_name, data):
    """ Save a state of an application to the user's Kano profile.

        :param app_name: The application that this data are associated with.
        :type app_name: str

        :param data: The data to be stored.
        :type data: dict
    """

    logger.debug("save_app_state {}".format(app_name))

    app_state_file = get_app_state_file(app_name)
    data['save_date'] = get_date_now()
    ensure_dir(get_app_dir(app_name))
    write_json(app_state_file, data)
    if 'SUDO_USER' in os.environ:
        chown_path(kanoprofile_dir)
        chown_path(apps_dir)
        chown_path(get_app_dir(app_name))
        chown_path(app_state_file)
Example #7
0
def save_profile(data, skip_kdesk_refresh=False):
    ''' Write profile data to file
    :param data: JSON serialisable data about the profile
    '''
    logger.debug('save_profile')

    data.pop('cpu_id', None)
    data.pop('mac_addr', None)
    data['save_date'] = get_date_now()
    ensure_dir(profile_dir)
    write_json(profile_file, data)

    if 'SUDO_USER' in os.environ:
        chown_path(kanoprofile_dir)
        chown_path(profile_dir)
        chown_path(profile_file)

    if (not skip_kdesk_refresh and
            os.path.exists('/usr/bin/kdesk') and
            not is_running('kano-sync')):
        logger.info("refreshing kdesk from save_profile")
        run_bg('kdesk -a profile')