cwconfig.py
changeset 5201 2b4267157f85
parent 5163 3079b8345915
parent 5198 cf8292f80384
child 5274 16461f675734
equal deleted inserted replaced
5196:d14bfd477c44 5201:2b4267157f85
  1056         sourcedirs = [join(path, 'i18n') for path in self.cubes_path()]
  1056         sourcedirs = [join(path, 'i18n') for path in self.cubes_path()]
  1057         sourcedirs.append(self.i18n_lib_dir())
  1057         sourcedirs.append(self.i18n_lib_dir())
  1058         return i18n.compile_i18n_catalogs(sourcedirs, i18ndir, langs)
  1058         return i18n.compile_i18n_catalogs(sourcedirs, i18ndir, langs)
  1059 
  1059 
  1060     def sendmails(self, msgs):
  1060     def sendmails(self, msgs):
  1061         """msgs: list of 2-uple (message object, recipients)"""
  1061         """msgs: list of 2-uple (message object, recipients). Return False
       
  1062         if connection to the smtp server failed, else True.
       
  1063         """
  1062         server, port = self['smtp-host'], self['smtp-port']
  1064         server, port = self['smtp-host'], self['smtp-port']
  1063         SMTP_LOCK.acquire()
  1065         SMTP_LOCK.acquire()
  1064         try:
  1066         try:
  1065             try:
  1067             try:
  1066                 smtp = SMTP(server, port)
  1068                 smtp = SMTP(server, port)
  1067             except Exception, ex:
  1069             except Exception, ex:
  1068                 self.exception("can't connect to smtp server %s:%s (%s)",
  1070                 self.exception("can't connect to smtp server %s:%s (%s)",
  1069                                server, port, ex)
  1071                                server, port, ex)
  1070                 return
  1072                 return False
  1071             heloaddr = '%s <%s>' % (self['sender-name'], self['sender-addr'])
  1073             heloaddr = '%s <%s>' % (self['sender-name'], self['sender-addr'])
  1072             for msg, recipients in msgs:
  1074             for msg, recipients in msgs:
  1073                 try:
  1075                 try:
  1074                     smtp.sendmail(heloaddr, recipients, msg.as_string())
  1076                     smtp.sendmail(heloaddr, recipients, msg.as_string())
  1075                 except Exception, ex:
  1077                 except Exception, ex:
  1076                     self.exception("error sending mail to %s (%s)",
  1078                     self.exception("error sending mail to %s (%s)",
  1077                                    recipients, ex)
  1079                                    recipients, ex)
  1078             smtp.close()
  1080             smtp.close()
  1079         finally:
  1081         finally:
  1080             SMTP_LOCK.release()
  1082             SMTP_LOCK.release()
       
  1083         return True
  1081 
  1084 
  1082 set_log_methods(CubicWebConfiguration, logging.getLogger('cubicweb.configuration'))
  1085 set_log_methods(CubicWebConfiguration, logging.getLogger('cubicweb.configuration'))
  1083 
  1086 
  1084 # alias to get a configuration instance from an instance id
  1087 # alias to get a configuration instance from an instance id
  1085 instance_configuration = CubicWebConfiguration.config_for
  1088 instance_configuration = CubicWebConfiguration.config_for