Belle II Software  release-08-01-10
Mails Class Reference

Provides functionality to send mails in case of failed scripts / validation plots. More...

Public Member Functions

def __init__ (self, validation, include_expert_plots=False)
 Initializes an instance of the Mail class from an instance of the Validation class. More...
 
def send_all_mails (self, incremental=None)
 
def write_log (self)
 

Private Member Functions

Dict[str, Dict[str, str]] _create_mail_log_failed_scripts (self)
 Looks up all scripts that failed and collects information about them. More...
 
Dict[str, Dict[str, Dict[str, str]]] _create_mail_log (self, comparison, include_expert_plots=False)
 Takes the entire comparison json file, finds all the plots where comparison failed, finds info about failed scripts and saves them in the following format: More...
 

Static Private Member Functions

Dict[str, Dict[str, Dict[str, str]]] _flag_new_failures (Dict[str, Dict[str, Dict[str, str]]] mail_log, Optional[Dict[str, Dict[str, Dict[str, str]]]] old_mail_log)
 
bool _check_if_same (Dict[str, Dict[str, str]] plot_errors)
 
def _compose_message (plots, incremental=True)
 Takes a dict (like in _create_mail_log) and composes a mail body. More...
 
bool _force_full_report ()
 

Private Attributes

 _validator
 Instance of validation.Validation.
 
 _mail_data_old
 Yesterday's mail data (generated from comparison_json). More...
 
 _mail_data_new
 Current mail data. More...
 

Detailed Description

Provides functionality to send mails in case of failed scripts / validation plots.

The mail data is built upon instantiation, the send_mails method sends the actual mails.

Definition at line 45 of file mail_log.py.

Constructor & Destructor Documentation

◆ __init__()

def __init__ (   self,
  validation,
  include_expert_plots = False 
)

Initializes an instance of the Mail class from an instance of the Validation class.

Assumes that a comparison json file exists, reads it and parses it to extract information about failed plots. This information, together with information about failed scripts, gets stored in self.mail_data_new. If there is mail_data.json inside the log folder, its contents get stored in self.mail_data_old for later comparison.

Parameters
validationvalidation.Validation instance
include_expert_plotsShould expert plots be included?

Definition at line 54 of file mail_log.py.

54  def __init__(self, validation, include_expert_plots=False):
55  """!
56  Initializes an instance of the Mail class from an instance of the
57  Validation class. Assumes that a comparison json file exists,
58  reads it and parses it to extract information about failed plots.
59  This information, together with information about failed scripts,
60  gets stored in self.mail_data_new. If there is mail_data.json inside
61  the log folder, its contents get stored in self.mail_data_old for
62  later comparison.
63 
64  @param validation: validation.Validation instance
65  @param include_expert_plots: Should expert plots be included?
66  """
67 
68  # Cannot import Validation to type hint because this would give us a
69  # circular import.
70 
71  self._validator = validation
72 
73  # read contents from comparison.json
74  work_folder = self._validator.work_folder
75  revisions = ["reference"] + available_revisions(work_folder)
77  work_folder, revisions
78  )
79  with open(comparison_json_file) as f:
80  comparison_json = json.load(f)
81 
82  # yesterday's mail data
83  old_mail_data_path = os.path.join(
84  self._validator.get_log_folder(), "mail_data.json"
85  )
86 
88  self._mail_data_old: Optional[dict] = None
89  try:
90  with open(old_mail_data_path) as f:
91  self._mail_data_old = json.load(f)
92  except FileNotFoundError:
93  print(
94  f"Could not find old mail_data.json at {old_mail_data_path}.",
95  file=sys.stderr,
96  )
97 
98 
100  self._mail_data_new = self._create_mail_log(
101  comparison_json, include_expert_plots=include_expert_plots
102  )
103 
def get_html_plots_tag_comparison_json(output_base_dir, tags)

Member Function Documentation

◆ _check_if_same()

bool _check_if_same ( Dict[str, Dict[str, str]]  plot_errors)
staticprivate
@param plot_errors: ``_create_mail_log[contact]``.
@return True, if there is at least one new/changed plot status

Definition at line 283 of file mail_log.py.

◆ _compose_message()

def _compose_message (   plots,
  incremental = True 
)
staticprivate

Takes a dict (like in _create_mail_log) and composes a mail body.

Parameters
plots
incremental(bool): Is this an incremental report or a full ("Monday") report?

Definition at line 294 of file mail_log.py.

◆ _create_mail_log()

Dict[str, Dict[str, Dict[str, str]]] _create_mail_log (   self,
  comparison,
  include_expert_plots = False 
)
private

Takes the entire comparison json file, finds all the plots where comparison failed, finds info about failed scripts and saves them in the following format:

{ "email@address.test" : { "title1": { "package": str, "description": str, "rootfile": str, "comparison_text": str, "description": str, "comparison_result": str, "warnings": str, "file_url": str }, "title2": {...} }, "mail@...": {...} }

The top level ordering is the email address of the contact to make sure every user gets only one mail with everything in it.

Definition at line 161 of file mail_log.py.

◆ _create_mail_log_failed_scripts()

Dict[str, Dict[str, str]] _create_mail_log_failed_scripts (   self)
private

Looks up all scripts that failed and collects information about them.

See :meth:_create_mail_log for the structure of the resulting dictionary.

Definition at line 104 of file mail_log.py.

◆ _flag_new_failures()

Dict[str, Dict[str, Dict[str, str]]] _flag_new_failures ( Dict[str, Dict[str, Dict[str, str]]]  mail_log,
Optional[Dict[str, Dict[str, Dict[str, str]]]]  old_mail_log 
)
staticprivate
 Add a new field 'compared_to_yesterday' which takes one of the
values 'unchanged' (same revision comparison result as in yesterday's
mail log, 'new' (new warning/failure), 'changed' (comparison result
changed). 

Definition at line 244 of file mail_log.py.

◆ _force_full_report()

bool _force_full_report ( )
staticprivate
 Should a full (=non incremental) report be sent?
Use case e.g.: Send a full report every Monday.

Definition at line 394 of file mail_log.py.

◆ send_all_mails()

def send_all_mails (   self,
  incremental = None 
)
Send mails to all contacts in self.mail_data_new. If
self.mail_data_old is given, a mail is only sent if there are new
failed plots
@param incremental: True/False/None (=automatic). Whether to send a
    full or incremental report.

Definition at line 404 of file mail_log.py.

◆ write_log()

def write_log (   self)
Dump mail json.

Definition at line 469 of file mail_log.py.

Member Data Documentation

◆ _mail_data_new

_mail_data_new
private

Current mail data.

Will be filled on instantiation. Check docstring of _create_mail_log for exact format

Definition at line 100 of file mail_log.py.

◆ _mail_data_old

_mail_data_old
private

Yesterday's mail data (generated from comparison_json).

Check docstring of _create_mail_log for exact format

Definition at line 91 of file mail_log.py.


The documentation for this class was generated from the following file: