Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1# (c) Stefan Countryman 2017-2018 

2 

3""" 

4FileHandlers that send out information to the LLAMA team via email and which 

5create log files to record the successful sending of those warning emails. 

6""" 

7 

8from llama.com.email import EmailReceipt 

9 

10 

11# The following class is abstract, so we shouldn't need to define abstract 

12# methods. 

13# pylint: disable=abstract-method, duplicate-bases 

14class TeamEmailReceipt(EmailReceipt): 

15 """ 

16 Emails with important files should be sent to LLAMA team members for 

17 review. These receipts record successful sending of those emails. 

18 """ 

19 

20 FILENAME_FMT = "rct_team_{}.log" 

21 CLASSNAME_FMT = "RctTeam{}" 

22 

23 @property 

24 def subject(self): 

25 """By default, just alert the team with an email saying which file is 

26 ready (defined as ``self.UPLOAD``) and the ``eventid``.""" 

27 return f"{self.eventid}: {self.UPLOAD.FILENAME} Ready" 

28 

29 @property 

30 def recipients(self): 

31 """The quick response team will be the same for most alert emails.""" 

32 # only email everybody if this is not a test and if this has been 

33 # labeled em ready (as checked by the ``Advok`` dependency). 

34 if 'test' in self.eventid: 

35 return ['gw.hen.analysis@gmail.com'] 

36 return ['imrebartos@gmail.com', 

37 'stefan.countryman@gmail.com', 

38 'stc2117@columbia.edu', 

39 'gw.hen.analysis@gmail.com'] 

40 

41 @classmethod 

42 def decorator_dict(cls, upload, subject=None): 

43 """See ``UploadReceipt.upload_this`` and 

44 ``UploadReceipt.decorator_dict``. 

45 

46 Parameters 

47 ---------- 

48 upload 

49 The decorated ``FileHandler`` class that is being registered for 

50 upload. 

51 subject : function or str, optional 

52 Either a string whose ``format`` function will be called with the 

53 new ``TeamEmailReceipt`` as its ``self`` keyword argument or a 

54 function taking the new ``TeamEmailReceipt`` as its only argument 

55 (will become the ``subject`` property for the new 

56 ``TeamEmailReceipt``). Uses the default 

57 ``TeamEmailReceipt.subject`` by default. 

58 

59 Returns 

60 ------- 

61 newclassdict : dict 

62 A dictionary that can be passed to ``type`` to specify the 

63 attributes of a new class. 

64 

65 Raises 

66 ------ 

67 TypeError 

68 If ``subject`` is not a formattable string or callable object. 

69 """ 

70 if subject is None: 

71 subject = cls.subject.fget # pylint: disable=no-member 

72 if hasattr(subject, 'format'): 

73 

74 def subj(self): 

75 return subject.format(self) 

76 

77 elif callable(subject): 

78 subj = subject 

79 else: 

80 raise TypeError(f"Can't understand this subject: {subject}") 

81 

82 @property 

83 def subject(self): # pylint: disable=function-redefined 

84 return subj(self) 

85 

86 subject.__doc__ = f"Email subject for {upload} email upload." 

87 return {"subject": subject}