Example #1
0
    def download_profile_stats(self, data=None):
        if not data:
            profile = load_profile()
            if 'kanoworld_id' in profile:
                user_id = profile['kanoworld_id']
            else:
                return False, 'Profile not registered!'

            success, text, data = request_wrapper('get', '/users/' + user_id,
                                                  headers=content_type_json,
                                                  session=self.session)
            if not success:
                return False, text

        try:
            version_no = data['user']['avatar']['generator']['version']
            save_profile_variable(
                'version',
                version_no,
                skip_kdesk_refresh=True
            )
        except Exception:
            pass

        updated_locally = False
        try:
            # Only update locally if version is 2. otherwise we will generate
            # a default
            if data['user']['avatar']['generator']['version'] == 2:
                gen = data['user']['avatar']['generator']
                avatar_subcat, avatar_item = gen['character']
                updated_locally = set_avatar(
                    avatar_subcat,
                    avatar_item,
                    sync=False
                )

                environment = gen['environment'][1]
                updated_locally |= set_environment(environment, sync=False)

        except Exception:
            pass

        # app states
        try:
            app_data = data['user']['profile']['stats']
        except Exception:
            return False, "Data missing from payload!"

        for app, values in app_data.iteritems():
            if not values or type(values) != dict or \
                    (len(values.keys()) == 1 and 'save_date' in values):
                continue
            if not is_private(app):
                save_app_state(app, values)

        if updated_locally:
            recreate_char(block=True)

        return True, None
Example #2
0
    def download_profile_stats(self, data=None):
        if not data:
            profile = load_profile()
            if 'kanoworld_id' in profile:
                user_id = profile['kanoworld_id']
            else:
                return False, 'Profile not registered!'

            success, text, data = request_wrapper('get',
                                                  '/users/' + user_id,
                                                  headers=content_type_json,
                                                  session=self.session)
            if not success:
                return False, text

        try:
            version_no = data['user']['avatar']['generator']['version']
            save_profile_variable('version',
                                  version_no,
                                  skip_kdesk_refresh=True)
        except Exception:
            pass

        updated_locally = False
        try:
            # Only update locally if version is 2. otherwise we will generate
            # a default
            if data['user']['avatar']['generator']['version'] == 2:
                gen = data['user']['avatar']['generator']
                avatar_subcat, avatar_item = gen['character']
                updated_locally = set_avatar(avatar_subcat,
                                             avatar_item,
                                             sync=False)

                environment = gen['environment'][1]
                updated_locally |= set_environment(environment, sync=False)

        except Exception:
            pass

        # app states
        try:
            app_data = data['user']['profile']['stats']
        except Exception:
            return False, "Data missing from payload!"

        for app, values in app_data.iteritems():
            if not values or type(values) != dict or \
                    (len(values.keys()) == 1 and 'save_date' in values):
                continue
            if not is_private(app):
                save_app_state(app, values)

        if updated_locally:
            recreate_char(block=True)

        return True, None
Example #3
0
    def download_profile_stats(self, data=None):
        if not data:
            profile = load_profile()
            if "kanoworld_id" in profile:
                user_id = profile["kanoworld_id"]
            else:
                return False, "Profile not registered!"

            success, text, data = request_wrapper(
                "get", "/users/" + user_id, headers=content_type_json, session=self.session
            )
            if not success:
                return False, text

        try:
            version_no = data["user"]["avatar"]["generator"]["version"]
            save_profile_variable("version", version_no)
        except Exception:
            pass

        updated_locally = False
        try:
            # Only update locally if version is 2. otherwise we will generate
            # a default
            if data["user"]["avatar"]["generator"]["version"] == 2:
                gen = data["user"]["avatar"]["generator"]
                avatar_subcat, avatar_item = gen["character"]
                updated_locally = set_avatar(avatar_subcat, avatar_item)

                environment = gen["environment"][1]
                updated_locally |= set_environment(environment)

        except Exception:
            pass

        # app states
        try:
            app_data = data["user"]["profile"]["stats"]
        except Exception:
            return False, "Data missing from payload!"

        for app, values in app_data.iteritems():
            if not values or (len(values.keys()) == 1 and "save_date" in values):
                continue
            if not is_private(app):
                save_app_state(app, values)

        if updated_locally:
            recreate_char(block=True)

        return True, None
Example #4
0
    def save_final_assets(self, dir_name, sync=True):
        """ Generates all types of assets and saves them to the directory and
        specified
        :param dir_name: The path to the base file, including the filename.
                         Other files are created from this filename and in
                         this directory (ex. '~/my_dir/my_new_char.png')
        :param sync: (Optional) Set to true to sync the avatar details with
                     the profile structure and if possible upload them to Kano
                     World
        :returns: True iff all operations necessary were successful
        :rtype: Boolean
        """
        dn = os.path.abspath(os.path.expanduser(dir_name))

        direc = os.path.dirname(dn)
        # if the path to file does not exist, create it
        if not os.path.isdir(direc):
            os.makedirs(direc)

        if not self._compare_existing_to_new(AVATAR_SELECTED_ITEMS):
            self._write_char_log_file(AVATAR_SELECTED_ITEMS)

            rc = self.create_avatar(dn)
            if not rc:
                logger.error(
                    "Encountered issue, stopping the creation of final assets"
                )
                return False

            logger.debug("Created {}".format(dn))
            rc = self.create_auxiliary_assets(dn)
            if not rc:
                logger.error("Encountered issue while creating aux assets")
                return False
        else:
            logger.info(
                "Assets for avatar already exist, will skip creating them")

        if sync:
            items_no_env = self.selected_items_per_cat()
            items_no_env.pop(self.env_label, None)
            # When saving a new character in the profile, ensure that
            # the right version is used to sync with the API
            save_profile_variable('version', 2, skip_kdesk_refresh=True)
            set_avatar(self._sel_char.get_id(), items_no_env, sync=False)
            set_environment(self._sel_env.get_id(), sync=False)
            sync_profile()

        return True
Example #5
0
    def log_in_success(self):
        '''If the login process is successful, sync with kano world
        and return success dialog text.
        '''
        logger.info('login successful')

        # saving hardware info and initial Kano version
        save_hardware_info()
        save_kano_version()

        # restore on first successful login/restore
        try:
            first_sync_done = profile['first_sync_done']
        except Exception:
            first_sync_done = False

        if not first_sync_done:
            logger.info(
                "running kano-sync --sync --restore after first time login"
            )

            # When both --sync and --restore are given as options, sync occurs
            # before the restore
            cmd = '{bin_dir}/kano-sync --sync -s --restore'.format(bin_dir=bin_dir)
            run_bg(cmd)

            save_profile_variable(
                'first_sync_done',
                True,
                skip_kdesk_refresh=True
            )

        else:
            logger.info("running kano-sync --sync after non-first login")

            # sync on each successful login
            cmd = '{bin_dir}/kano-sync --sync -s'.format(bin_dir=bin_dir)
            run_bg(cmd)

        title = _("Success!")
        description = _("You're in - online features now enabled.")
        return_value = 'SUCCESS'

        return (title, description, return_value)
Example #6
0
    def log_in_success(self):
        '''If the login process is successful, sync with kano world
        and return success dialog text.
        '''
        logger.info('login successful')

        # saving hardware info and initial Kano version
        save_hardware_info()
        save_kano_version()

        # restore on first successful login/restore
        try:
            first_sync_done = profile['first_sync_done']
        except Exception:
            first_sync_done = False

        if not first_sync_done:
            logger.info('running kano-sync --sync && --sync && --restore after first time login')

            # doing first sync and restore
            cmd1 = '{bin_dir}/kano-sync --sync -s'.format(bin_dir=bin_dir)
            cmd2 = '{bin_dir}/kano-sync --sync -s'.format(bin_dir=bin_dir)
            cmd3 = '{bin_dir}/kano-sync --restore -s'.format(bin_dir=bin_dir)
            cmd = "{} && {} && {}".format(cmd1, cmd2, cmd3)
            run_bg(cmd)

            save_profile_variable('first_sync_done', True)

        else:
            logger.info('running kano-sync --sync after non-first login')

            # sync on each successful login
            cmd = '{bin_dir}/kano-sync --sync -s'.format(bin_dir=bin_dir)
            run_bg(cmd)

        title = _("Success!")
        description = _("You're in - online features now enabled.")
        return_value = "SUCCESS"

        return (title, description, return_value)
    def register_user_with_gui(self):
        self.data_screen.cache_emails()
        self.data_screen.cache_marketing_choice()

        self.page_control.disable_buttons()
        self.data_screen.disable_all()
        self.get_email_data()

        # Make cursor into a spinner
        watch_cursor = Gdk.Cursor(Gdk.CursorType.WATCH)
        self.win.get_window().set_cursor(watch_cursor)

        # This means no threads are needed.
        while Gtk.events_pending():
            Gtk.main_iteration()

        # Try and register the account on the server
        email = self.win.data["email"]
        secondary_email = self.win.data["secondary_email"]
        username = self.win.data["username"]
        password = self.win.data["password"]
        date_year = self.win.data["year"]
        date_month = self.win.data["month"]
        date_day = self.win.data["day"]
        marketing_enabled = self.win.data["marketing_enabled"]

        logger.info('trying to register user with data {} {} {} {} {} {} {} {}'
                    .format(
                        email, secondary_email, username, password, date_year,
                        date_month, date_day, marketing_enabled
                    )
                    )

        success, text = register_(email, username, password,
                                  date_year, date_month, date_day,
                                  secondary_email=secondary_email,
                                  marketing_enabled=marketing_enabled)

        # This should no longer be needed, since this is checked in the first screen.
        # However there is a small chance someone could take the username
        # while the user is in the process of registering
        if not success:
            if text.strip() == "Cannot register, problem: Username already registered":

                logger.info('username invalid - getting second username')
                self.collect_new_username()
                return

            else:
                logger.info('problem with registration: {}'.format(text))
                return_value = "FAIL"
                self.create_dialog(
                    title=_("Houston, we have a problem"),
                    description=str(text)
                )
                track_data('world-registration-failed', {'reason': text})

        else:
            logger.info('registration successful')

            bday_date = str(datetime.date(date_year, date_month, date_day))
            save_profile_variable('birthdate', bday_date)

            # saving hardware info and initial Kano version
            save_hardware_info()
            save_kano_version()

            # running kano-sync after registration
            logger.info('running kano-sync after successful registration')
            cmd = '{bin_dir}/kano-sync --sync -s'.format(bin_dir=bin_dir)
            run_bg(cmd)

            return_value = "SUCCEED"
            self.create_dialog(
                title=_("Profile activated!"),
                description=_("Now you can share stuff, build your character, "
                              "and connect with friends.")
            )

        self.page_control.enable_buttons()
        self.data_screen.enable_all()
        self.win.get_window().set_cursor(None)

        # Close the app if it was successful
        if return_value == "SUCCEED":
            Gtk.main_quit()