def importGraph(self): # This method is called to import a new graph. # An empty graph to populate is accessible through the "graph" class attribute # (see documentation of class tlp.Graph). # The parameters provided by the user are stored in a Tulip DataSet # and can be accessed through the "dataSet" class attribute # (see documentation of class tlp.DataSet). # The method must return a boolean indicating if the # graph has been successfully imported. # Check that we are using at least Tulip 4.8 if not tulipPluginUtils.tulipVersionCheck(4, 8, 0, self.pluginProgress): return False npmPackageDir = self.dataSet[npmPackageDirParamName] # Check if the directory contains a npm package first rootPackageJson = npmPackageDir + '/package.json' if not os.path.exists(rootPackageJson): if self.pluginProgress: self.pluginProgress.setError('Error : directory ' + npmPackageDir + ' does not seem to contain a npm package.') return False # parse package depedencies graph parsePackageJsonForDependenciesGraph(npmPackageDir, self.graph) # apply a force directed algorithm to draw the graph self.graph.applyLayoutAlgorithm('Fast Multipole Multilevel Embedder (OGDF)') return True
def importGraph(self): # This method is called to import a new graph. # An empty graph to populate is accessible through the "graph" class attribute # (see documentation of class tlp.Graph). # The parameters provided by the user are stored in a Tulip DataSet # and can be accessed through the "dataSet" class attribute # (see documentation of class tlp.DataSet). # The method must return a boolean indicating if the # graph has been successfully imported. # Check that we are using at least Tulip 4.8 if not tulipPluginUtils.tulipVersionCheck(4, 8, 0, self.pluginProgress): return False # get the CMake project source directory path cmakeProjectSourceDir = self.dataSet[cmakeProjectSourceDirParamName] # create a temporary directory that we will use as a CMake binary directory tmpdir = tempfile.mkdtemp() # build the command line to execute cmake and generate the dot files command = self.dataSet[cmakeExecutableParamName] + ' ' + self.dataSet[cmakeParametersParamName] + ' ' \ + ' --graphviz=' + cmakeProjectDotFileName + ' ' + cmakeProjectSourceDir # create a temporary file in which we will redirect stderr stderrfile = tmpdir + '/stderr.txt' # execute the CMake project configuration retval = executeCommand(command, tmpdir, stderrfile, self.pluginProgress) # Special case for MinGW Makefiles as it often fails the first time it is executed # due to the presence of sh.exe in the PATH environemt variable. # It fails the first time CMake is executed but not for the subsequent calls, # so relaunch the CMake configuration if retval != 0 and 'MinGW Makefiles' in self.dataSet[cmakeParametersParamName]: retval = executeCommand(command, tmpdir, stderrfile, self.pluginProgress) # something went wrong if retval != 0: # read stderr file and transmit error string to the plugin progress errors = open(stderrfile, 'rb').read().decode('utf-8') if self.pluginProgress: self.pluginProgress.setError(errors) # remove temporary directory shutil.rmtree(tmpdir) return False # check if CMake has generated the expected dot file cmakeProjectDotFilePath = tmpdir + '/' + cmakeProjectDotFileName if not os.path.exists(cmakeProjectDotFilePath): cmakeProjectDotFilePath = tmpdir + '/' + cmakeProjectDotFileName + '.dot' if not os.path.exists(cmakeProjectDotFilePath): if self.pluginProgress: self.pluginProgress.setError("Error : the graphviz file has not been generated by CMake") # remove temporary directory shutil.rmtree(tmpdir) return False # import the dot file in Tulip trough the graphviz import plugin dotImportParams = tlp.getDefaultPluginParameters("graphviz", self.graph) dotImportParams['file::filename'] = cmakeProjectDotFilePath tlp.importGraph("graphviz", dotImportParams, self.graph) # set some visual attributes to the imported graph self.graph['viewSize'].setAllNodeValue(tlp.Size(1,1,1)) self.graph['viewShape'].setAllNodeValue(tlp.NodeShape.Circle) # apply a force directed algorithm to draw the graph self.graph.applyLayoutAlgorithm('Fast Multipole Multilevel Embedder (OGDF)') # remove temporary directory shutil.rmtree(tmpdir) # done return True