def makeClassObj(self, filePathId, filePath, props): ## # provide a default context dict def get_contextdict(): contextdict = {} contextdict["console"] = context.console contextdict["cache"] = context.cache contextdict["jobconf"] = context.jobconf contextdict["envchecksmap"] = {} return contextdict # ----------------------------------------------------------------------- contextdict = get_contextdict( ) # TODO: Clazz() still relies on a context dict! if filePathId == "qx.core.Environment": clazz = qcEnvClass(filePathId, filePath, self, contextdict) else: clazz = Class(filePathId, filePath, self, contextdict) # extract code ID (e.g. class name, mixin name, ...) #fileCodeId = self.checkClassId(clazz, filePathId) # involves parsing clazz.encoding = props.fileEncoding clazz.size = props.fileSize # dependency logging uses this clazz.package = props.filePackage # Apiloader uses this clazz.relpath = props.fileRel # Locale uses this clazz.m_time_ = props.fileStat.st_mtime return clazz, filePathId
def _scanClassPath(self, timeOfLastScan=0): codeIdFromTree = True # switch between regex- and tree-based codeId search # Check class path classPath = os.path.join(self.path, self.classPath) if not os.path.isdir(classPath): raise ConfigurationError( "Class path from Manifest doesn't exist: %s" % self.classPath) # Check multiple namespaces if not len([d for d in os.listdir(classPath) if not d.startswith(".") ]) == 1: self._console.warn( "The class path must contain exactly one namespace; ignoring everything else: '%s'" % (classPath, )) # Check Manifest namespace matches file system nsPrefix = self.namespace.replace(".", os.sep) classNSRoot = os.path.join(classPath, nsPrefix) if not os.path.isdir(classNSRoot): raise ValueError( "Manifest namespace does not exist on file system: '%s'" % (classNSRoot)) self._console.debug("Scanning class folder...") classList = [] existClassIds = dict([(x.id, x) for x in self._classes]) # if we scanned before docs = {} # TODO: Clazz still relies on a context dict! contextdict = {} contextdict["console"] = context.console contextdict["cache"] = context.cache contextdict["jobconf"] = context.jobconf contextdict["envchecksmap"] = {} # Iterate... for root, dirs, files in filetool.walk(classNSRoot): # Filter ignored directories for ignoredDir in dirs: if self._ignoredDirEntries.match(ignoredDir): dirs.remove(ignoredDir) # Add good directories currNameSpace = root[len(classNSRoot + os.sep):] currNameSpace = currNameSpace.replace(os.sep, ".") # TODO: var name # Searching for files for fileName in files: # Ignore dot files if fileName.startswith(".") or self._ignoredDirEntries.match( fileName): continue self._console.dot() # Process path data filePath = os.path.join(root, fileName) fileRel = filePath.replace( classNSRoot + os.sep, "") # now only path fragment *afte* NS fileExt = os.path.splitext(fileName)[-1] fileStat = os.stat(filePath) fileSize = fileStat.st_size fileMTime = fileStat.st_mtime # Compute full URI from relative path fileUri = self.classUri + "/" + fileRel.replace(os.sep, "/") # Compute identifier from relative path filePathId = fileRel.replace(fileExt, "").replace(os.sep, ".") filePathId = self.namespace + "." + filePathId # e.g. "qx.core.Environment" filePathId = unidata.normalize( "NFC", filePathId) # combine combining chars: o" -> ö fileId = nsPrefix + "/" + fileRel # e.g. "qx/core/Environment.js" # check if known and fresh if (filePathId in existClassIds and fileMTime < timeOfLastScan): classList.append(existClassIds[filePathId]) #print "re-using existing", filePathId continue # re-use known class # Extract package ID filePackage = filePathId[:filePathId.rfind(".")] # Handle doc files if fileName == self._docFilename: fileFor = filePathId[:filePathId.rfind(".")] docs[filePackage] = { "relpath": fileId, "path": filePath, "encoding": self.encoding, "namespace": self.namespace, "id": filePathId, "package": filePackage, "size": fileSize } # Stop further processing continue # Ignore non-script if os.path.splitext(fileName)[-1] != ".js": continue if filePathId == "qx.core.Environment": clazz = qcEnvClass(filePathId, filePath, self, contextdict) else: clazz = Class(filePathId, filePath, self, contextdict) # Extract code ID (e.g. class name, mixin name, ...) try: if codeIdFromTree: fileCodeId = self._getCodeId(clazz) else: # Read content fileContent = filetool.read(filePath, self.encoding) fileCodeId = self._getCodeId1(fileContent) except ValueError, e: argsList = [] for arg in e.args: argsList.append(arg) argsList[0] = argsList[0] + u' (%s)' % fileName e.args = tuple(argsList) raise e # Ignore all data files (e.g. translation, doc files, ...) if fileCodeId == None: continue # Compare path and content if fileCodeId != filePathId: self._console.error( "Detected conflict between filename and classname!") self._console.indent() self._console.error("Classname: %s" % fileCodeId) self._console.error("Path: %s" % filePath) self._console.outdent() raise RuntimeError() # Store file data self._console.debug("Adding class %s" % filePathId) clazz.encoding = self.encoding clazz.size = fileSize # dependency logging uses this clazz.package = filePackage # Apiloader uses this clazz.relpath = fileId # Locale uses this clazz.m_time_ = fileStat.st_mtime classList.append(clazz)
def _scanClassPath(self, path, uri, encoding): if not os.path.exists(path): raise ValueError("The given class path does not exist: %s" % path) self._console.debug("Scanning class folder...") classList = {} docs = {} # Iterate... for root, dirs, files in filetool.walk(path): # Filter ignored directories for ignoredDir in dirs: if self._ignoredDirectories.match(ignoredDir): dirs.remove(ignoredDir) # Add good directories currNameSpace = root[len(path + os.sep):] currNameSpace = currNameSpace.replace(os.sep, ".") # Searching for files for fileName in files: # Ignore dot files if fileName.startswith("."): continue # Process path data filePath = os.path.join(root, fileName) fileRel = filePath.replace(path + os.sep, "") fileExt = os.path.splitext(fileName)[-1] fileSize = os.stat(filePath).st_size # Compute full URI from relative path fileUri = uri + "/" + fileRel.replace(os.sep, "/") # Compute identifier from relative path filePathId = fileRel.replace(fileExt, "").replace(os.sep, ".") # Extract package ID filePackage = filePathId[:filePathId.rfind(".")] # Handle doc files if fileName == self._docFilename: fileFor = filePathId[:filePathId.rfind(".")] docs[filePackage] = { "relpath": fileRel, "path": filePath, "encoding": encoding, "namespace": self.namespace, "id": filePathId, "package": filePackage, "size": fileSize } # Stop further processing continue # Ignore non-script if os.path.splitext(fileName)[-1] != ".js": continue # Read content fileContent = filetool.read(filePath, encoding) # Extract code ID (e.g. class name, mixin name, ...) try: fileCodeId = self._getCodeId(fileContent) except ValueError, e: e.args[0] = e.args[0] + u' (%s)' % fileName raise e # Ignore all data files (e.g. translation, doc files, ...) if fileCodeId == None: continue # Compare path and content if fileCodeId != filePathId: self._console.error( "Detected conflict between filename and classname!") self._console.indent() self._console.error("Classname: %s" % fileCodeId) self._console.error("filePathId: %s" % filePathId) self._console.error("Path: %s" % fileRel) self._console.outdent() raise RuntimeError() # Store file data self._console.debug("Adding class %s" % filePathId) classList[filePathId] = { "relpath": fileRel, "path": filePath, "encoding": encoding, "namespace": self.namespace, "id": filePathId, "package": filePackage, "size": fileSize } # TODO: Clazz still relies on a context dict! contextdict = {} contextdict["console"] = context.console contextdict["cache"] = context.cache contextdict["jobconf"] = context.jobconf # TODO: currently creation of throw-away objects (unless they're .append'ed) clazz = Class(classList[filePathId], filePath, self, contextdict, self._classesObj) clazz.encoding = encoding clazz.size = fileSize # dependency logging uses this clazz.package = filePackage # Apiloader uses this
def dependencies(self, classId, classPath, variantSet, force=False): print "\nrunning on Pyro server", str(self.num) c = Class(classId, classPath, None, generator_context, self.classList) d, cached = c.dependencies(variantSet, force) return d, cached
def tree(self, classId, classPath, variantSet): c = Class(classId, classPath, None, generator_context, {}) t = c.tree() return t
def _scanClassPath(self, timeOfLastScan=0): ## # provide a default context dict def get_contextdict(): contextdict = {} contextdict["console"] = context.console contextdict["cache"] = context.cache contextdict["jobconf"] = context.jobconf contextdict["envchecksmap"] = {} return contextdict ## # check class path is on file system def check_class_path(classRoot): if not os.path.isdir(classRoot): raise ConfigurationError( "Class path from Manifest doesn't exist: %s" % self.classPath) ## # check single subdirectory from class path def check_multiple_namespaces(classRoot): try: self._checkNamespace(classRoot) except ValueError: self._console.warn( "The class path should contain exactly one namespace: '%s'" % (classRoot, )) ## # check manifest namespace is on file system def check_manifest_namespace(classRoot): nsPrefix = self.namespace.replace(".", os.sep) classNSRoot = os.path.join(classRoot, nsPrefix) if not os.path.isdir(classNSRoot): raise ValueError( "Manifest namespace does not exist on file system: '%s'" % (classNSRoot)) # ---------------------------------------------------------------------- codeIdFromTree = True # switch between regex- and tree-based codeId search classList = [] existClassIds = dict([(x.id, x) for x in self._classes]) # if we scanned before docs = {} contextdict = get_contextdict( ) # TODO: Clazz() still relies on a context dict! classRoot = os.path.join(self.path, self.classPath) check_class_path(classRoot) check_multiple_namespaces(classRoot) check_manifest_namespace(classRoot) self._console.debug("Scanning class folder...") # Iterate... for root, dirs, files in filetool.walk(classRoot): # Filter ignored directories for ignoredDir in dirs: if self._ignoredDirEntries.match(ignoredDir): dirs.remove(ignoredDir) # Searching for files for fileName in files: # ignore dot files if fileName.startswith(".") or self._ignoredDirEntries.match( fileName): continue self._console.dot() # basic attributes filePath = os.path.join( root, fileName) # /foo/bar/baz/source/class/my/space/AppClass.js fileRel = filePath.replace(classRoot + os.sep, '') # my/space/AppClass.js fileExt = os.path.splitext(fileName)[-1] # "js" filePathId = fileRel.replace(fileExt, "").replace( os.sep, ".") # my.space.AppClass filePathId = unidata.normalize("NFC", filePathId) # o" -> ö filePackage = filePathId[:filePathId.rfind( ".")] if "." in filePathId else "" # my.space fileStat = os.stat(filePath) fileSize = fileStat.st_size fileMTime = fileStat.st_mtime # ignore non-script if fileExt != ".js": continue # check if known and fresh if (filePathId in existClassIds and fileMTime < timeOfLastScan): classList.append(existClassIds[filePathId]) continue # re-use known class # handle doc files if fileName == self._docFilename: docs[filePackage] = { "relpath": fileRel, "path": filePath, "encoding": self.encoding, "namespace": self.namespace, "id": filePathId, "package": filePackage, "size": fileSize } # stop further processing continue if filePathId == "qx.core.Environment": clazz = qcEnvClass(filePathId, filePath, self, contextdict) else: clazz = Class(filePathId, filePath, self, contextdict) # extract code ID (e.g. class name, mixin name, ...) try: if codeIdFromTree: fileCodeId = self._getCodeId(clazz) else: # use regexp fileContent = filetool.read(filePath, self.encoding) fileCodeId = self._getCodeId1(fileContent) except ValueError, e: argsList = [] for arg in e.args: argsList.append(arg) argsList[0] = argsList[0] + u' (%s)' % fileName e.args = tuple(argsList) raise e # ignore all data files (e.g. translation, doc files, ...) if fileCodeId == None: continue # compare path and content if fileCodeId != filePathId: errmsg = [ u"Detected conflict between filename and classname!\n", u" Classname: %s\n" % fileCodeId, u" Path: %s\n" % filePath, ] raise RuntimeError(u''.join(errmsg)) # store file data self._console.debug("Adding class %s" % filePathId) clazz.encoding = self.encoding clazz.size = fileSize # dependency logging uses this clazz.package = filePackage # Apiloader uses this clazz.relpath = fileRel # Locale uses this clazz.m_time_ = fileStat.st_mtime classList.append(clazz)