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()
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
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()
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
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
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
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
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)
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
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
def file2package(fname, rootname): fileid = Path.getCommonPrefix(rootname, fname)[2] fileid = os.path.splitext(fileid)[0] # strip .py return fileid.replace(os.sep, '.')
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')) _, _, url_path = Path.getCommonPrefix(doc_root, app_root) url_path = Path.posifyPath(url_path) return url_path
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
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
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