def loadFile(self, path): _.msg("loading: " + path) path = _.unifyPath(path) if not os.path.isfile(path): self.finer("\nfile not not found or cannot be read: " + path) return None module_ = self.getCachedModule(path) if module_ is not None: self.finer("\nusing cached module " + path + " [succeeded]") return module_ # detect circular import if Analyzer.self.inImportStack(path): return None # set new CWD and save the old one on stack oldcwd = self.cwd self.setCWD(os.path.join(*path.split(os.sep)[:-1])) Analyzer.self.pushImportStack(path) mod = self.parseAndResolve(path) # restore old CWD self.setCWD(oldcwd) return mod
def loadFile(self, path): _.msg("loading: " + path); path = _.unifyPath(path) if not os.path.isfile(path): self.finer("\nfile not not found or cannot be read: " + path) return None module_ = self.getCachedModule(path) if module_ is not None: self.finer("\nusing cached module " + path + " [succeeded]") return module_ # detect circular import if Analyzer.self.inImportStack(path): return None # set new CWD and save the old one on stack oldcwd = self.cwd self.setCWD( os.path.join(*path.split(os.sep)[:-1]) ) Analyzer.self.pushImportStack(path) mod = self.parseAndResolve(path) # restore old CWD self.setCWD(oldcwd) return mod
def createCacheDir(self): """ generated source for method createCacheDir """ self.cacheDir = _.makePathString(_.getSystemTempDir(), "pysonar2", "ast_cache") f = self.cacheDir _.msg("AST cache is at: " + self.cacheDir) if not os.path.exists(f): os.makedirs(f) if not os.path.exists(f): _.die("Failed to create tmp directory: " + self.cacheDir + ".Please check permissions")
def __init__(self): tmpDir = _.getSystemTempDir() sid = _.newSessionId() self.exchangeFile = _.makePathString(tmpDir, "pysonar2", "json." + sid) self.endMark = _.makePathString(tmpDir, "pysonar2", "end." + sid) self.pyStub = _.makePathString(tmpDir, "pysonar2", "ast2json." + sid) # =) you ARE a python process =) #self.startPythonProcesses() if self.python2Process is not None: _.msg("Started: " + self.PYTHON2_EXE) if self.python3Process is not None: _.msg("Started: " + self.PYTHON3_EXE)
def finish(self): """ generated source for method finish """ # progress.end(); _.msg("\nFinished loading files. " + str(self.nCalled) + " functions were called.") _.msg("Analyzing uncalled functions") self.applyUncalled() # mark unused variables for b in self.allBindings: if not b.getType().isClassType() and not b.getType().isFuncType() and not b.getType().isModuleType() and _.isEmpty(b.getRefs()): Analyzer.self.putProblem(b.getNode(), "Unused variable: " + b.__class__.__name__) for ent in self.references.items(): self.convertCallToNew(ent[0], ent[1]) _.msg(self.getAnalysisSummary())
def finish(self): """ generated source for method finish """ # progress.end(); _.msg("\nFinished loading files. " + str(self.nCalled) + " functions were called.") _.msg("Analyzing uncalled functions") self.applyUncalled() # mark unused variables for b in self.allBindings: if not b.getType().isClassType() and not b.getType().isFuncType( ) and not b.getType().isModuleType() and _.isEmpty(b.getRefs()): Analyzer.self.putProblem( b.getNode(), "Unused variable: " + b.__class__.__name__) for ent in self.references.items(): self.convertCallToNew(ent[0], ent[1]) _.msg(self.getAnalysisSummary())
def log(self, level, msg): _.msg(msg)