def aceptar(self, widget): self._wndAtenticacion.hide() self.app.set_mensaje("Autenticando usuario") username = self._user.get_text() password = self._pass.get_text() values = { 'username': username, 'password': password } url_base = '%s://%s' % (PROTOCOLO_CERTS, self.config.HOST_CERTS) url_login = '******' % (url_base, URL_LOGIN_CERTS) data = urllib.urlencode(values) req = urllib2.Request(url_login, data) try: response = urllib2.urlopen(req) data = response.read() # TODO: el json viene escapado. solucionar el doble load. response_data = loads(data) response_auth = response_data.get('authenticated') response_mesg = response_data.get('message') response_certs = response_data.get('certs') if response_auth == 1: if not response_mesg: if len(response_certs): self.app.set_mensaje(MSG_DESCARGANDO_CERTS) #TODO or not TODO: si es tecnico en mas de una escuela # toma el último según el orden en que se envia la # lista. try: establecimiento, archivo = response_certs.pop() destino = download(url_base, archivo, username, password) faltan_archivos, archivos_danados = \ importar_claves(destino, self.config) if faltan_archivos: self.app.set_mensaje(MSG_FALTAN_CERTIFICADOS) elif archivos_danados: self.app.set_mensaje(MSG_CERTIFICADOS_DANADOS) else: self.app.set_mensaje(MSG_CLAVES_IMPORTADAS) except urllib2.HTTPError: self.app.set_mensaje(MSG_ERROR_BAJAR_CERT) except Exception: self.app.set_mensaje(MSG_ERROR_BAJAR_CERT_GRAVE) else: self.app.set_mensaje(MSG_NO_HAY_CLAVES) else: self.app.set_mensaje(response_mesg) elif response_auth == 0: self.app.set_mensaje(MSG_WRONG_PASS) else: self.app.set_mensaje(response_mesg) except urllib2.HTTPError: self.app.set_mensaje(MSG_ERROR_COMUNICACION)
def aceptar(self, widget): tar_filename = self._wndImportarClaves.get_filename() faltan_archivos, archivos_danados = importar_claves(tar_filename, self.config) self._wndImportarClaves.hide() if faltan_archivos: msg = MSG_FALTAN_CERTIFICADOS tipo_msg = gtk.MESSAGE_ERROR elif archivos_danados: msg = MSG_CERTIFICADOS_DANADOS tipo_msg = gtk.MESSAGE_ERROR else: msg = MSG_CLAVES_IMPORTADAS tipo_msg = gtk.MESSAGE_INFO dialog = gtk.MessageDialog(self._wndImportarClaves, gtk.DIALOG_MODAL, tipo_msg, gtk.BUTTONS_CLOSE, msg) dialog.run() dialog.destroy()