def __init__(self, fab_env, to_addrs, smtp_host, smtp_creds): self.std_hook = StdHook() self.std_hook.attach() self.fab_env = fab_env self.to_addrs = to_addrs self.smtp_host = smtp_host self.smtp_creds = smtp_creds
class Report(object): def __init__(self, fab_env, to_addrs, smtp_host, smtp_creds): self.std_hook = StdHook() self.std_hook.attach() self.fab_env = fab_env self.to_addrs = to_addrs self.smtp_host = smtp_host self.smtp_creds = smtp_creds def __call__(self): self.std_hook.detach() if not self.fab_env.report: return from_id = os.getenv('LOGNAME') or os.getlogin() from_addr = '%s@%s' % (from_id, socket.gethostname()) # FIXME: this is probably wrong log = self.std_hook.log.getvalue() log = re.sub('\r.+?\n', '\n', log) # TODO: make it pretty? msg = MIMEText(log) msg['Subject'] = '%s@%s' % ( self.fab_env.command, ','.join(self.fab_env.roles)) msg['From'] = from_addr msg['To'] = ', '.join(self.to_addrs) server = smtplib.SMTP(*self.smtp_host) try: server.login(*self.smtp_creds) server.sendmail(from_addr, self.to_addrs, msg.as_string()) finally: server.quit()
class Report(object): def __init__(self, fab_env, to_addrs, smtp_host, smtp_creds): self.std_hook = StdHook() self.std_hook.attach() self.fab_env = fab_env self.to_addrs = to_addrs self.smtp_host = smtp_host self.smtp_creds = smtp_creds def __call__(self): self.std_hook.detach() if not self.fab_env.report: return from_id = os.getenv('LOGNAME') or os.getlogin() from_addr = '%s@%s' % (from_id, socket.gethostname()) # FIXME: this is probably wrong log = self.std_hook.log.getvalue() log = re.sub('\r.+?\n', '\n', log) # TODO: make it pretty? msg = MIMEText(log) msg['Subject'] = '%s@%s' % (self.fab_env.command, ','.join( self.fab_env.roles)) msg['From'] = from_addr msg['To'] = ', '.join(self.to_addrs) server = smtplib.SMTP(*self.smtp_host) try: server.login(*self.smtp_creds) server.sendmail(from_addr, self.to_addrs, msg.as_string()) finally: server.quit()