Changeset dc5de5f in rtems-tools for rtemstoolkit


Ignore:
Timestamp:
Oct 11, 2017, 7:11:16 PM (2 years ago)
Author:
Chris Johns <chrisj@…>
Branches:
master
Children:
fce29b0
Parents:
7c032b0
Message:

rtemstoolkit: Update the mailer module to the option interface.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • rtemstoolkit/mailer.py

    r7c032b0 rdc5de5f  
    7373            return l.strip()
    7474
    75         addr = self.opts.get_arg('--mail-from')
     75        addr = self.opts.find_arg('--mail-from')
    7676        if addr is not None:
    7777            return addr[1]
     
    8484            # set from="Joe Blow <joe@blow.org>"
    8585            try:
    86                 mrc = open(mailrc, 'r')
    87                 lines = mrc.readlines()
    88                 mrc.close()
     86                with open(mailrc, 'r') as mrc:
     87                    lines = mrc.readlines()
    8988            except IOError as err:
    9089                raise error.general('error reading: %s' % (mailrc))
     
    101100
    102101    def smtp_host(self):
    103         host = self.opts.get_arg('--smtp-host')
     102        host = self.opts.find_arg('--smtp-host')
    104103        if host is not None:
    105104            return host[1]
     
    121120            raise error.general('sending mail: %s' % (str(se)))
    122121
     122    def send_file_as_body(self, to_addr, subject, name, intro = None):
     123        try:
     124            with open(name, 'r') as f:
     125                body = f.readlines()
     126        except IOError as err:
     127            raise error.general('error reading mail body: %s' % (name))
     128        if intro is not None:
     129            body = intro + body
     130        self.send(to_addr, from_addr, body)
     131
    123132if __name__ == '__main__':
    124133    import sys
Note: See TracChangeset for help on using the changeset viewer.