Exemplo n.º 1
0
    def __init__(self):
        self.width = 646
        self.height = 88

        apps = get_app_list()

        self.projects_list = []

        for app in apps:
            if app in app_profiles:
                if 'ext' in app_profiles[app]:
                    if app_profiles[app]['dir'] == 'kanoprofile':
                        data_dir = get_app_data_dir(app)
                    else:
                        data_dir = os.path.join(get_home(), app_profiles[app]['dir'])

                    icon_path = os.path.join(image_dir, 'icons', app_profiles[app]['icon'])

                    if not os.path.exists(data_dir):
                        continue

                    files = os.listdir(data_dir)
                    files_filtered = [f for f in files if os.path.splitext(f)[1][1:] == app_profiles[app]['ext']]

                    for filename in files_filtered:
                        project = dict()
                        project['app'] = app
                        project['data_dir'] = data_dir
                        project['file'] = filename
                        project['display_name'] = os.path.splitext(filename)[0]
                        project['icon'] = icon_path
                        self.projects_list.append(project)

        self.background = Gtk.EventBox()
        self.background.get_style_context().add_class("project_list_background")

        self.container = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=20)

        self.align = Gtk.Alignment(xalign=0.5, yalign=0.5)
        self.align.set_padding(10, 10, 20, 20)
        self.align.add(self.container)
        self.background.add(self.align)

        if not self.projects_list:
            image_no_projects = icons.set_from_name("no_challenges")
            image_no_projects.set_margin_top(70)
            self.container.pack_start(image_no_projects, False, False, 0)
            return

        for i, project in enumerate(self.projects_list):
            item = ProjectItem(project)
            self.container.pack_start(item.background, False, False, 0)
Exemplo n.º 2
0
def download_share(entry):
    app = entry['app']
    title = entry['title']
    description = entry['description']
    attachment_url = entry['attachment_url']
    cover_url = entry['cover_url']
    resource_url = entry['resource_url']

    data = {
        'title': title,
        'description': description
    }

    app_profiles = read_json(app_profiles_file)

    if app not in app_profiles:
        logger.error("Cannot download share, app not found in app-profiles")
        return

    app_profile = app_profiles[app]

    folder = os.path.join(get_home(), app_profile['dir'], 'webload')
    ensure_dir(folder)

    title_slugified = slugify(title)

    # Download attachment
    attachment_ext = attachment_url.split('.')[-1]
    attachment_name = '{}.{}'.format(title_slugified, attachment_ext)
    attachment_path = os.path.join(folder, attachment_name)

    success, text = download_url(attachment_url, attachment_path)
    if not success:
        msg = "Error with downloading share file: {}".format(text)
        logger.error(msg)
        return False, msg

    # Download screenshot
    if cover_url:
        cover_ext = cover_url.split('.')[-1]
        cover_name = '{}.{}'.format(title_slugified, cover_ext)
        cover_path = os.path.join(folder, cover_name)

        success, text = download_url(cover_url, cover_path)
        if not success:
            msg = "Error with downloading cover file: {}".format(text)
            logger.error(msg)
            return False, msg

    # Download resource file
    if resource_url:
        resource_ext = resource_url.split('.')[-1]
        # Make sure we don't remove the tar from gz
        if 'tar.gz' in resource_url:
            resource_ext = 'tar.' + resource_ext
        resource_name = '{}.{}'.format(title_slugified, resource_ext)
        resource_path = os.path.join(folder, resource_name)

        success, text = download_url(resource_url, resource_path)
        if not success:
            msg = "Error with downloading resource file: {}".format(text)
            logger.error(msg)
            return False, msg

    # JSON file
    json_name = '{}.{}'.format(title_slugified, 'json')
    json_path = os.path.join(folder, json_name)
    write_json(json_path, data)
    return True, [title, attachment_path, app, attachment_name, folder]
Exemplo n.º 3
0
#
# Path constants
#
# Copyright (C) 2015 Kano Computing Ltd.
# License: http://www.gnu.org/licenses/gpl-2.0.txt GNU GPL v2
#

import os

from kano.utils import get_home

OLD_FIRST_BOOT_FILE = os.path.join(get_home(), '.kano-settings/first_boot')
STATUS_FILE_PATH = os.path.join(get_home(), '.init-flow.json')


def get_asset_path(stage_path, directory, filename):
    '''
        :params stage_path: the path of the current stage
        :type stage_path: str

        :params directory: the directory name we're interested in
        :type directory: str

        :params filename: the name of the file
        :type filename: str
    '''
    stage_dir = os.path.dirname(os.path.abspath(stage_path))
    path = os.path.join(stage_dir, directory, filename)

    if not os.path.exists(path):
        raise OSError("Path {} doesn't exist".format(path))
Exemplo n.º 4
0
#
# Path constants
#
# Copyright (C) 2015 Kano Computing Ltd.
# License: http://www.gnu.org/licenses/gpl-2.0.txt GNU GPL v2
#

import os

from kano.utils import get_home


OLD_FIRST_BOOT_FILE = os.path.join(get_home(), '.kano-settings/first_boot')
STATUS_FILE_PATH = os.path.join(get_home(), '.init-flow.json')


def get_asset_path(stage_path, directory, filename):
    '''
        :params stage_path: the path of the current stage
        :type stage_path: str

        :params directory: the directory name we're interested in
        :type directory: str

        :params filename: the name of the file
        :type filename: str
    '''
    stage_dir = os.path.dirname(os.path.abspath(stage_path))
    path = os.path.join(stage_dir, directory, filename)

    if not os.path.exists(path):
Exemplo n.º 5
0
def download_share(entry):
    app = entry['app']
    title = entry['title']
    description = entry['description']
    attachment_url = entry['attachment_url']
    cover_url = entry['cover_url']
    resource_url = entry['resource_url']

    data = {'title': title, 'description': description}

    app_profiles = read_json(app_profiles_file)

    if app not in app_profiles:
        logger.error("Cannot download share, app not found in app-profiles")
        return

    app_profile = app_profiles[app]

    folder = os.path.join(get_home(), app_profile['dir'], 'webload')
    ensure_dir(folder)

    title_slugified = slugify(title)

    # Download attachment
    attachment_ext = attachment_url.split('.')[-1]
    attachment_name = '{}.{}'.format(title_slugified, attachment_ext)
    attachment_path = os.path.join(folder, attachment_name)

    success, text = download_url(attachment_url, attachment_path)
    if not success:
        msg = "Error with downloading share file: {}".format(text)
        logger.error(msg)
        return False, msg

    # Download screenshot
    if cover_url:
        cover_ext = cover_url.split('.')[-1]
        cover_name = '{}.{}'.format(title_slugified, cover_ext)
        cover_path = os.path.join(folder, cover_name)

        success, text = download_url(cover_url, cover_path)
        if not success:
            msg = "Error with downloading cover file: {}".format(text)
            logger.error(msg)
            return False, msg

    # Download resource file
    if resource_url:
        resource_ext = resource_url.split('.')[-1]
        # Make sure we don't remove the tar from gz
        if 'tar.gz' in resource_url:
            resource_ext = 'tar.' + resource_ext
        resource_name = '{}.{}'.format(title_slugified, resource_ext)
        resource_path = os.path.join(folder, resource_name)

        success, text = download_url(resource_url, resource_path)
        if not success:
            msg = "Error with downloading resource file: {}".format(text)
            logger.error(msg)
            return False, msg

    # JSON file
    json_name = '{}.{}'.format(title_slugified, 'json')
    json_path = os.path.join(folder, json_name)
    write_json(json_path, data)
    return True, [title, attachment_path, app, attachment_name, folder]
Exemplo n.º 6
0
# paths.py
#
# Copyright (C) 2015 Kano Computing Ltd.
# License: http://www.gnu.org/licenses/gpl-2.0.txt GNU GPL v2
#
# Path constants for character creation

import os
from kano.utils import get_home, get_user
from kano_content.extended_paths import content_dir

AVATAR_SCRATCH = os.path.join(
    '/tmp/', get_user(), 'char_gen_scratch', 'character.png')
AVATAR_DEFAULT_LOC = os.path.join(get_home(), '.character-content')
AVATAR_DEFAULT_NAME = 'character.png'
AVATAR_ENV_DEFAULT = 'character_inc_env.png'
AVATAR_ENV_SHIFTED = 'character_inc_env_page2.png'
AVATAR_CIRC_PLAIN_DEFAULT = 'character_circ_plain.png'
AVATAR_SELECTED_ITEMS = os.path.join(AVATAR_DEFAULT_LOC, 'character_log.json')
AVATAR_OVERWORLD = os.path.join(get_home(), '.local/share/love/kanoOverworld/res/images/avatar.png')
AVATAR_PONG = os.path.join(get_home(), '.local/share/love/kanoPong/res/images/avatar.png')

AVATAR_CONF_FILE = '/usr/share/kano-profile/rules/avatar_generator/conf.json'
PROFILE_IMAGES_FOLDER = '/usr/share/kano-profile/media/images'
AVATAR_ASSET_FOLDER = os.path.join(PROFILE_IMAGES_FOLDER, 'avatar_generator')
CSS_PATH = '/usr/share/kano-profile/media/CSS/avatar_generator.css'

CHARACTER_DIR = os.path.join(AVATAR_ASSET_FOLDER, 'characters')
CHARACTER_OVERWORLD_DIR = os.path.join(AVATAR_ASSET_FOLDER, 'characters_overworld')
ENVIRONMENT_DIR = os.path.join(
    PROFILE_IMAGES_FOLDER, 'environments', '734x404', 'all')
Exemplo n.º 7
0
# paths.py
#
# Copyright (C) 2015 Kano Computing Ltd.
# License: http://www.gnu.org/licenses/gpl-2.0.txt GNU GPL v2
#
# Path constants for character creation

import os
from kano.utils import get_home, get_user
from kano_content.extended_paths import content_dir

AVATAR_SCRATCH = os.path.join(
    '/tmp/', get_user(), 'char_gen_scratch', 'character.png')
AVATAR_DEFAULT_LOC = os.path.join(get_home(), '.character-content')
AVATAR_DEFAULT_NAME = 'character.png'
AVATAR_ENV_DEFAULT = 'character_inc_env.png'
AVATAR_ENV_SHIFTED = 'character_inc_env_page2.png'
AVATAR_CIRC_PLAIN_DEFAULT = 'character_circ_plain.png'
AVATAR_SELECTED_ITEMS = os.path.join(AVATAR_DEFAULT_LOC, 'character_log.json')

AVATAR_CONF_FILE = '/usr/share/kano-profile/rules/avatar_generator/conf.json'
PROFILE_IMAGES_FOLDER = '/usr/share/kano-profile/media/images'
AVATAR_ASSET_FOLDER = os.path.join(PROFILE_IMAGES_FOLDER, 'avatar_generator')
CSS_PATH = '/usr/share/kano-profile/media/CSS/avatar_generator.css'

CHARACTER_DIR = os.path.join(AVATAR_ASSET_FOLDER, 'characters')
ENVIRONMENT_DIR = os.path.join(
    PROFILE_IMAGES_FOLDER, 'environments', '734x404', 'all')
ITEM_DIR = os.path.join(AVATAR_ASSET_FOLDER, 'items')

CATEGORY_ICONS = os.path.join(AVATAR_ASSET_FOLDER, 'category_icons')