Exemplo n.º 1
0
Arquivo: lib.py Projeto: p/midge
def sendmail(to, message):
    """Attempt to send email, and return boolean success."""
    try:
        server = smtplib.SMTP(config.Email.smtp_host)
	from_to_headers = "From: %s\r\nTo: %s\r\n" % (
            config.Email.from_address, to)
        subject = "Subject: Midge password\r\n"
        server.sendmail(config.Email.from_address, [to],
                        subject + from_to_headers + "\r\n" + message)
        server.quit()
        return True
    except (smtplib.SMTPException, socket.error):
        logger.error("Unable to send email")
        logger.exception()
    return False
Exemplo n.º 2
0
def run_sql(database, sql_commands):
    assert database in (config.Database.name, config.Database.test_name)
    connection = psycopg2.connect(
        "dbname=%s user=%s password=%s" % (database, config.Database.user, config.Database.password)
    )
    success = False
    cursor = connection.cursor()
    try:
        cursor.execute(sql_commands)
        connection.commit()
        success = True
    except psycopg2.Error:
        logger.exception()
        connection.rollback()
        success = False
    cursor.close()
    return success
Exemplo n.º 3
0
Arquivo: config.py Projeto: p/midge
 def get_boolean(section, option):
     try:
         return config.getboolean(section, option)
     except Exception:
         logger.exception()
         raise
Exemplo n.º 4
0
Arquivo: config.py Projeto: p/midge
 def get_int(section, option):
     try:
         return config.getint(section, option)
     except Exception:
         logger.exception()
         raise
Exemplo n.º 5
0
Arquivo: config.py Projeto: p/midge
 def items(section):
     try:
         return config.items(section)
     except Exception:
         logger.exception()
         raise