def generate(self, outputfile=None, dotfile=None, mapfile=None): """Generates a graph file. :param outputfile: filename and path [defaults to graphname.png] :param dotfile: filename and path [defaults to graphname.dot] :rtype: str :return: a path to the generated file """ import subprocess # introduced in py 2.4 name = self.graphname if not dotfile: # if 'outputfile' is a dot file use it as 'dotfile' if outputfile and outputfile.endswith(".dot"): dotfile = outputfile else: dotfile = '%s.dot' % name if outputfile is not None: storedir, basename, target = target_info_from_filename(outputfile) if target != "dot": pdot, dot_sourcepath = tempfile.mkstemp(".dot", name) os.close(pdot) else: dot_sourcepath = osp.join(storedir, dotfile) else: target = 'png' pdot, dot_sourcepath = tempfile.mkstemp(".dot", name) ppng, outputfile = tempfile.mkstemp(".png", name) os.close(pdot) os.close(ppng) pdot = open(dot_sourcepath, 'w') pdot.write(str_encode(self.source, 'utf8')) pdot.close() if target != 'dot': if sys.platform == 'win32': use_shell = True else: use_shell = False if mapfile: subprocess.call([ self.renderer, '-Tcmapx', '-o', mapfile, '-T', target, dot_sourcepath, '-o', outputfile ], shell=use_shell) else: subprocess.call([ self.renderer, '-T', target, dot_sourcepath, '-o', outputfile ], shell=use_shell) os.unlink(dot_sourcepath) return outputfile
def generate(self, outputfile=None, dotfile=None, mapfile=None): """Generates a graph file. :param outputfile: filename and path [defaults to graphname.png] :param dotfile: filename and path [defaults to graphname.dot] :rtype: str :return: a path to the generated file """ import subprocess # introduced in py 2.4 name = self.graphname if not dotfile: # if 'outputfile' is a dot file use it as 'dotfile' if outputfile and outputfile.endswith(".dot"): dotfile = outputfile else: dotfile = "%s.dot" % name if outputfile is not None: storedir, basename, target = target_info_from_filename(outputfile) if target != "dot": pdot, dot_sourcepath = tempfile.mkstemp(".dot", name) os.close(pdot) else: dot_sourcepath = osp.join(storedir, dotfile) else: target = "png" pdot, dot_sourcepath = tempfile.mkstemp(".dot", name) ppng, outputfile = tempfile.mkstemp(".png", name) os.close(pdot) os.close(ppng) pdot = open(dot_sourcepath, "w") pdot.write(str_encode(self.source, "utf8")) pdot.close() if target != "dot": if sys.platform == "win32": use_shell = True else: use_shell = False if mapfile: subprocess.call( [self.renderer, "-Tcmapx", "-o", mapfile, "-T", target, dot_sourcepath, "-o", outputfile], shell=use_shell, ) else: subprocess.call([self.renderer, "-T", target, dot_sourcepath, "-o", outputfile], shell=use_shell) os.unlink(dot_sourcepath) return outputfile
def generate(self, outputfile=None, dotfile=None, mapfile=None): """Generates a graph file. :param outputfile: filename and path [defaults to graphname.png] :param dotfile: filename and path [defaults to graphname.dot] :rtype: str :return: a path to the generated file """ import subprocess # introduced in py 2.4 name = self.graphname if not dotfile: # if 'outputfile' is a dot file use it as 'dotfile' if outputfile and outputfile.endswith(".dot"): dotfile = outputfile else: dotfile = '%s.dot' % name if outputfile is not None: storedir, basename, target = target_info_from_filename(outputfile) if target != "dot": pdot, dot_sourcepath = tempfile.mkstemp(".dot", name) os.close(pdot) else: dot_sourcepath = osp.join(storedir, dotfile) else: target = 'png' pdot, dot_sourcepath = tempfile.mkstemp(".dot", name) ppng, outputfile = tempfile.mkstemp(".png", name) os.close(pdot) os.close(ppng) pdot = open(dot_sourcepath, 'w') pdot.write(str_encode(self.source, 'utf8')) pdot.close() if target != 'dot': if mapfile: print '%s -Tcmapx -o%s -T%s %s -o%s' % (self.renderer, mapfile, target, dot_sourcepath, outputfile) subprocess.call('%s -Tcmapx -o%s -T%s %s -o%s' % (self.renderer, mapfile, target, dot_sourcepath, outputfile), shell=True) else: subprocess.call('%s -T%s %s -o%s' % (self.renderer, target, dot_sourcepath, outputfile), shell=True) os.unlink(dot_sourcepath) return outputfile