def create(self, prog=None, format='ps'):
        """Creates and returns a Postscript representation of the graph.

        create will write the graph to a temporary dot file and process
        it with the program given by 'prog' (which defaults to 'twopi'),
        reading the Postscript output and returning it as a string is the
        operation is successful.
        On failure None is returned.
        
        There's also the preferred possibility of using:
        
            create_'format'(prog='program')
            
        which are automatically defined for all the supported formats.
        [create_ps(), create_gif(), create_dia(), ...]
        
        If 'prog' is a list instead of a string the fist item is expected
        to be the program name, followed by any optional command-line
        arguments for it:
        
            [ 'twopi', '-Tdot', '-s10' ]
        """
        
        if prog is None:
            prog = self.prog
            
        if isinstance(prog, (list, tuple)):
            prog, args = prog[0], prog[1:]
        else:
            args = []
            
        if self.progs is None:
            self.progs = find_graphviz()
            if self.progs is None:
                raise InvocationException(
                    'GraphViz\'s executables not found' )
                
        if not self.progs.has_key(prog):
            raise InvocationException(
                'GraphViz\'s executable "%s" not found' % prog )
            
        if not os.path.exists( self.progs[prog] ) or not os.path.isfile( self.progs[prog] ):
            raise InvocationException(
                'GraphViz\'s executable "%s" is not a file or doesn\'t exist' % self.progs[prog] )
            
            
        tmp_fd, tmp_name = tempfile.mkstemp()
        os.close(tmp_fd)
        self.write(tmp_name)
        tmp_dir = os.path.dirname(tmp_name )
        
        # For each of the image files...
        #
        for img in self.shape_files:
        
            # Get its data
            #
            f = file(img, 'rb')
            f_data = f.read()
            f.close()
            
            # And copy it under a file with the same name in the temporary directory
            #
            f = file( os.path.join( tmp_dir, os.path.basename(img) ), 'wb' )
            f.write(f_data)
            f.close()
        
        cmdline = [self.progs[prog], '-T'+format, tmp_name] + args
        
        p = subprocess.Popen(
            cmdline,
            cwd=tmp_dir,
            stderr=subprocess.PIPE, stdout=subprocess.PIPE)
            
        stderr = p.stderr
        stdout = p.stdout
        
        stdout_output = list()
        while True:
            data = stdout.read()
            if not data:
                break
            stdout_output.append(data)
        stdout.close()
            
        stdout_output = ''.join(stdout_output)
        
        if not stderr.closed:
            stderr_output = list()
            while True:
                data = stderr.read()
                if not data:
                    break
                stderr_output.append(data)
            stderr.close()
                
            if stderr_output:
                stderr_output = ''.join(stderr_output)
            
        #pid, status = os.waitpid(p.pid, 0)
        status = p.wait()
        
        if status != 0 :
            raise InvocationException(
                'Program terminated with status: %d. stderr follows: %s' % (
                    status, stderr_output) )
        elif stderr_output:
            print stderr_output
        
        # For each of the image files...
        #
        for img in self.shape_files:
        
            # remove it
            #
            os.unlink( os.path.join( tmp_dir, os.path.basename(img) ) )

        os.unlink(tmp_name)
        
        return stdout_output
def create ( self , prog = None , format = 'ps' ) : if prog is None : prog = self . prog if isinstance ( prog , ( list , tuple ) ) : prog , args = prog [ 0 ] , prog [ 1 : ] else : args = [ ] if self . progs is None : self . progs = find_graphviz ( ) if self . progs is None : raise InvocationException ( 'GraphViz\'s executables not found' ) if not self . progs . has_key ( prog ) : raise InvocationException ( 'GraphViz\'s executable "%s" not found' % prog ) if not os . path . exists ( self . progs [ prog ] ) or not os . path . isfile ( self . progs [ prog ] ) : raise InvocationException ( 'GraphViz\'s executable "%s" is not a file or doesn\'t exist' % self . progs [ prog ] ) tmp_fd , tmp_name = tempfile . mkstemp ( ) os . close ( tmp_fd ) self . write ( tmp_name ) tmp_dir = os . path . dirname ( tmp_name ) for img in self . shape_files : f = file ( img , 'rb' ) f_data = f . read ( ) f . close ( ) f = file ( os . path . join ( tmp_dir , os . path . basename ( img ) ) , 'wb' ) f . write ( f_data ) f . close ( ) cmdline = [ self . progs [ prog ] , '-T' + format , tmp_name ] + args p = subprocess . Popen ( cmdline , cwd = tmp_dir , stderr = subprocess . PIPE , stdout = subprocess . PIPE ) stderr = p . stderr stdout = p . stdout stdout_output = list ( ) while True : data = stdout . read ( ) if not data : break stdout_output . append ( data ) stdout . close ( ) stdout_output = '' . join ( stdout_output ) if not stderr . closed : stderr_output = list ( ) while True : data = stderr . read ( ) if not data : break stderr_output . append ( data ) stderr . close ( ) if stderr_output : stderr_output = '' . join ( stderr_output ) status = p . wait ( ) if status != 0 : raise InvocationException ( 'Program terminated with status: %d. stderr follows: %s' % ( status , stderr_output ) ) elif stderr_output : print stderr_output for img in self . shape_files : os . unlink ( os . path . join ( tmp_dir , os . path . basename ( img ) ) ) os . unlink ( tmp_name ) return stdout_output
Creates and returns a Postscript representation of the graph.

        create will write the graph to a temporary dot file and process
        it with the program given by 'prog' (which defaults to 'twopi'),
        reading the Postscript output and returning it as a string is the
        operation is successful.
        On failure None is returned.
        
        There's also the preferred possibility of using:
        
            create_'format'(prog='program')
            
        which are automatically defined for all the supported formats.
        [create_ps(), create_gif(), create_dia(), ...]
        
        If 'prog' is a list instead of a string the fist item is expected
        to be the program name, followed by any optional command-line
        arguments for it:
        
            [ 'twopi', '-Tdot', '-s10' ]