def getGraphvizVersion(): " Provides the graphviz version " from globals import GlobalData if not GlobalData().graphvizAvailable: return "Not installed", None path = find_executable( "dot" ) if not path: return "Not installed", None from misc import safeRunWithStderr try: stdOut, stdErr = safeRunWithStderr( [ path, "-V" ] ) for line in stdErr.splitlines(): # E.g. dot - graphviz version 2.26.3 (20100126.1600) line = line.strip() if line.startswith( "dot - graphviz version " ): line = line.replace( "dot - graphviz version ", "" ) parts = line.split( " " ) if len( parts ) == 2 and parts[ 0 ][ 0 ].isdigit(): return parts[ 0 ], path except: return "Not installed", None return "could not determine", path
def getTerminalCommandToProfile(fileName, workingDir, arguments, terminalType, closeTerminal, port): " Provides a command to run a separate shell terminal " if os.name != 'posix': raise Exception("Cannot guess terminal command.") pythonExec = sys.executable shell = getUserShell() if terminalType == TERM_REDIRECT: logging.warning("Profiling with redirected IO to IDE has not been " "implemented yet. Falling back to xterm...") terminalStartCmd = getStartTerminalCommand(TERM_XTERM) else: terminalStartCmd = getStartTerminalCommand(terminalType) args = "" for index in xrange(len(arguments)): args += ' "$CDM_ARG' + str(index) + '"' if closeTerminal: exit_if_ok = EXIT_IF_OK else: exit_if_ok = "" # Calculate the procfeedback.py path. procfeedbackPath = os.path.sep.join( [os.path.dirname(sys.argv[0]), "utils", "procfeedback.py"]) # Decide where to store the profiling output from globals import GlobalData outputPath = GlobalData().getProfileOutputPath() if terminalStartCmd in __osSpawnForProfile: return __osSpawnForProfile[terminalStartCmd] % { 'shell': shell, 'wdir': workingDir, 'exec': pythonExec, 'options': fileName + args, 'out': outputPath, 'fb': procfeedbackPath, 'port': port, 'exit_if_ok': exit_if_ok } return __osSpawnForProfile[os.name] % { 'term': terminalStartCmd, 'shell': shell, 'wdir': workingDir, 'exec': pythonExec, 'options': fileName + args, 'out': outputPath, 'fb': procfeedbackPath, 'port': port, 'exit_if_ok': exit_if_ok }
def getProjectTemplateFile(): " Provides the name of the project template file " project = GlobalData().project if project.isLoaded(): # Project is loaded - use from the project dir projectDir = os.path.dirname(project.fileName) if not projectDir.endswith(os.path.sep): projectDir += os.path.sep return projectDir + templateFileName return None
def getPyLintVersion(): " Provides pylint version " from globals import GlobalData if not GlobalData().pylintAvailable: return "Not installed", None from pylintparser.pylintparser import Pylint lint = Pylint() try: version = lint.getVersion() if version: return version, lint.getPath() return "could not determine", lint.getPath() except: return "Not installed", None
def getCodimensionVersion(): " Provides the IDE version " from globals import GlobalData import sys return GlobalData().version, abspath( sys.argv[ 0 ] )
def getNewFileTemplate(): " Searches for the template file and fills fields in it " templateFile = getProjectTemplateFile() if templateFile is None: templateFile = getIDETemplateFile() elif not os.path.exists(templateFile): templateFile = getIDETemplateFile() if not os.path.exists(templateFile): return "" # read the file content content = [] f = open(templateFile, "r") for line in f: content.append(line.rstrip()) f.close() # substitute the fields project = GlobalData().project projectLoaded = project.isLoaded() if projectLoaded: subs = [(re.compile(re.escape('$projectdate'), re.I), project.creationDate), (re.compile(re.escape('$author'), re.I), project.author), (re.compile(re.escape('$license'), re.I), project.license), (re.compile(re.escape('$copyright'), re.I), project.copyright), (re.compile(re.escape('$version'), re.I), project.version), (re.compile(re.escape('$email'), re.I), project.email)] else: subs = [] # Common substitutions subs.append((re.compile(re.escape('$date'), re.I), getLocaleDate())) subs.append((re.compile(re.escape('$time'), re.I), getLocaleTime())) subs.append((re.compile(re.escape('$user'), re.I), getpass.getuser())) if projectLoaded: # description could be multilined so it is a different story descriptionRegexp = re.compile(re.escape('$description'), re.I) description = project.description.split('\n') result = [] for line in content: for key, value in subs: line = re.sub(key, value, line) if projectLoaded: # description part if so match = re.search(descriptionRegexp, line) if match is not None: # description is in the line leadingPart = line[:match.start()] trailingPart = line[match.end():] for dline in description: result.append(leadingPart + dline + trailingPart) else: result.append(line) else: result.append(line) return "\n".join(result)