Exemplo n.º 1
0
    def Do(self):

        import Abby  # for exception

        # Build the import file and wrap it in a stream object
        ## print 'streamtype:',self.streamtype
        # may throw exception if file not found
        stream = Streams.Factory(self.filename, 'r', self.streamtype) 
        layout = Layouts.Factory(self.abby, stream.layouttype)
        
        ## print 'stream:',stream
        ## print 'layout:',layout
        
        #stream.ReadToLayout()
        
        # the stream will return tokens one by one from the file, 
        # and layout will parse the tokens into commands.
        
        # get a composite command object
        ## cmd = layout.ParseFrom(stream)
        ## layoutresult = cmd.Do()
        
        # more efficient to do this way, so don't get a huge honkin composite cmd!
        ob = Objects.Objs()
        errors = []
        try:
            for cmd in layout.Parse(stream):
                try:
                    # cmd will usually be an Add command
                    layout = cmd.Do()
                    #, build up a list of all the objects added so can report to user
                    ob.append(layout.ob)
                except Abby.AbbyError, e:
                    #. add error to a file also?
                    errors.append(str(e))
        except Exception, e: #, Parser.ParserError, e:
            #errors.append(e)
            #errors.append(str(e))
            raise # pass it on