Skip to content
Snippets Groups Projects
Commit 8c9ce466 authored by Henrik tom Wörden's avatar Henrik tom Wörden
Browse files

WIP: no path collision and email

parent dce18d21
No related branches found
No related tags found
2 merge requests!39Release 0.4.0,!20created draft for generic analysis method
Pipeline #16473 passed
......@@ -40,12 +40,44 @@ import numpy as np
from caosadvancedtools.cfood import assure_property_is
from caosadvancedtools.guard import INSERT, UPDATE
from caosadvancedtools.guard import global_guard as guard
from caosadvancedtools.serverside.helper import send_mail as main_send_mail
logger = logging.getLogger(__name__)
guard.set_level(level=UPDATE)
def send_mail(self, changes):
""" calls sendmail in order to send a mail to the curator about pending
changes
Parameters:
-----------
changes: The CaosDB entities in the version after the update.
"""
caosdb_config = db.configuration.get_config()
text = """Dear Curator,
The following changes where done automatically.
{changes}
""".format(changes="\n".join(changes))
try:
fro = caosdb_config["advancedtools"]["automated_updates.from_mail"]
to = caosdb_config["advancedtools"]["automated_updates.to_mail"]
except KeyError:
logger.error("Server Configuration is missing a setting for "
"sending mails. The administrator should check "
"'from_mail' and 'to_mail'.")
return
main_send_mail(
from_addr=fro,
to=to,
subject="Automated Update",
body=text)
def main(args):
# TODO (maybe) can these checks be replaced by a more declaritive appoach?
try:
......@@ -84,19 +116,20 @@ def main(args):
# ####################################################################### #
# Insert the result plot
# TODO (must): how do we find a good file path??
fig = db.File(file=filename,
path="/uploaded/something3/"+str(datetime.now())+filename)
path="/Analysis/results/"+str(datetime.now())+"/"+filename)
fig.insert()
# Add the result to the analysis Record
# An update should only be done if necessary: assure_property_is should be
# used instead of direct calls to 'update'.
to_be_updated = []
assure_property_is(
dataAnalysisRecord,
"mean_value",
mean,
to_be_updated=to_be_updated
)
# TODO (maybe) this is not really meaningful since an uploaded file will always
# be different.... Compare checksums of files?
......@@ -104,7 +137,12 @@ def main(args):
dataAnalysisRecord,
"results",
fig.id,
to_be_updated=to_be_updated
)
if len(to_be_updated) > 0:
send_mail(to_be_updated)
# TODO (must) what should be done with the old file? Removed if not referenced?
# TODO (maybe) inform about updates (reuse stuff from crawler.py?)
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment