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
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
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
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