本文整理汇总了Python中misc.ExtMap.ExtMap类的典型用法代码示例。如果您正苦于以下问题:Python ExtMap类的具体用法?Python ExtMap怎么用?Python ExtMap使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了ExtMap类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: createResourceStruct
def createResourceStruct(resources, formatAsTree=False, updateOnlyExistingSprites=False):
skippatt = re.compile(r'\.(meta|py)$', re.I)
result = {}
if formatAsTree:
result = ExtMap()
# Filter unwanted files
for res in resources:
if skippatt.search(res.path):
continue
result[res.id] = res
# Update simple images
for combImg in (x for x in result.values() if isinstance(x, CombinedImage)):
for embImg in combImg.embeds:
if embImg.id in result:
result[embImg.id].attachCombinedImage(combImg)
elif not updateOnlyExistingSprites:
embImg.attachCombinedImage(combImg)
result[embImg.id] = embImg
# Flatten out the resource representation
for resid, res in result.items():
result[resid] = res.toResinfo()
# ExtMap returns nested maps
if formatAsTree:
result = result.getData()
return result
示例2: runFix
def runFix(jobconf, classesObj):
def fixPng():
return
def removeBOM(fpath):
content = open(fpath, "rb").read()
if content.startswith(codecs.BOM_UTF8):
console.debug("removing BOM: %s" % filePath)
open(fpath, "wb").write(content[len(codecs.BOM_UTF8):])
return
# - Main ---------------------------------------------------------------
if not isinstance(jobconf.get("fix-files", False), types.DictType):
return
console = Context.console
classes = classesObj.keys()
fixsettings = ExtMap(jobconf.get("fix-files"))
# Fixing JS source files
console.info("Fixing whitespace in source files...")
console.indent()
console.info("Fixing files: ", False)
numClasses = len(classes)
eolStyle = fixsettings.get("eol-style", "LF")
tabWidth = fixsettings.get("tab-width", 2)
for pos, classId in enumerate(classes):
console.progress(pos+1, numClasses)
classEntry = classesObj[classId]
filePath = classEntry.path
fileEncoding = classEntry.encoding
fileContent = filetool.read(filePath, fileEncoding)
# Caveat: as filetool.read already calls any2Unix, converting to LF will
# not work as the file content appears unchanged to this function
if eolStyle == "CR":
fixedContent = textutil.any2Mac(fileContent)
elif eolStyle == "CRLF":
fixedContent = textutil.any2Dos(fileContent)
else:
fixedContent = textutil.any2Unix(fileContent)
fixedContent = textutil.normalizeWhiteSpace(textutil.removeTrailingSpaces(textutil.tab2Space(fixedContent, tabWidth)))
if fixedContent != fileContent:
console.debug("modifying file: %s" % filePath)
filetool.save(filePath, fixedContent, fileEncoding)
# this has to go separate, as it requires binary operation
removeBOM(filePath)
console.outdent()
# Fixing PNG files -- currently just a stub!
if fixsettings.get("fix-png", False):
console.info("Fixing PNGs...")
console.indent()
fixPng()
console.outdent()
return
示例3: createResourceStruct
def createResourceStruct(resources, formatAsTree=False, updateOnlyExistingSprites=False):
skippatt = re.compile(r'\.(meta|py)$', re.I)
result = {}
if formatAsTree:
result = ExtMap()
# Filter unwanted files
for res in resources:
if skippatt.search(res.path):
continue
result[res.id] = res
# Update simple images
for combImg in (x for x in result.values() if isinstance(x, CombinedImage)):
for embImg in combImg.embeds:
if embImg.id in result:
result[embImg.id].attachCombinedImage(combImg)
elif not updateOnlyExistingSprites:
embImg.attachCombinedImage(combImg)
result[embImg.id] = embImg
# Flatten out the resource representation
for resid, res in result.items():
result[resid] = res.toResinfo()
# Unify font map aliases
if isinstance(res, FontMap):
for glyphname, code in res.mapping.iteritems():
fdsc = "@%s/%s" % (res.alias, glyphname)
if not fdsc in result:
result[fdsc] = [result[resid][1], round(result[resid][2] / code[1]), code[0]]
del result[resid][4]
# ExtMap returns nested maps
if formatAsTree:
result = result.getData()
return result
示例4: runPrettyPrinting
def runPrettyPrinting(self, classesObj):
if not isinstance(self._job.get("pretty-print", False), types.DictType):
return
self._console.info("Pretty-printing code...")
self._console.indent()
ppsettings = ExtMap(self._job.get("pretty-print")) # get the pretty-print config settings
# init options
def options(): pass
pretty.defaultOptions(options)
# modify according to config
if 'general/indent-string' in ppsettings:
options.prettypIndentString = ppsettings.get('general/indent-string')
if 'comments/block/add' in ppsettings:
options.prettypCommentsBlockAdd = ppsettings.get('comments/trailing/keep-column')
if 'comments/trailing/keep-column' in ppsettings:
options.prettypCommentsTrailingKeepColumn = ppsettings.get('comments/trailing/keep-column')
if 'comments/trailing/comment-cols' in ppsettings:
options.prettypCommentsTrailingCommentCols = ppsettings.get('comments/trailing/comment-cols')
if 'comments/trailing/padding' in ppsettings:
options.prettypCommentsInlinePadding = ppsettings.get('comments/trailing/padding')
if 'code/align-with-curlies' in ppsettings:
options.prettypAlignBlockWithCurlies = ppsettings.get('code/align-with-curlies')
if 'code/open-curly/newline-before' in ppsettings:
options.prettypOpenCurlyNewlineBefore = ppsettings.get('code/open-curly/newline-before')
if 'code/open-curly/indent-before' in ppsettings:
options.prettypOpenCurlyIndentBefore = ppsettings.get('code/open-curly/indent-before')
self._console.info("Pretty-printing files: ", False)
numClasses = len(classesObj)
for pos, classId in enumerate(classesObj):
self._console.progress(pos+1, numClasses)
tree = classesObj[classId].tree()
result = [u'']
result = pretty.prettyNode(tree, options, result)
compiled = u''.join(result)
filetool.save(self._classes[classId].path, compiled)
self._console.outdent()
return
示例5: runLogDependencies
#.........这里部分代码省略.........
console.outdent()
console.outdent()
console.outdent()
return
def graphAddEdges(classDepsIter, gr, pLoadOrRun):
loadAttrs = [('color','red')]
runAttrs = []
for (packageId, classId, depId, loadOrRun) in classDepsIter:
if not gr.has_node(classId):
graphAddNode(gr, classId)
if not gr.has_node(depId):
graphAddNode(gr, depId)
if loadOrRun == 'load' and pLoadOrRun != "runtime":
gr.add_edge(classId, depId, attrs = loadAttrs)
if loadOrRun == 'run' and pLoadOrRun != "loadtime":
gr.add_edge(classId, depId, attrs = runAttrs)
return
def graphAddNodes(gr, clsList):
for cid in clsList:
graphAddNode(gr, cid)
def graphAddNode(gr, cid):
if cid in script.classesAll:
fsize = script.classesAll[cid].size
if fsize > 20000:
color = "red"
elif fsize > 5000:
color = "green"
else:
color = "blue"
else:
color = "blue"
gr.add_node(cid, attrs=[("color", color)])
return
def logDeps(depsLogConf, type):
mainformat = depsLogConf.get('format', None)
includeTransitives = depsLogConf.get('include-transitive-load-deps', True)
forceFreshDeps = depsLogConf.get('force-fresh-deps', False)
# TODO: debug
for cls in (c for p in packages for c in p.classes):
#print cls.id
pass
if type == "using":
classDepsIter = lookupUsingDeps(packages, includeTransitives, forceFreshDeps)
else:
classDepsIter = lookupUsedByDeps(packages, includeTransitives, forceFreshDeps)
if mainformat == 'dot':
depsToDotFile(classDepsIter, depsLogConf)
elif mainformat == 'json':
depsToJsonFile(classDepsIter, depsLogConf)
elif mainformat == 'flare':
depsToFlareFile(classDepsIter, depsLogConf)
elif mainformat == 'term':
depsToTerms(classDepsIter)
elif mainformat == 'provider':
depsToProviderFormat(classDepsIter, depsLogConf)
else:
depsToConsole(classDepsIter, type)
return
# -- Main (runLogDependencies) ------------------
depsLogConf = jobconf.get("log/dependencies", False)
if not depsLogConf:
return
console = Context.console
console.info("Dependency logging ", feed=False)
console.indent()
packages = script.packagesSorted()
parts = script.parts
variants = script.variants
depsLogConf = ExtMap(depsLogConf)
type = depsLogConf.get('type', None)
if type in ("used-by", "using"):
logDeps(depsLogConf, type)
else:
console.error('Dependency log type "%s" not in ["using", "used-by"]; skipping...' % type)
console.outdent()
console.dotclear()
return
示例6: getFeature
def getFeature(self, feature, default=None):
dataMap = ExtMap(self._data)
return dataMap.get(feature, default)
示例7: runCompiled
def runCompiled(self, script, treeCompiler):
def getAppName(memo={}):
if not 'appname' in memo:
appname = self._job.get("let/APPLICATION")
if not appname:
raise RuntimeError, "Need an application name in config (key let/APPLICATION)"
else:
memo['appname'] = appname
return memo['appname']
def getOutputFile():
filePath = compConf.get("paths/file")
if not filePath:
filePath = os.path.join("build", "script", getAppName() + ".js")
return filePath
def getFileUri(scriptUri):
appfile = os.path.basename(fileRelPath)
fileUri = os.path.join(scriptUri, appfile) # make complete with file name
fileUri = Path.posifyPath(fileUri)
return fileUri
def generateBootScript(bootPackage=""):
def packagesOfFiles(fileUri, packages):
# returns list of lists, each containing destination file name of the corresp. part
# npackages = [['script/gui-0.js'], ['script/gui-1.js'],...]
npackages = []
file = os.path.basename(fileUri)
for packageId in range(len(packages)):
packageFileName = self._resolveFileName(file, variants, settings, packageId)
npackages.append((packageFileName,))
return npackages
self._console.info("Generating boot script...")
bootBlocks = []
# For resource list
resourceUri = compConf.get('uris/resource', 'resource')
resourceUri = Path.posifyPath(resourceUri)
globalCodes = self.generateGlobalCodes(libs, translationMaps, settings, variants, format, resourceUri, scriptUri)
filesPackages = packagesOfFiles(fileUri, packages)
bootBlocks.append(self.generateBootCode(parts, filesPackages, boot, variants, settings, bootPackage, globalCodes, "build", format))
if format:
bootContent = "\n\n".join(bootBlocks)
else:
bootContent = "".join(bootBlocks)
return bootContent
def writePackages(compiledPackages, startId=0):
for packageId, content in enumerate(compiledPackages):
writePackage(content, startId + packageId)
return
def writePackage(content, packageId=""):
# Construct file name
resolvedFilePath = self._resolveFileName(filePath, variants, settings, packageId)
# Save result file
filetool.save(resolvedFilePath, content)
if compConf.get("paths/gzip"):
filetool.gzip(resolvedFilePath, content)
self._console.debug("Done: %s" % self._computeContentSize(content))
self._console.debug("")
return
# ----------------------------------------------------------------------
if not self._job.get("compile-dist", False):
return
packages = script.packages
parts = script.parts
boot = script.boot
variants = script.variants
classList = script.classes
self._treeCompiler = treeCompiler
self._classList = classList
compConf = ExtMap(self._job.get("compile-dist"))
# Read in base file name
fileRelPath = getOutputFile()
filePath = self._config.absPath(fileRelPath)
# Read in uri prefixes
scriptUri = compConf.get('uris/script', 'script')
scriptUri = Path.posifyPath(scriptUri)
fileUri = getFileUri(scriptUri)
# Read in compiler options
#.........这里部分代码省略.........