def findAllResources(self, libraries, filter=None, useCombImgs=True): combinedImages = set(()) # go through all libs (weighted) and collect necessary resources for lib in libraries: for resource in self.findLibResources(lib, ): if self.isCombinedImage(resource): combinedImages.add(resource) if (filter and not filter(resource)): continue else: yield resource # go through the combined images if filter: for combpath in combinedImages: combimg = CombinedImage(combpath) for embimg in combimg.getEmbeddedImages(): if filter(embimg): yield combpath break # one match is enough else: # if there is no filter, the comb. images have been added in the # first loop pass return
def registerResources(libs, filteredResources, combinedImages): skippatt = re.compile(r'\.(meta|py)$', re.I) for lib in libs: resourceList = self._resourceHandler.findAllResources([lib], None) # resourceList = [file1,file2,...] for resource in resourceList: if skippatt.search(resource): continue if assetFilter(resource): # add those anyway resId, resVal = analyseResource(resource, lib) filteredResources[resId] = resVal if self._resourceHandler.isCombinedImage(resource): # register those for later evaluation combId, combImgFmt = analyseResource(resource, lib) combObj = CombinedImage(resource) # this parses also the .meta file combObj.info = combImgFmt combinedImages[combId] = combObj return filteredResources, combinedImages
def getResourcesByClass(self, libs, classToAssetHints): classToResources = collections.defaultdict(list) for lib in libs: allResources = [x for x in self.findAllResources([lib])] # lookup table for resource id's resVals = {} # get resId and pot. embedded Images for res in allResources: resId = self.assetIdFromPath(res, lib) if self.isCombinedImage(res): combimg = CombinedImage(res) embImgs = combimg.getEmbeddedImages() resVals[res] = (resId, embImgs) else: resVals[res] = (resId, False) # try to match classes to resources in this lib for classId, assetSet in classToAssetHints.items(): for resource in allResources: resVal = resVals[resource] if self.assetsMatchResource(assetSet, resource, resVal): classToResources[classId].append(resId) return classToResources
def _scanResourcePath(self, path): if not os.path.exists(path): raise ValueError("The given resource path does not exist: %s" % path) self._console.debug("Scanning resource folder...") for root, dirs, files in filetool.walk(path): # filter ignored directories for dir in dirs: if self._ignoredDirectories.match(dir): dirs.remove(dir) for file in files: fpath = os.path.join(root, file) #self._resources.append(fpath) # avoiding this currently, as it is not used if CombinedImage.isCombinedImage(fpath): self.resources.combImages.add(os.path.normpath(fpath)) return
def _scanResourcePath(self, path): if not os.path.exists(path): raise ValueError("The given resource path does not exist: %s" % path) self._console.debug("Scanning resource folder...") for root, dirs, files in filetool.walk(path): # filter ignored directories for dir in dirs: if self._ignoredDirectories.match(dir): dirs.remove(dir) for file in files: fpath = os.path.join(root, file) #self._resources.append(fpath) # avoiding this currently, as it is not used if CombinedImage.isCombinedImage(fpath): self.resources.combImages.add(fpath) return