replace the return with an else: statement after config reading

This commit is contained in:
Schrolli 2015-06-29 12:25:21 +02:00
parent 95d2d2f119
commit 6371d1cf3c
6 changed files with 374 additions and 383 deletions

View file

@ -118,110 +118,109 @@ def run(typ,freq,data):
except:
logging.error("cannot read config file")
logging.debug("cannot read config file", exc_info=True)
# Without config, plugin couldn't work
return
else: # Without config, plugin couldn't work
try:
#
# connect to SMTP-Server
#
server = smtplib.SMTP(globals.config.get("eMail", "smtp_server"), globals.config.get("eMail", "smtp_port"))
# debug-level to shell (0=no debug|1)
server.set_debuglevel(0)
# if tls is enabled, starttls
if globals.config.get("eMail", "tls"):
server.starttls()
# if user is given, login
if globals.config.get("eMail", "user"):
server.login(globals.config.get("eMail", "user"), globals.config.get("eMail", "password"))
except:
logging.error("cannot connect to eMail")
logging.debug("cannot connect to eMail", exc_info=True)
# Without connection, plugin couldn't work
return
else:
if typ == "FMS":
logging.debug("Start FMS to eMail")
try:
# read subject-structure from config.ini
subject = globals.config.get("eMail", "fms_subject")
subject = subject.replace("%FMS%", data["fms"]).replace("%STATUS%", data["status"]) #replace Wildcards
subject = subject.replace("%DIR%", data["direction"]).replace("%DIRT%", data["directionText"]) #replace Wildcards
subject = subject.replace("%TSI%", data["tsi"]) #replace Wildcards
subject = subject.replace("%DESCR%", data["description"]) # replace Wildcards
subject = subject.replace("%TIME%", curtime()) # replace Wildcards
# read mailtext-structure from config.ini
mailtext = globals.config.get("eMail", "fms_message")
mailtext = mailtext.replace("%FMS%", data["fms"]).replace("%STATUS%", data["status"]) #replace Wildcards
mailtext = mailtext.replace("%DIR%", data["direction"]).replace("%DIRT%", data["directionText"]) #replace Wildcards
mailtext = mailtext.replace("%TSI%", data["tsi"]) #replace Wildcards
mailtext = mailtext.replace("%DESCR%", data["description"]) # replace Wildcards
mailtext = mailtext.replace("%TIME%", curtime()) # replace Wildcards
# send eMail
doSendmail(server, subject, mailtext)
except:
logging.error("%s to eMail failed", typ)
logging.debug("%s to eMail failed", typ, exc_info=True)
return
elif typ == "ZVEI":
logging.debug("Start ZVEI to eMail")
try:
# read subject-structure from config.ini
subject = globals.config.get("eMail", "zvei_subject")
subject = subject.replace("%ZVEI%", data["zvei"]) #replace Wildcards
subject = subject.replace("%DESCR%", data["description"]) # replace Wildcards
subject = subject.replace("%TIME%", curtime()) # replace Wildcards
# read mailtext-structure from config.ini
mailtext = globals.config.get("eMail", "zvei_message")
mailtext = mailtext.replace("%ZVEI%", data["zvei"]) #replace Wildcards
mailtext = mailtext.replace("%DESCR%", data["description"]) # replace Wildcards
mailtext = mailtext.replace("%TIME%", curtime()) # replace Wildcards
# send eMail
doSendmail(server, subject, mailtext)
except:
logging.error("%s to eMail failed", typ)
logging.debug("%s to eMail failed", typ, exc_info=True)
return
elif typ == "POC":
logging.debug("Start POC to eMail")
try:
# read subject-structure from config.ini
subject = globals.config.get("eMail", "poc_subject")
subject = subject.replace("%RIC%", data["ric"]) #replace Wildcards
subject = subject.replace("%FUNC%", data["function"]).replace("%FUNCCHAR%", data["functionChar"]) #replace Wildcards
subject = subject.replace("%MSG%", data["msg"]).replace("%BITRATE%", str(data["bitrate"])) #replace Wildcards
subject = subject.replace("%DESCR%", data["description"]) # replace Wildcards
subject = subject.replace("%TIME%", curtime()) # replace Wildcards
# read mailtext-structure from config.ini
mailtext = globals.config.get("eMail", "poc_message")
mailtext = mailtext.replace("%RIC%", data["ric"]) #replace Wildcards
mailtext = mailtext.replace("%FUNC%", data["function"]).replace("%FUNCCHAR%", data["functionChar"]) #replace Wildcards
mailtext = mailtext.replace("%MSG%", data["msg"]).replace("%BITRATE%", str(data["bitrate"])) #replace Wildcards
mailtext = mailtext.replace("%DESCR%", data["description"]) # replace Wildcards
mailtext = mailtext.replace("%TIME%", curtime()) # replace Wildcards
# send eMail
doSendmail(server, subject, mailtext)
except:
logging.error("%s to eMail failed", typ)
logging.debug("%s to eMail failed", typ, exc_info=True)
return
else:
logging.warning("Invalid Typ: %s", typ)
finally:
logging.debug("close eMail-Connection")
try:
server.quit()
try:
#
# connect to SMTP-Server
#
server = smtplib.SMTP(globals.config.get("eMail", "smtp_server"), globals.config.get("eMail", "smtp_port"))
# debug-level to shell (0=no debug|1)
server.set_debuglevel(0)
# if tls is enabled, starttls
if globals.config.get("eMail", "tls"):
server.starttls()
# if user is given, login
if globals.config.get("eMail", "user"):
server.login(globals.config.get("eMail", "user"), globals.config.get("eMail", "password"))
except:
pass
logging.error("cannot connect to eMail")
logging.debug("cannot connect to eMail", exc_info=True)
# Without connection, plugin couldn't work
return
else:
if typ == "FMS":
logging.debug("Start FMS to eMail")
try:
# read subject-structure from config.ini
subject = globals.config.get("eMail", "fms_subject")
subject = subject.replace("%FMS%", data["fms"]).replace("%STATUS%", data["status"]) #replace Wildcards
subject = subject.replace("%DIR%", data["direction"]).replace("%DIRT%", data["directionText"]) #replace Wildcards
subject = subject.replace("%TSI%", data["tsi"]) #replace Wildcards
subject = subject.replace("%DESCR%", data["description"]) # replace Wildcards
subject = subject.replace("%TIME%", curtime()) # replace Wildcards
# read mailtext-structure from config.ini
mailtext = globals.config.get("eMail", "fms_message")
mailtext = mailtext.replace("%FMS%", data["fms"]).replace("%STATUS%", data["status"]) #replace Wildcards
mailtext = mailtext.replace("%DIR%", data["direction"]).replace("%DIRT%", data["directionText"]) #replace Wildcards
mailtext = mailtext.replace("%TSI%", data["tsi"]) #replace Wildcards
mailtext = mailtext.replace("%DESCR%", data["description"]) # replace Wildcards
mailtext = mailtext.replace("%TIME%", curtime()) # replace Wildcards
# send eMail
doSendmail(server, subject, mailtext)
except:
logging.error("%s to eMail failed", typ)
logging.debug("%s to eMail failed", typ, exc_info=True)
return
elif typ == "ZVEI":
logging.debug("Start ZVEI to eMail")
try:
# read subject-structure from config.ini
subject = globals.config.get("eMail", "zvei_subject")
subject = subject.replace("%ZVEI%", data["zvei"]) #replace Wildcards
subject = subject.replace("%DESCR%", data["description"]) # replace Wildcards
subject = subject.replace("%TIME%", curtime()) # replace Wildcards
# read mailtext-structure from config.ini
mailtext = globals.config.get("eMail", "zvei_message")
mailtext = mailtext.replace("%ZVEI%", data["zvei"]) #replace Wildcards
mailtext = mailtext.replace("%DESCR%", data["description"]) # replace Wildcards
mailtext = mailtext.replace("%TIME%", curtime()) # replace Wildcards
# send eMail
doSendmail(server, subject, mailtext)
except:
logging.error("%s to eMail failed", typ)
logging.debug("%s to eMail failed", typ, exc_info=True)
return
elif typ == "POC":
logging.debug("Start POC to eMail")
try:
# read subject-structure from config.ini
subject = globals.config.get("eMail", "poc_subject")
subject = subject.replace("%RIC%", data["ric"]) #replace Wildcards
subject = subject.replace("%FUNC%", data["function"]).replace("%FUNCCHAR%", data["functionChar"]) #replace Wildcards
subject = subject.replace("%MSG%", data["msg"]).replace("%BITRATE%", str(data["bitrate"])) #replace Wildcards
subject = subject.replace("%DESCR%", data["description"]) # replace Wildcards
subject = subject.replace("%TIME%", curtime()) # replace Wildcards
# read mailtext-structure from config.ini
mailtext = globals.config.get("eMail", "poc_message")
mailtext = mailtext.replace("%RIC%", data["ric"]) #replace Wildcards
mailtext = mailtext.replace("%FUNC%", data["function"]).replace("%FUNCCHAR%", data["functionChar"]) #replace Wildcards
mailtext = mailtext.replace("%MSG%", data["msg"]).replace("%BITRATE%", str(data["bitrate"])) #replace Wildcards
mailtext = mailtext.replace("%DESCR%", data["description"]) # replace Wildcards
mailtext = mailtext.replace("%TIME%", curtime()) # replace Wildcards
# send eMail
doSendmail(server, subject, mailtext)
except:
logging.error("%s to eMail failed", typ)
logging.debug("%s to eMail failed", typ, exc_info=True)
return
else:
logging.warning("Invalid Typ: %s", typ)
finally:
logging.debug("close eMail-Connection")
try:
server.quit()
except:
pass
except:
# something very mysterious