Beispiel #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)
Beispiel #2
0
    def upload_private_data(self):
        data = dict()
        for app in get_app_list():
            if is_private(app):
                data[app] = load_app_state(app)

        payload = dict()
        payload["data"] = data

        success, text, data = request_wrapper(
            "put", "/sync/data", data=json.dumps(payload), headers=content_type_json, session=self.session
        )
        if not success:
            return False, text

        return self.download_private_data(data)
Beispiel #3
0
    def upload_private_data(self):
        data = dict()
        for app in get_app_list():
            if is_private(app):
                data[app] = load_app_state(app)

        payload = dict()
        payload['data'] = data

        success, text, data = request_wrapper('put',
                                              '/sync/data',
                                              data=json.dumps(payload),
                                              headers=content_type_json,
                                              session=self.session)
        if not success:
            return False, text

        return self.download_private_data(data)
Beispiel #4
0
    def upload_profile_stats(self):
        profile = load_profile()

        data = dict()

        # xp
        data['xp'] = calculate_xp()

        # version
        try:
            data['version'] = profile['version']
        except KeyError:
            logger.debug("Version field not in the data to be synced")

        # age
        try:
            data['birthdate'] = profile['birthdate']
        except Exception:
            pass

        # gender
        try:
            gender = profile['gender']
            if gender == "Boy":
                gender = 'm'
            elif gender == "Girl":
                gender = 'f'
            elif gender == "Wizard":
                gender = 'x'
            data['gender'] = gender
        except Exception:
            pass

        # avatar_generator
        data, files = self._prepare_avatar_gen(profile, data)
        # app states
        stats = dict()
        for app in get_app_list():
            if not is_private(app):
                stats[app] = load_app_state(app)

        # append stats
        data['stats'] = stats

        # Uploading profile stats
        success, text, response_data = request_wrapper(
            'put',
            '/users/profile',
            data=json.dumps(data),
            headers=content_type_json,
            session=self.session)

        if not success:
            logger.error("Uploading of the profile data failed")
            return False, text

        if files:
            # Uploading avatar assets
            success, text, response_data = request_wrapper(
                'put', '/users/profile', session=self.session, files=files)

            # requests doesn't close the file objects after sending them, so
            # we need to tidy up
            self._tidy_up_avatar_files(files)

            if not success:
                logger.error("Uploading of the avatar assets failed")
                return False, text

        return self.download_profile_stats(response_data)
Beispiel #5
0
    def upload_profile_stats(self):
        profile = load_profile()

        data = dict()

        # xp
        data['xp'] = calculate_xp()

        # version
        try:
            data['version'] = profile['version']
        except KeyError:
            logger.debug("Version field not in the data to be synced")

        # age
        try:
            data['birthdate'] = profile['birthdate']
        except Exception:
            pass

        # gender
        try:
            gender = profile['gender']
            if gender == "Boy":
                gender = 'm'
            elif gender == "Girl":
                gender = 'f'
            elif gender == "Wizard":
                gender = 'x'
            data['gender'] = gender
        except Exception:
            pass

        # avatar_generator
        data, files = self._prepare_avatar_gen(profile, data)
        # app states
        stats = dict()
        for app in get_app_list():
            if not is_private(app):
                stats[app] = load_app_state(app)

        # append stats
        data['stats'] = stats

        # Uploading profile stats
        success, text, response_data = request_wrapper(
            'put',
            '/users/profile',
            data=json.dumps(data),
            headers=content_type_json,
            session=self.session)

        if not success:
            logger.error("Uploading of the profile data failed")
            return False, text

        if files:
            # Uploading avatar assets
            success, text, response_data = request_wrapper(
                'put',
                '/users/profile',
                session=self.session,
                files=files)

            # requests doesn't close the file objects after sending them, so
            # we need to tidy up
            self._tidy_up_avatar_files(files)

            if not success:
                logger.error("Uploading of the avatar assets failed")
                return False, text

        return self.download_profile_stats(response_data)