Ejemplo n.º 1
0
    def proceedWithFile( self, needToParse = True ):
        """ Taks the file from settings and processes it """

        if needToParse:
            if self.verbose:
                self.logMessage( "Parsing file " + self.fName )
            self.cf = getControlFlowFromFile( self.fName )
            if self.verbose:
                self.logMessage( "Parsed file:" )
                self.logMessage( formatFlow( str( self.cf ) ) )

            if len( self.cf.errors ) != 0:
                self.logMessage( "No drawing due to parsing errors" )
                return

            if len( self.cf.warnings ) != 0:
                self.logMessage( "Parser warnings: " )
                for warn in self.cf.warnings:
                    self.logMessage( str( warn[0] ) + ": " + warn[1] )
        else:
            if self.cf is None:
                self.logMessage( "No control flow object" )
                return
            if len( self.cf.errors ) != 0:
                self.logMessage( "No drawing due to parsing errors" )
                return

        self.scene.clear()

        if self.verbose:
            self.logMessage( "Layouting ..." )
        try:
            # To pick up possibly changed settings
            reload( cflowsettings )
            cflowSettings = cflowsettings.getDefaultCflowSettings( self )
            if DEBUG == True:
                cflowSettings.debug = True

            # Top level canvas has no adress and no parent canvas
            canvas = vcanvas.VirtualCanvas( cflowSettings, None, None, None )
            canvas.layout( self.cf )
            if self.verbose:
                self.logMessage( "Layout is done:" )
                self.logMessage( str( canvas ) )
                self.logMessage( "Rendering ..." )

            width, height = canvas.render()
            if self.verbose:
                self.logMessage( "Rendering is done. Scene size: " +
                                 str( width ) + "x" + str( height ) +
                                 ". Drawing ..." )

            self.scene.setSceneRect( 0, 0, width, height )
            canvas.draw( self.scene, 0, 0 )
        except Exception, exc:
            self.logMessage( "Exception:\n" + str( exc ) )
            raise
Ejemplo n.º 2
0
    def proceedWithFile(self, needToParse=True):
        """ Taks the file from settings and processes it """

        if needToParse:
            if self.verbose:
                self.logMessage("Parsing file " + self.fName)
            self.cf = getControlFlowFromFile(self.fName)
            if self.verbose:
                self.logMessage("Parsed file:")
                self.logMessage(formatFlow(str(self.cf)))

            if len(self.cf.errors) != 0:
                self.logMessage("No drawing due to parsing errors")
                return

            if len(self.cf.warnings) != 0:
                self.logMessage("Parser warnings: ")
                for warn in self.cf.warnings:
                    self.logMessage(str(warn[0]) + ": " + warn[1])
        else:
            if self.cf is None:
                self.logMessage("No control flow object")
                return
            if len(self.cf.errors) != 0:
                self.logMessage("No drawing due to parsing errors")
                return

        self.scene.clear()

        if self.verbose:
            self.logMessage("Layouting ...")
        try:
            # To pick up possibly changed settings
            reload(cflowsettings)
            cflowSettings = cflowsettings.getDefaultCflowSettings(self)
            if DEBUG == True:
                cflowSettings.debug = True

            # Top level canvas has no adress and no parent canvas
            canvas = vcanvas.VirtualCanvas(cflowSettings, None, None, None)
            canvas.layout(self.cf)
            if self.verbose:
                self.logMessage("Layout is done:")
                self.logMessage(str(canvas))
                self.logMessage("Rendering ...")

            width, height = canvas.render()
            if self.verbose:
                self.logMessage("Rendering is done. Scene size: " +
                                str(width) + "x" + str(height) +
                                ". Drawing ...")

            self.scene.setSceneRect(0, 0, width, height)
            canvas.draw(self.scene, 0, 0)
        except Exception, exc:
            self.logMessage("Exception:\n" + str(exc))
            raise
Ejemplo n.º 3
0
def cdmcfparserTest( files ):
    " Loop for the codimension parser "
    count = 0
    for item in files:
#        print "Processing " + item + " ..."
        tempObj = getControlFlowFromFile( item )
        count += 1
    print "cdmcf: processed " + str(count) + " file(s)"
    return
Ejemplo n.º 4
0
    def test_errors( self ):
        " Test errors "

        pythonFile = self.dir + "errors.py"
        info = getControlFlowFromFile( pythonFile )
        self.failUnless( info.isOK != True )

        outFileName = pythonFile.replace( ".py", ".out" )
        outFile = open( outFileName, "w" )
        outFile.write( formatFlow( str( info ) ) + "\n" )
        outFile.close()

        okFileName = pythonFile.replace( ".py", ".ok" )
        self.failUnless( files_equal( outFileName, okFileName ),
                         "errors test failed" )
        return
Ejemplo n.º 5
0
    def test_wrong_indent( self ):
        " Test wrong indent "

        pythonFile = self.dir + "wrong_indent.py"
        info = getControlFlowFromFile( pythonFile )
        if info.isOK == True:
            self.fail( "Expected parsing error for file " + pythonFile +
                       ". Option: directly from file." )

        outFileName = pythonFile.replace( ".py", ".out" )
        outFile = open( outFileName, "w" )
        outFile.write( str( info ) + "\n" )
        outFile.close()

        okFileName = pythonFile.replace( ".py", ".ok" )
        if not files_equal( outFileName, okFileName ):
            self.fail( "wrong indent test failed" )
        return
Ejemplo n.º 6
0
    def meat( self, pythonFile, errorMsg, expectedOK = True ):
        " The test process meat "

        controlFlow = getControlFlowFromFile( pythonFile )
        if controlFlow.isOK != expectedOK:
            self.fail( "Error parsing the file " + pythonFile +
                       ". Option: directly from a file." )

        f = open( pythonFile )
        content = f.read()
        f.close()

        controlFlow = getControlFlowFromMemory( content )
        if controlFlow.isOK != expectedOK:
            self.fail( "Error parsing the file " + pythonFile +
                       ". Option: from memory." )

        outFileName = pythonFile.replace( ".py", ".out" )
        outFile = open( outFileName, "w" )
        outFile.write( formatFlow( str( controlFlow ) ) + "\n" )
        outFile.close()

        okFileName = pythonFile.replace( ".py", ".ok" )
        if files_equal( outFileName, okFileName ):
            return

        # Python 3 may serialize dictionary items in different order depending
        # on a particular run. This causes troubles with .ok file which
        # can have only one order. This is a quick and dirty workaround.
        index = 1
        while True:
            okFileNameOption = okFileName + str( index )
            if not os.path.exists( okFileNameOption ):
                break       # Bad: no option matched
            if files_equal( outFileName, okFileNameOption ):
                return      # Good: matched

            index += 1

        self.fail( errorMsg )
        return
Ejemplo n.º 7
0
    def meat( self, pythonFile, errorMsg ):
        " The test process meat "

        controlFlow = getControlFlowFromFile( pythonFile )
        self.failUnless( controlFlow.isOK == True )

        f = open( pythonFile )
        content = f.read()
        f.close()

        controlFlow = getControlFlowFromMemory( content )
        self.failUnless( controlFlow.isOK == True )

        outFileName = pythonFile.replace( ".py", ".out" )
        outFile = open( outFileName, "w" )
        outFile.write( formatFlow( str( controlFlow ) ) + "\n" )
        outFile.close()

        okFileName = pythonFile.replace( ".py", ".ok" )
        self.failUnless( files_equal( outFileName, okFileName ),
                         errorMsg )
        return
Ejemplo n.º 8
0
            result += sym
            continue
        if sym == ">":
            shift = shifts[ -1 ] - 1
            result += '\n'
            result += shift * " "
            pos = shift
            result += sym
            pos += 1
            if index < maxIndex:
                if s[ index + 1 ] == '>':
                    del shifts[ -1 ]
            continue
        result += sym
        pos += 1
    return result


from cdmcf import getControlFlowFromFile, VERSION

if len( sys.argv ) != 2:
    print >> sys.stderr, "Single file name is expected"
    sys.exit( 1 )

print "Running control flow parser version: " + VERSION

controlFlow = getControlFlowFromFile( sys.argv[ 1 ] )
print formatFlow( str( controlFlow ) )
sys.exit( 0 )