예제 #1
0
파일: Commands.py 프로젝트: bburns/Abby
    def Do(self):
        
        # Build the export file and wrap it in a stream object
        # bug: forgot self in filename in similar case - wound up overwriting stuff.abby file by passing None!!!!!
        # bug: must write in binary mode or screws up endline!!
        stream = Streams.Factory(self.filename, 'wb', self.streamtype)
        
        # Build a list command to get the objects to export
        # export all properties!
        cmd = List(self.abby, self.adjectives, showprops='all') #, groupby, sortby)
        layout = cmd.Do() # don't tie into history
        
        # Pass the layout object to the stream object, which will pull 
        # the information from the layout and write it to the file in the
        # proper format.
        stream.WriteFromLayout(layout)

        #, i think the list command will set this via abby.get!
#        self.abby.it = layout.ob #, set current object(s)

        # wrap the status string in a simple String layout object
        nobjects = len(layout.ob)
        s = "%d objects exported to file '%s'." % (nobjects, self.filename)
#        self.abby.status = s #, standardize this
        return Layouts.String(s)
예제 #2
0
파일: Commands.py 프로젝트: bburns/Abby
    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