本文整理汇总了Python中misc.Path.getCommonPrefix方法的典型用法代码示例。如果您正苦于以下问题:Python Path.getCommonPrefix方法的具体用法?Python Path.getCommonPrefix怎么用?Python Path.getCommonPrefix使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类misc.Path
的用法示例。
在下文中一共展示了Path.getCommonPrefix方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: runCopyFiles
# 需要导入模块: from misc import Path [as 别名]
# 或者: from misc.Path import getCommonPrefix [as 别名]
def runCopyFiles(jobconf, confObj):
# Copy application files
if not jobconf.get("copy-files/files", False):
return
console = Context.console
filePatts = jobconf.get("copy-files/files", [])
if filePatts:
buildRoot = jobconf.get("copy-files/target", "build")
buildRoot = confObj.absPath(buildRoot)
sourceRoot = jobconf.get("copy-files/source", "source")
sourceRoot = confObj.absPath(sourceRoot)
console.info("Copying application files...")
console.indent()
for patt in filePatts:
appfiles = glob.glob(os.path.join(sourceRoot, patt))
for srcfile in appfiles:
console.debug("copying %s" % srcfile)
srcfileSuffix = Path.getCommonPrefix(sourceRoot, srcfile)[2]
destfile = os.path.join(buildRoot, srcfileSuffix)
if os.path.isdir(srcfile):
destdir = destfile
else:
destdir = os.path.dirname(destfile)
_copyResources(srcfile, destdir)
console.outdent()
示例2: from_doc_root_to_app_root
# 需要导入模块: from misc import Path [as 别名]
# 或者: from misc.Path import getCommonPrefix [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: getImageId
# 需要导入模块: from misc import Path [as 别名]
# 或者: from misc.Path import getCommonPrefix [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
示例4: getSavePath
# 需要导入模块: from misc import Path [as 别名]
# 或者: from misc.Path import getCommonPrefix [as 别名]
def getSavePath(self, urlRoot, fileRoot, currUrl):
savePath = pathFrag = ""
# pathFrag = currUrl - urlRoot; assert currUrl > urlRoot
assert currUrl.startswith(urlRoot) # only consider urls from the same root
(pre,sfx1,sfx2) = Path.getCommonPrefix(urlRoot, currUrl)
pathFrag = sfx2
savePath = os.path.join(fileRoot, pathFrag)
return savePath
示例5: resourceValue
# 需要导入模块: from misc import Path [as 别名]
# 或者: from misc.Path import getCommonPrefix [as 别名]
def resourceValue(r):
# create a pair res = [path, uri] for this resource...
rsource = os.path.normpath(r) # normalize "./..."
relpath = (Path.getCommonPrefix(libObj._resourcePath, rsource))[2]
if relpath[0] == os.sep: # normalize "/..."
relpath = relpath[1:]
ruri = (self._genobj._computeResourceUri(lib, relpath, rType='resource',
appRoot=self._genobj.approot))
return (rsource, ruri)
示例6: normalizeImgUri
# 需要导入模块: from misc import Path [as 别名]
# 或者: from misc.Path import getCommonPrefix [as 别名]
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
示例7: findLibResources
# 需要导入模块: from misc import Path [as 别名]
# 或者: from misc.Path import getCommonPrefix [as 别名]
def findLibResources(self, lib, filter=None):
def getCache(lib):
cacheId = "resinlib-%s" % lib._path
liblist = self._genobj._cache.read(cacheId, dependsOn=None, memory=True)
return liblist, cacheId
def isSkipFile(f):
if [x for x in map(lambda x: re.search(x, f), ignoredFiles) if x!=None]:
return True
else:
return False
# - Main --------------------------------------------------------------
cacheList = [] # to poss. populate cache
cacheId = "" # will be filled in getCache()
ignoredFiles = [r'\.meta$',] # files not considered as resources
# create wrapper object
libObj = Library(lib, self._genobj._console)
# retrieve list of library resources
libList, cacheId = getCache(libObj)
if libList:
inCache = True
else:
libList = libObj.scanResourcePath()
inCache = False
# go through list of library resources and add suitable
for resource in libList:
# scanResourcePath() yields absolute paths to a resource, but
# we only want to match against the 'resource' part of it
resourcePart = Path.getCommonPrefix(libObj._resourcePath, resource)[2]
if not inCache:
cacheList.append(resource)
if isSkipFile(resource):
continue
elif (filter and not filter(resourcePart)):
continue
else:
yield resource
if not inCache:
# cache write
self._genobj._cache.write(cacheId, cacheList, memory=True, writeToFile=False)
return
示例8: file2package
# 需要导入模块: from misc import Path [as 别名]
# 或者: from misc.Path import getCommonPrefix [as 别名]
def file2package(fname, rootname):
fileid = Path.getCommonPrefix(rootname, fname)[2]
fileid = os.path.splitext(fileid)[0] # strip .py
return fileid.replace(os.sep, '.')
示例9: findAllResources
# 需要导入模块: from misc import Path [as 别名]
# 或者: from misc.Path import getCommonPrefix [as 别名]
def findAllResources(self, libraries, filter=None):
"""Find relevant resources/assets, implementing shaddowing of resources.
Returns a list of resources, each a pair of [file_path, uri]"""
# - Helpers -----------------------------------------------------------
def getCache(lib):
cacheId = "resinlib-%s" % lib._path
liblist = self._genobj._cache.read(cacheId, dependsOn=None, memory=True)
return liblist, cacheId
def isSkipFile(f):
if [x for x in map(lambda x: re.search(x, f), ignoredFiles) if x!=None]:
return True
else:
return False
def resourceValue(r):
# create a pair res = [path, uri] for this resource...
rsource = os.path.normpath(r) # normalize "./..."
relpath = (Path.getCommonPrefix(libObj._resourcePath, rsource))[2]
if relpath[0] == os.sep: # normalize "/..."
relpath = relpath[1:]
ruri = (self._genobj._computeResourceUri(lib, relpath, rType='resource',
appRoot=self._genobj.approot))
return (rsource, ruri)
# - Main --------------------------------------------------------------
result = []
cacheList = [] # to poss. populate cache
cacheId = "" # will be filled in getCache()
ignoredFiles = [r'\.meta$',] # files not considered as resources
libs = libraries[:]
#libs.reverse() # this is to search the 'important' libs first
# go through all libs (weighted) and collect necessary resources
for lib in libs:
# create wrapper object
libObj = LibraryPath(lib, self._genobj._console)
# retrieve list of library resources
libList, cacheId = getCache(libObj)
if libList:
inCache = True
else:
libList = libObj.scanResourcePath()
inCache = False
# go through list of library resources and add suitable
for resource in libList:
# scanResourcePath() yields absolute paths to a resource, but
# we only want to match against the 'resource' part of it
resourcePart = Path.getCommonPrefix(libObj._resourcePath, resource)[2]
if not inCache:
cacheList.append(resource)
if isSkipFile(resource):
continue
elif (filter and not filter(resourcePart)):
continue
else:
result.append(resource)
if not inCache:
# cache write
self._genobj._cache.write(cacheId, cacheList, memory=True, writeToFile=False)
return result
示例10: extractAssetPart
# 需要导入模块: from misc import Path [as 别名]
# 或者: from misc.Path import getCommonPrefix [as 别名]
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
示例11: replaceWithNamespace
# 需要导入模块: from misc import Path [as 别名]
# 或者: from misc.Path import getCommonPrefix [as 别名]
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