Coverage for pesummary/core/finish.py: 57.1%

28 statements  

« prev     ^ index     » next       coverage.py v7.4.4, created at 2024-05-02 08:42 +0000

1# Licensed under an MIT style license -- see LICENSE.md 

2 

3import subprocess 

4from pesummary.utils.utils import logger 

5 

6__author__ = ["Charlie Hoy <charlie.hoy@ligo.org>"] 

7 

8 

9class FinishingTouches(object): 

10 """Class to handle the finishing touches 

11 

12 Parameters 

13 ---------- 

14 parser: argparser 

15 The parser containing the command line arguments 

16 """ 

17 def __init__(self, inputs, **kwargs): 

18 self.inputs = inputs 

19 self.send_email() 

20 logger.info("Complete. Webpages can be viewed at the following url " 

21 "%s" % (self.inputs.baseurl + "/home.html")) 

22 

23 def send_email(self, message=None): 

24 """Send notification email. 

25 """ 

26 if self.inputs.email: 

27 logger.info("Sending email to %s" % (self.inputs.email)) 

28 try: 

29 self._email_notify(message) 

30 except Exception as e: 

31 logger.info("Unable to send notification email because %s" % ( 

32 e)) 

33 

34 def _email_message(self, message=None): 

35 """Message that will be send in the email. 

36 """ 

37 if not message: 

38 message = ("Hi %s,\n\nYour output page is ready on %s. You can " 

39 "view the result at %s \n" 

40 % (self.inputs.user, self.inputs.host, self.inputs.baseurl + "/home.html")) 

41 return message 

42 

43 def _email_notify(self, message): 

44 """Subprocess to send the notification email. 

45 """ 

46 subject = "Output page available at %s" % (self.host) 

47 message = self._email_message(message) 

48 cmd = 'echo -e "%s" | mail -s "%s" "%s"' % ( 

49 message, subject, self.email) 

50 ess = subprocess.Popen(cmd, shell=True) 

51 ess.wait() 

52 

53 def remove_tmp_directories(self): 

54 """Remove the temp directories created by PESummary 

55 """ 

56 from pesummary.utils import utils 

57 

58 utils.remove_tmp_directories()