def _get_co_assets(): from kano_content.api import ContentManager cm = ContentManager.from_local() co_index = {} for co in cm.list_local_objects(spec='make-art-assets'): co_files = co.get_data('').get_content() if len(co_files) != 2: logger.warning( 'Count of files other than 2 in co[{}], skipping'.format( co.get_data('').get_dir() ) ) continue # Check whether the first file is the index index_no = _get_co_index_apply_order(co_files[0]) if index_no is not None: co_index[index_no] = co_files[1] else: # It wasn't the first one, go for the second one index_no = _get_co_index_apply_order(co_files[1]) if index_no is not None: co_index[index_no] = co_files[0] else: err_msg = 'None of the files contained in co have apply index' logger.error(err_msg) continue return co_index
def create_wallpaper_dict(self): '''Get the wallpapers from the profile, the Kano Draw pictures and find which ones are unlocked ''' self.images = {} self.get_wallpapers(wallpaper_path) self.get_wallpapers(kano_draw_path) cm = ContentManager.from_local() for co in cm.list_local_objects(spec='wallpapers'): wallpaper_dir = co.get_data('wallpapers').get_dir() self.get_wallpapers(wallpaper_dir) # To get info about which environments are unlocked we first calculate # badges then we take the 'achieved' attribute of an environment and # add it to the attribute of our local list of wallpapers # # NOTE: it relies on the wallpapers in kano-desktop to me named as # their respective rule in kano-profile with the following pattern: # # [rule_name]-background[name_pattern] # e.g. [arcade_hall]-background[-4-3.png] environments = calculate_badges()['environments']['all'] for environment, attributes in environments.iteritems(): try: self.images[environment]['unlocked'] = attributes['achieved'] except: pass
def get_co_list(): ''' Returns a list of content object IDs currently on the system. ''' try: cm = ContentManager.from_local() objects = cm.list_local_objects(active_only=False, inactive_only=False) return str(objects) except: return "Couldn't get a list of content objects."
def get_avatar_conf(aux_files=[]): conf = None cm = ContentManager.from_local() for k in cm.list_local_objects(spec='kano-character-v2'): content_dir.register_path( 'CHARACTER_DIR', k.get_data('character_base').get_dir()) content_dir.register_path( 'CHARACTER_OVERWORLD_DIR', k.get_data('character_overworld_base').get_dir()) content_dir.register_path( 'PREVIEW_ICONS', k.get_data('character_thumb').get_dir()) content_dir.register_path( 'ACTIVE_CATEGORY_ICONS', k.get_data('active_cat_icon').get_dir()) content_dir.register_path( 'INACTIVE_CATEGORY_ICONS', k.get_data('inactive_cat_icon').get_dir()) content_dir.register_path( 'PREVIEW_ICONS', k.get_data('previews').get_dir()) content_dir.register_path('ITEM_DIR', k.get_data('assets').get_dir()) content_dir.register_path('ITEM_OVERWORLD_DIR', k.get_data('assets_overworld').get_dir()) aux_files.append(k.get_data('').get_content()[0]) for k in cm.list_local_objects(spec='kano-character-category-v2'): content_dir.register_path( 'ACTIVE_CATEGORY_ICONS', k.get_data('active_cat_icon').get_dir()) content_dir.register_path( 'INACTIVE_CATEGORY_ICONS', k.get_data('inactive_cat_icon').get_dir()) content_dir.register_path( 'PREVIEW_ICONS', k.get_data('previews').get_dir()) content_dir.register_path('ITEM_DIR', k.get_data('assets').get_dir()) content_dir.register_path('ITEM_OVERWORLD_DIR', k.get_data('assets_overworld').get_dir()) aux_files.append(k.get_data('').get_content()[0]) for k in cm.list_local_objects(spec='kano-character-items-v2'): content_dir.register_path( 'PREVIEW_ICONS', k.get_data('previews').get_dir()) content_dir.register_path('ITEM_DIR', k.get_data('assets').get_dir()) content_dir.register_path('ITEM_OVERWORLD_DIR', k.get_data('assets_overworld').get_dir()) aux_files.append(k.get_data('').get_content()[0]) with open(AVATAR_CONF_FILE) as f: conf = load(f) if conf is None: logger.error("Default Conf file {} not found".format(AVATAR_CONF_FILE)) else: if not is_valid_configuration(conf): logger.error("Default configuration file is not in valid format") return dict() if aux_files: logger.debug( "Auxiliary configuration files to be used: {}".format(aux_files)) for con_fname in aux_files: if os.path.isfile(con_fname): # Attempt to decode as JSON try: f = open(con_fname) except IOError as e: logger.error( "Error opening the aux conf file {}".format(e)) continue else: with f: try: aux_conf = load(f) except ValueError as e: logger.info("Conf file not a JSON {}".format(e)) continue if is_valid_configuration(aux_conf): if not merge_conf_files(conf, aux_conf): logger.error( "Can't integrate conf file {}".format(con_fname)) else: logger.error( "Parsed auxiliary film doesn't contain valid conf") else: logger.warn( "Auxiliary conf file {} doen't exist".format(con_fname)) return conf