Example #1
0
    def _read_predgraph(self):
        """
        development method, doesn't use it
        """
        #assume that filepath is the c2 and dotpath is the dot
        if not self.silent:
            print "Reading", self.filepath

        if os.path.exists(self.filepath):
            self.load_c2()
            return None

        if not self.get_keyOnDataset():
            raise IOError("Key on dataset not defined! Cannot find c2 and cannot convert from dot")
                    
        if os.path.exists(self.dotpath):
            dot.to_c2(self.dotpath,self.filepath,self.get_keyOnDataset())
            self.load_c2()
            return None

        if os.path.exists(self.dotpath+'.bz2'):
            from trustlet.helpers import tempnam
            tmppath = tempnam()
            f = file(tmppath,'w')
            try:
                from bz2 import BZ2File
                f.write(BZ2File(self.dotpath+'.bz2').read())
                f.close()
            except ImportError:
                os.system('bzcat "%s" > "%s"' % (self.dotpath,tmppath))
    
            dot.to_c2(tmppath,self.filepath,self.get_keyOnDataset())
            self.load_c2()
            return None
Example #2
0
    def _write_pred_graph_dot(self, pred_graph):
        """Write PredGraph.dot."""
        if not self.silent:
            print "Writing", self.filepath,
            print "-", len(pred_graph.nodes()),
            print "nodes", len(pred_graph.edges()), "edges"
        
        import os
        
        name = tempnam()

        if not self.silent:
            print pred_graph.edges()[0]

        write_dot(pred_graph, name)

        try:
            from bz2 import BZ2File
            BZ2File( self.filepath+'.bz2' , 'w' ).write( file( name ).read() )
        except:
            os.system( 'bzip2 -z "'+name+'" -c > "'+self.filepath+'.bz2"' )
Example #3
0
    def _write_pred_graph_dot(self, pred_graph):
        """Write PredGraph.dot."""
        if not self.silent:
            print "Writing", self.filepath,
            print "-", len(pred_graph.nodes()),
            print "nodes", len(pred_graph.edges()), "edges"

        import os

        name = tempnam()

        if not self.silent:
            print pred_graph.edges()[0]

        write_dot(pred_graph, name)

        try:
            from bz2 import BZ2File
            BZ2File(self.filepath + '.bz2', 'w').write(file(name).read())
        except:
            os.system('bzip2 -z "' + name + '" -c > "' + self.filepath +
                      '.bz2"')
Example #4
0
    def _read_predgraph(self):
        """
        development method, doesn't use it
        """
        #assume that filepath is the c2 and dotpath is the dot
        if not self.silent:
            print "Reading", self.filepath

        if os.path.exists(self.filepath):
            self.load_c2()
            return None

        if not self.get_keyOnDataset():
            raise IOError(
                "Key on dataset not defined! Cannot find c2 and cannot convert from dot"
            )

        if os.path.exists(self.dotpath):
            dot.to_c2(self.dotpath, self.filepath, self.get_keyOnDataset())
            self.load_c2()
            return None

        if os.path.exists(self.dotpath + '.bz2'):
            from trustlet.helpers import tempnam
            tmppath = tempnam()
            f = file(tmppath, 'w')
            try:
                from bz2 import BZ2File
                f.write(BZ2File(self.dotpath + '.bz2').read())
                f.close()
            except ImportError:
                os.system('bzcat "%s" > "%s"' % (self.dotpath, tmppath))

            dot.to_c2(tmppath, self.filepath, self.get_keyOnDataset())
            self.load_c2()
            return None