Logo Search packages:      
Sourcecode: jabber-irc version File versions  Download package

def jep0133::Edit_Admin_List_Command::cmdSecondStage (   self,
  conn,
  request 
)

Apply and save the config

Definition at line 284 of file jep0133.py.

00284                                          :
        """Apply and save the config"""
        form = DataForm(node=request.getTag(name='command').getTag(name='x',namespace=NS_DATA))
        session = request.getTagAttr('command','sessionid')
        if self.sessions.has_key(session):
            if self.sessions[session]['jid'] == request.getFrom():
                config.admins = form.getField('adminjids').getValues()
                if len(config.admins) == 1 and len(config.admins[0]) == 0:
                    config.admins = []
                doc = parse(config.configFile)
                admins = doc.getElementsByTagName('admins')[0]
                for el in [x for x in admins.childNodes]:
                    admins.removeChild(el)
                    el.unlink()
                for admin in config.admins:
                    txt = doc.createTextNode('\n        ')
                    admins.appendChild(txt)
                    txt = doc.createTextNode(admin)
                    el = doc.createElement('jid')
                    el.appendChild(txt)
                    admins.appendChild(el)
                txt = doc.createTextNode('\n    ')
                admins.appendChild(txt)
                attrs={'node':request.getTagAttr('command','node'),'sessionid':session,'status':'completed'}
                payload=[]
                try:
                    f = open(config.configFile,'w')
                    doc.writexml(f)
                    f.close()
                except IOError, (errno, strerror):
                    # attrs['status'] = 'canceled' # Psi doesn't display the form if we cancel the command
                    form = DataForm(typ='result',data=[DataField(value="I/O error(%s): %s" % (errno, strerror),typ='fixed')])
                    payload.append(form)
                doc.unlink()
                reply = request.buildReply('result')
                reply.addChild(name='command',namespace=NS_COMMANDS,attrs=attrs,payload=payload)
                self._owner.send(reply)
            else:
                self._owner.send(Error(request,ERR_BAD_REQUEST))
        else:
            self._owner.send(Error(request,ERR_BAD_REQUEST))   
        raise NodeProcessed

    def cmdCancel(self,conn,request):


Generated by  Doxygen 1.6.0   Back to index