本文整理汇总了Python中misc.Path.posifyPath方法的典型用法代码示例。如果您正苦于以下问题:Python Path.posifyPath方法的具体用法?Python Path.posifyPath怎么用?Python Path.posifyPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类misc.Path
的用法示例。
在下文中一共展示了Path.posifyPath方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: filter
# 需要导入模块: from misc import Path [as 别名]
# 或者: from misc.Path import posifyPath [as 别名]
def filter(respath):
respath = Path.posifyPath(respath)
for res in self._resList:
mo = res.search(respath) # this might need a better 'match' algorithm
if mo:
return True
return False
示例2: from_doc_root_to_app_root
# 需要导入模块: from misc import Path [as 别名]
# 或者: from misc.Path import posifyPath [as 别名]
def from_doc_root_to_app_root(jobconf, confObj, doc_root):
japp_root = jobconf.get("compile-options/paths/app-root", "source")
app_root = os.path.normpath(os.path.join(confObj.absPath(japp_root), 'index.html'))
# as soon as app_root and doc_root have a drive letter, the next might fail due to capitalization
_, _, url_path = Path.getCommonPrefix(doc_root, app_root)
url_path = Path.posifyPath(url_path)
return url_path
示例3: _scanResourcePath
# 需要导入模块: from misc import Path [as 别名]
# 或者: from misc.Path import posifyPath [as 别名]
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...")
path = os.path.abspath(path)
lib_prefix_len = len(path)
if not path.endswith(os.sep):
lib_prefix_len += 1
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)
fpath = os.path.normpath(fpath)
if Image.isImage(fpath):
if CombinedImage.isCombinedImage(fpath):
res = CombinedImage(fpath)
else:
res = Image(fpath)
res.analyzeImage()
else:
res = Resource(fpath)
res.id = Path.posifyPath(fpath[lib_prefix_len:])
res.library= self
self.resources.add(res)
return
示例4: generateBootScript
# 需要导入模块: from misc import Path [as 别名]
# 或者: from misc.Path import posifyPath [as 别名]
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
示例5: getImageId
# 需要导入模块: from misc import Path [as 别名]
# 或者: from misc.Path import posifyPath [as 别名]
def getImageId(imagePath, prefixSpec):
prefix, altprefix = extractFromPrefixSpec(prefixSpec)
imageId = imagePath # init
_, imageId, _ = Path.getCommonPrefix(imagePath, prefix) # assume: imagePath = prefix "/" imageId
if altprefix:
imageId = altprefix + "/" + imageId
imageId = Path.posifyPath(imageId)
return imageId
示例6: assetIdFromPath
# 需要导入模块: from misc import Path [as 别名]
# 或者: from misc.Path import posifyPath [as 别名]
def assetIdFromPath(self, resource, lib):
def extractAssetPart(libresuri, imguri):
pre,libsfx,imgsfx = Path.getCommonPrefix(libresuri, imguri) # split libresuri from imguri
if imgsfx[0] == os.sep: imgsfx = imgsfx[1:] # strip leading '/'
return imgsfx # use the bare img suffix as its asset Id
librespath = os.path.normpath(os.path.join(lib['path'], lib['resource']))
assetId = extractAssetPart(librespath, resource)
assetId = Path.posifyPath(assetId)
return assetId
示例7: _scanResourcePath
# 需要导入模块: from misc import Path [as 别名]
# 或者: from misc.Path import posifyPath [as 别名]
def _scanResourcePath(self):
resources = set()
if self.resourcePath is None:
return resources
if not os.path.isdir(os.path.join(self.path,self.resourcePath)):
self._console.info("Lib<%s>: Skipping non-existing resource path" % self.namespace)
return resources
path = os.path.join(self.path,self.resourcePath)
self._console.debug("Scanning resource folder...")
path = os.path.abspath(path)
lib_prefix_len = len(path)
if not path.endswith(os.sep):
lib_prefix_len += 1
for root, dirs, files in filetool.walk(path):
# filter ignored directories
for dir in dirs:
if self._ignoredDirEntries.match(dir):
dirs.remove(dir)
for file in files:
if self._ignoredDirEntries.match(file):
continue
fpath = os.path.join(root, file)
fpath = os.path.normpath(fpath)
if Image.isImage(fpath):
if CombinedImage.isCombinedImage(fpath):
res = CombinedImage(fpath)
else:
res = Image(fpath)
res.analyzeImage()
elif FontMap.isFontMap(fpath):
res = FontMap(fpath)
else:
res = Resource(fpath)
res.set_id(Path.posifyPath(fpath[lib_prefix_len:]))
res.library= self
resources.add(res)
self._console.indent()
self._console.debug("Found %s resources" % len(resources))
self._console.outdent()
return resources
示例8: processCombinedImg
# 需要导入模块: from misc import Path [as 别名]
# 或者: from misc.Path import posifyPath [as 别名]
def processCombinedImg(data, meta_fname, combinedImageUri, combinedImageShortUri, combinedImageObject):
# make sure lib and type info for the combined image are present
assert combinedImageObject.lib, combinedImageObject.type
# see if we have cached the contents (json) of this .meta file
cacheId = "imgcomb-%s" % meta_fname
imgDict = self._cache.read(cacheId, meta_fname)
if imgDict == None:
mfile = open(meta_fname)
imgDict = simplejson.loads(mfile.read())
mfile.close()
self._cache.write(cacheId, imgDict)
# now loop through the dict structure from the .meta file
for imagePath, imageSpec_ in imgDict.items():
# sort of like this: imagePath : [width, height, type, combinedUri, off-x, off-y]
imageObject = ImgInfoFmt(imageSpec_) # turn this into an ImgInfoFmt object, to abstract from representation in .meta file and loader script
# have to normalize the uri's from the meta file
#imageUri = normalizeImgUri(imagePath, combinedImageUri, imageObject.mappedId)
imageUri = imagePath
## replace lib uri with lib namespace in imageUri
imageShortUri = extractAssetPart(librespath, imageUri)
imageShortUri = Path.posifyPath(imageShortUri)
# now put all elements of the image object together
imageObject.mappedId = combinedImageShortUri # correct the mapped uri of the combined image
imageObject.lib = combinedImageObject.lib
imageObject.mtype = combinedImageObject.type
imageObject.mlib = combinedImageObject.lib
# and store it in the data structure
data[imageShortUri] = imageObject.flatten() # this information takes precedence over existing
return
示例9: generateResourceInfoCode
# 需要导入模块: from misc import Path [as 别名]
# 或者: from misc.Path import posifyPath [as 别名]
def generateResourceInfoCode(self, settings, libs, format=False):
"""Pre-calculate image information (e.g. sizes)"""
data = {}
resdata = data
imgpatt = re.compile(r'\.(png|jpeg|jpg|gif)$', re.I)
skippatt = re.compile(r'\.(meta|py)$', re.I)
self._console.info("Analysing assets...")
self._console.indent()
self._imageInfo = ImageInfo(self._console, self._cache)
# some helper functions
def replaceWithNamespace(imguri, liburi, libns):
pre,libsfx,imgsfx = Path.getCommonPrefix(liburi, imguri)
if imgsfx[0] == os.sep: imgsfx = imgsfx[1:] # strip leading '/'
imgshorturi = os.path.join("${%s}" % libns, imgsfx)
return imgshorturi
def extractAssetPart(libresuri, imguri):
pre,libsfx,imgsfx = Path.getCommonPrefix(libresuri, imguri) # split libresuri from imguri
if imgsfx[0] == os.sep: imgsfx = imgsfx[1:] # strip leading '/'
return imgsfx # use the bare img suffix as its asset Id
##
# calculate the uri of the clipped image, by taking the uri of the combined image,
# "substracting" its asset id (the right end), taking what remains (the left
# part), extracting the asset id of the clipped image, and pre-fixing it with the
# left part of the combined image uri.
# imageUri = (combinedUri - combinedAssetId) + imageAssetId
#
# @param uriFromMetafile |String| the path of the clipped image from when the meta file was generated,
# like: "./source/resource/qx/decoration/Modern/..."
# @param trueCombinedUri |String| the uri of the combined image, as returned from
# the library scan and adapted for the current
# application, like:
# "../../framework/source/resource/qx/decoration/Modern/panel-combined.png"
# @param combinedUriFromMetafile |String| the path of the combined image, as
# recorded in the .meta file
def normalizeImgUri(uriFromMetafile, trueCombinedUri, combinedUriFromMetafile):
# normalize paths (esp. "./x" -> "x")
(uriFromMetafile, trueCombinedUri, combinedUriFromMetafile) = map(os.path.normpath,
(uriFromMetafile, trueCombinedUri, combinedUriFromMetafile))
# get the "wrong" left part of the combined image, as used in the .meta file (in mappedUriPrefix)
trueUriPrefix, mappedUriPrefix, _ = Path.getCommonSuffix(trueCombinedUri, combinedUriFromMetafile)
# ...and strip it from clipped image, to get a correct image id (in uriSuffix)
_, _, uriSuffix = Path.getCommonPrefix(mappedUriPrefix, uriFromMetafile)
# ...then compose the correct prefix with the correct suffix
normalUri = os.path.normpath(os.path.join(trueUriPrefix, uriSuffix))
return normalUri
##
# - reads through the entries of a .meta file, which is the contents of a combined image
# - for each contained image:
# - computes the image id ("short uri")
# - collects the list of interesting values (width, height, ..., combined image, ...)
# - and adds these as key:value to the general data map of images
#
# @param data |{imageId:[width, height, ...]}| general map for qx.$$resource in loader
# @param meta_fname |String| file path of the .meta file
# @param combinedImageUri |String| uri of the combined image
# @param combinedImageShortUri |String| short uri (image/asset id) of the combined image
# these are necessary to compute the image id's of the contained imgs
# @param combinedImageObject |ImgInfoFmt| an ImgInfoFmt wrapper object for the combined image
# (interesting for the lib and type info)
def processCombinedImg(data, meta_fname, combinedImageUri, combinedImageShortUri, combinedImageObject):
# make sure lib and type info for the combined image are present
assert combinedImageObject.lib, combinedImageObject.type
# see if we have cached the contents (json) of this .meta file
cacheId = "imgcomb-%s" % meta_fname
imgDict = self._cache.read(cacheId, meta_fname)
if imgDict == None:
mfile = open(meta_fname)
imgDict = simplejson.loads(mfile.read())
mfile.close()
self._cache.write(cacheId, imgDict)
# now loop through the dict structure from the .meta file
for imagePath, imageSpec_ in imgDict.items():
# sort of like this: imagePath : [width, height, type, combinedUri, off-x, off-y]
imageObject = ImgInfoFmt(imageSpec_) # turn this into an ImgInfoFmt object, to abstract from representation in .meta file and loader script
# have to normalize the uri's from the meta file
#imageUri = normalizeImgUri(imagePath, combinedImageUri, imageObject.mappedId)
imageUri = imagePath
## replace lib uri with lib namespace in imageUri
imageShortUri = extractAssetPart(librespath, imageUri)
imageShortUri = Path.posifyPath(imageShortUri)
# now put all elements of the image object together
imageObject.mappedId = combinedImageShortUri # correct the mapped uri of the combined image
imageObject.lib = combinedImageObject.lib
imageObject.mtype = combinedImageObject.type
imageObject.mlib = combinedImageObject.lib
#.........这里部分代码省略.........
示例10: runCompiled
# 需要导入模块: from misc import Path [as 别名]
# 或者: from misc.Path import posifyPath [as 别名]
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
#.........这里部分代码省略.........