[rtems-tools commit] rtemstoolkit: Update the mailer module to the option interface.
Chris Johns
chrisj at rtems.org
Wed Oct 11 19:14:20 UTC 2017
Module: rtems-tools
Branch: master
Commit: dc5de5f299a5b8984bd1a328c6fe3a616a5c34df
Changeset: http://git.rtems.org/rtems-tools/commit/?id=dc5de5f299a5b8984bd1a328c6fe3a616a5c34df
Author: Chris Johns <chrisj at rtems.org>
Date: Thu Oct 12 06:11:16 2017 +1100
rtemstoolkit: Update the mailer module to the option interface.
---
rtemstoolkit/mailer.py | 19 ++++++++++++++-----
1 file changed, 14 insertions(+), 5 deletions(-)
diff --git a/rtemstoolkit/mailer.py b/rtemstoolkit/mailer.py
index 7f71d10..81a5c70 100644
--- a/rtemstoolkit/mailer.py
+++ b/rtemstoolkit/mailer.py
@@ -72,7 +72,7 @@ class mail:
l = l[:l.index('\n')]
return l.strip()
- addr = self.opts.get_arg('--mail-from')
+ addr = self.opts.find_arg('--mail-from')
if addr is not None:
return addr[1]
mailrc = None
@@ -83,9 +83,8 @@ class mail:
if mailrc is not None and path.exists(mailrc):
# set from="Joe Blow <joe at blow.org>"
try:
- mrc = open(mailrc, 'r')
- lines = mrc.readlines()
- mrc.close()
+ with open(mailrc, 'r') as mrc:
+ lines = mrc.readlines()
except IOError as err:
raise error.general('error reading: %s' % (mailrc))
for l in lines:
@@ -100,7 +99,7 @@ class mail:
return addr
def smtp_host(self):
- host = self.opts.get_arg('--smtp-host')
+ host = self.opts.find_arg('--smtp-host')
if host is not None:
return host[1]
host = self.opts.defaults.get_value('%{_mail_smtp_host}')
@@ -120,6 +119,16 @@ class mail:
except socket.error as se:
raise error.general('sending mail: %s' % (str(se)))
+ def send_file_as_body(self, to_addr, subject, name, intro = None):
+ try:
+ with open(name, 'r') as f:
+ body = f.readlines()
+ except IOError as err:
+ raise error.general('error reading mail body: %s' % (name))
+ if intro is not None:
+ body = intro + body
+ self.send(to_addr, from_addr, body)
+
if __name__ == '__main__':
import sys
optargs = {}
More information about the vc
mailing list