本文整理匯總了Python中generator.code.Class.Class.mapResourcesToClasses方法的典型用法代碼示例。如果您正苦於以下問題:Python Class.mapResourcesToClasses方法的具體用法?Python Class.mapResourcesToClasses怎麽用?Python Class.mapResourcesToClasses使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類generator.code.Class.Class
的用法示例。
在下文中一共展示了Class.mapResourcesToClasses方法的4個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: runResources
# 需要導入模塊: from generator.code.Class import Class [as 別名]
# 或者: from generator.code.Class.Class import mapResourcesToClasses [as 別名]
def runResources(confObj, script):
jobconf = script.jobconfig
if not jobconf.get("copy-resources", False):
return
console = Context.console
console.info("Copying resources...")
classList = script.classesObj
resTargetRoot = jobconf.get("copy-resources/target", "build")
resTargetRoot = confObj.absPath(resTargetRoot)
# generator.approot = resTargetRoot # doesn't seem necessary anymore
# map resources to class.resources
classList = Class.mapResourcesToClasses(script.libraries, classList, jobconf.get("asset-let", {}))
console.indent()
# make resources to copy unique
resources_to_copy = set(_res for cls in classList for _res in cls.resources)
# Copy resources
# for lib in libs:
for res in resources_to_copy:
# construct target path
resTarget = os.path.join(resTargetRoot, "resource", res.id)
# Copy
_copyResources(res.path, os.path.dirname(resTarget))
console.outdent()
示例2: generateResourceInfoCode
# 需要導入模塊: from generator.code.Class import Class [as 別名]
# 或者: from generator.code.Class.Class import mapResourcesToClasses [as 別名]
def generateResourceInfoCode(self, script, settings, libraries, format=False):
def addResourceInfoToPackages(script):
for package in script.packages:
package_resources = []
# TODO: the next is a hack, since package.classes are still id's
package_classes = [x for x in script.classesObj if x.id in package.classes]
for clazz in package_classes:
package_resources.extend(clazz.resources)
package.data.resources = Script.createResourceStruct(package_resources, formatAsTree=resources_tree,
updateOnlyExistingSprites=True)
return
# -- main --------------------------------------------------------------
compConf = self._job.get ("compile-options")
compConf = ExtMap (compConf)
resources_tree = compConf.get ("code/resources-tree", False)
classes = Class.mapResourcesToClasses (libraries, script.classesObj,
self._job.get("asset-let", {}))
filteredResources = []
for clazz in classes:
filteredResources.extend(clazz.resources)
resdata = Script.createResourceStruct (filteredResources, formatAsTree=resources_tree,
updateOnlyExistingSprites=True)
# add resource info to packages
addResourceInfoToPackages(script)
return resdata # end: generateResourceInfoCode()
示例3: packagesResourceInfo
# 需要導入模塊: from generator.code.Class import Class [as 別名]
# 或者: from generator.code.Class.Class import mapResourcesToClasses [as 別名]
def packagesResourceInfo(self, script):
classes = Class.mapResourcesToClasses (script.libraries, script.classesObj,
self._job.get("asset-let", {}))
for package in script.packages:
package_resources = []
package_classes = package.classes
for clazz in package_classes:
package_resources.extend(clazz.resources)
package.data.resources = Script.createResourceStruct(package_resources, formatAsTree=False,
updateOnlyExistingSprites=True)
return script
示例4: depsToProviderFormat
# 需要導入模塊: from generator.code.Class import Class [as 別名]
# 或者: from generator.code.Class.Class import mapResourcesToClasses [as 別名]
def depsToProviderFormat(classDepsIter, depsLogConf):
##
# duplicates CodeProvider.passesOutputFilter
def passesOutputFilter(resId):
# must match some include expressions
if not filter(None, [x.search(resId) for x in inclregexps]): # [None, None, _sre.match, None, _sre.match, ...]
return False
# must not match any exclude expressions
if filter(None, [x.search(resId) for x in exclregexps]):
return False
return True
# ---------------------------------------
inclregexps = jobconf.get("provider/include", ["*"])
exclregexps = jobconf.get("provider/exclude", [])
inclregexps = map(textutil.toRegExp, inclregexps)
exclregexps = map(textutil.toRegExp, exclregexps)
replace_dots = depsLogConf.get("json/replace-dots-in", [])
slashes_keys = 'keys' in replace_dots
slashes_vals = 'values' in replace_dots
classToDeps = {}
# Class deps
for (packageId, classId, depId, loadOrRun) in classDepsIter:
if passesOutputFilter(classId):
if classId not in classToDeps:
classToDeps[classId] = {}
classToDeps[classId]["load"] = []
classToDeps[classId]["run"] = []
if depId != None:
classToDeps[classId][loadOrRun].append(depId)
if slashes_vals:
# transform dep items
for key, val in classToDeps.items():
newval = []
for ldep in val["load"]:
newdep = ldep.replace(".", "/")
newval.append(newdep)
val["load"] = newval
newval = []
for ldep in val["run"]:
newdep = ldep.replace(".", "/")
newval.append(newdep)
val["run"] = newval
# Resource deps
# class list
classObjs = [x for x in script.classesObj if x.id in classToDeps.keys()]
# map resources to class.resources
classObjs = Class.mapResourcesToClasses(script.libraries, classObjs, jobconf.get("asset-let", {}))
for clazz in classObjs:
reskeys = ["/resource/resources#"+x.id for x in clazz.resources]
classToDeps[clazz.id]["run"].extend(reskeys)
# Message key deps
for classId in classToDeps:
#classKeys, _ = Locale.getTranslation(classId, {})
classKeys, _ = script.classesAll[classId].messageStrings({})
transIds = set(x['id'] for x in classKeys) # get the msgid's, uniquely
transIds.update(x['plural'] for x in classKeys if 'plural' in x) # add plural keys
transKeys = ["/translation/i18n-${lang}#" + x for x in transIds]
classToDeps[classId]["run"].extend(transKeys)
# CLDR dependency
for classId in classToDeps:
if script.classesAll[classId].getHints("cldr"):
classToDeps[classId]["run"].append("/locale/locale-${lang}#cldr")
if slashes_keys:
# transform dep keys ("qx.Class" -> "qx/Class.js")
for key, val in classToDeps.items():
if key.find(".")>-1:
newkey = key.replace(".", "/")
classToDeps[newkey] = classToDeps[key]
del classToDeps[key]
# sort information for each class (for stable output)
for classvals in classToDeps.values():
for key in classvals:
classvals[key] = sorted(classvals[key], reverse=True)
# write to file
file_ = depsLogConf.get('json/file', "deps.json")
console.info("Writing dependency data to file: %s" % file_)
pretty = depsLogConf.get('json/pretty', None)
if pretty:
indent = 2
separators = (', ', ': ')
else:
indent = None
separators = (',', ':')
filetool.save(file_, json.dumps(classToDeps, sort_keys=True, indent=indent, separators=separators))
return