Exemplo n.º 1
0
    def Do(self):
#        filename = '__tempedit.txt'
        newname = self.name[:20].replace(' ','_')
        newname = newname.replace('/','_')
        filename = '__' + newname + '_description.txt'
        # get description
        s = self.obj.GetValue('description') 
        # save it to a temp file
        open(filename,'w').write(s)
        # edit file in notepad
        command = "notepad.exe %s" % filename
        pipe = os.popen(command)
        nada = pipe.read() # pipe will return '' when notepad closes
        # load file
        snew = open(filename,'r').read()
        # if description changed, save to the object
        ischanged = s != snew
        if ischanged:
            self.obj.SetValue('description', snew) # save new description
            status = "Object '%s' edited." % self.name
        else:
            status = "No changes made to object '%s'." % self.name
        # make sure to delete the temporary file also
        os.remove(filename)
        # set current object
        self.abby.it = self.obj 
        # return status message
        layout = Layouts.String(status)
        return layout
Exemplo n.º 2
0
    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)
Exemplo n.º 3
0
    def Do(self):
        
        # this can throw an exception - let caller handle it.
        obj = self.abby.Add(self.type,self.name,self.description) #,self.altname)

        # set any adjectives
        # bug: had a loop here using obj as loop variable also, clobbering the original obj!!
        obj.PutIn(self.adjectives)

        # set any other property values defined in the assignments object
#        self.assignments.ApplyToObj(obj)

        # save state for undo
        self.id = obj.id

        # set abby.it
        self.abby.it = obj

        #, resolve this (string vs view of object...)
        if len(obj.name) > 30:
            name = obj.name[:30]+'...'
        else:
            name = obj.name
        s = "Added %s '%s'." % (obj.type, name)
        return Layouts.String(s)
Exemplo n.º 4
0
 def Do(self):
     # put the objects in the given adjectives
     # eg 'put alarmclock in kalispell' is equivalent to 'alarmclock.company = kalispell'
     for obj in self.ob:
         obj.PutIn(self.adjectives)
     
     # set abby.it
     self.abby.it = self.ob
     s = 'Put %s in %s' % (self.ob, self.adjectives)
     layout = Layouts.String(s)
     return layout        
Exemplo n.º 5
0
    def Do(self):

        # build command to start browser...
        #. use popen to hide cmd console
        url = "http://www.google.com/search?q=dictionary+etymology+" + self.name
        browser = r'C:\Program Files\Mozilla Firefox\firefox.exe'
        cmd = ''' "%s" %s '''  % (firefox, url)
        log.debug(cmd)
        os.system(cmd)

        # return status message
        status = "Looked up '%s' in Google" % self.name
        layout = Layouts.String(status)
        return layout
Exemplo n.º 6
0
    def Do(self):

        #, modify the objects in the list
#        self.ob.SetValue(self.propname, self.propvalue)

        # for now assert just one object
        assert(len(self.ob)==1)
        obj = self.ob[0]
#        obj.SetValue(self.propname, self.propvalue)
        obj.SetData(self.prop, self.data)
        
        s = "Set %s.%s to %s" % (obj, self.prop, self.data)
        self.abby.status = s #, update abby status
        self.abby.it = obj
        log.debug('set abby.it to %s' % obj)
        return Layouts.String(s)
Exemplo n.º 7
0
 def Do(self):
     self.abby.Save()
     s = "%d objects saved to file '%s'." % (len(self.abby), self.abby.filename)
     return Layouts.String(s)
Exemplo n.º 8
0
class Import(Command):
    
    name = "Import"
    type = "Command"
    description = "Import objects from a file into the main namespace."
    example = "import words from 'test.txt'"
    grammar = "IMPORT [adjectives] [FROM] filename"
    code = "cmd = Commands.Import(adjectives, filename)"
    
    def __init__(self, abby, filename, streamtype=None):
        self.abby = abby
        self.filename = filename
        self.streamtype = streamtype

    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
            
        nobjs = len(ob)
        nerrors = len(errors)
        self.abby.it = ob #, set current object(s)
        s = "%d objects imported from file '%s' [%d errors]." % (nobjs, self.filename, nerrors)
        if errors:
            s = s + '\nErrors:\n\t' + '\n\t'.join(errors)
        return Layouts.String(s)
Exemplo n.º 9
0
 def Do(self):
     self.abby.Delete(self.ob)
     s = "Deleted '%s'." % self.name
     return Layouts.String(s)
Exemplo n.º 10
0
 def Do(self):
     self.abby.SetDebug(self.debug)
     ## self.abby.debug = not self.abby.debug
     s = "Debug set to %s" % self.debug
     return Layouts.String(s)
Exemplo n.º 11
0
 def Do(self):
     # should always return a layout object
     return Layouts.String('(did nothing)')
Exemplo n.º 12
0
 def Do(self):
     s = self.abby.Verify()
     return Layouts.String(s)
Exemplo n.º 13
0
 def Do(self):
     # open a pipe to the shell command
     # the pipe is like a file object, which you read
     pipe = os.popen(self.s)
     s = pipe.read()
     return Layouts.String(s)
Exemplo n.º 14
0
 def GetLayout(self, abby, showprops):
     data = self.obj.GetData(self.prop)
     log.debug('getlayout: data=%s' % data)
     s = data.GetString()
     return Layouts.String(s)