[rtems-release commit] Add cron support.

Chris Johns chrisj at rtems.org
Wed Oct 30 05:09:31 UTC 2019


Module:    rtems-release
Branch:    master
Commit:    7eb84b1a873fe75ff5d5ee4b64d9b5524a9e39cb
Changeset: http://git.rtems.org/rtems-release/commit/?id=7eb84b1a873fe75ff5d5ee4b64d9b5524a9e39cb

Author:    Chris Johns <chrisj at rtems.org>
Date:      Wed Oct 30 16:09:21 2019 +1100

Add cron support.

---

 rtems-mailer             | 167 +++++++++++++++++++++++++++++++++++++++++++++++
 rtems-release-cron       | 153 +++++++++++++++++++++++++++++++++++++++++++
 snapshot-announce.txt.in |  17 +++++
 3 files changed, 337 insertions(+)

diff --git a/rtems-mailer b/rtems-mailer
new file mode 100755
index 0000000..1532a0f
--- /dev/null
+++ b/rtems-mailer
@@ -0,0 +1,167 @@
+#! /usr/bin/env python
+#
+# RTEMS Tools Project (http://www.rtems.org/)
+# Copyright 2019 Chris Johns (chrisj at rtems.org)
+# All rights reserved.
+#
+# This file is part of the RTEMS Tools package in 'rtems-tools'.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+#
+# A tool to email a file. Taken from the mailer.py module in
+# rtems-tools's toolkit.
+#
+
+from __future__ import print_function
+
+import argparse
+import smtplib
+import sys
+
+class error(Exception):
+    def __init__(self, what):
+        self.set_output('error: ' + what)
+    def set_output(self, msg):
+        self.msg = msg
+    def __str__(self):
+        return self.msg
+
+class mail:
+    def __init__(self, opts):
+        self.opts = opts
+
+    def from_address(self):
+
+        def _clean(l):
+            if '#' in l:
+                l = l[:l.index('#')]
+            if '\r' in l:
+                l = l[:l.index('r')]
+            if '\n' in l:
+                l = l[:l.index('\n')]
+            return l.strip()
+
+        addr = self.opts.mail_from
+        if addr is not None:
+            return addr
+        mailrc = None
+        if 'MAILRC' in os.environ:
+            mailrc = os.environ['MAILRC']
+        if mailrc is None and 'HOME' in os.environ:
+            mailrc = path.join(os.environ['HOME'], '.mailrc')
+        if mailrc is not None and path.exists(mailrc):
+            # set from="Joe Blow <joe at blow.org>"
+            try:
+                with open(mailrc, 'r') as mrc:
+                    lines = mrc.readlines()
+            except IOError as err:
+                raise error('error reading: %s' % (mailrc))
+            for l in lines:
+                l = _clean(l)
+                if 'from' in l:
+                    fa = l[l.index('from') + len('from'):]
+                    if '=' in fa:
+                        addr = fa[fa.index('=') + 1:].replace('"', ' ').strip()
+            if addr is not None:
+                return addr
+        if self._args_are_macros():
+            addr = self.opts.defaults.get_value('%{_sbgit_mail}')
+        else:
+            raise error('no valid from address for mail')
+        return addr
+
+    def smtp_host(self):
+        host = self.opts.smtp_host
+        if host is not None:
+            return host
+        return 'localhost'
+
+    def send(self, to_addr, subject, body):
+        from_addr = self.from_address()
+        msg = "From: %s\r\nTo: %s\r\nSubject: %s\r\n\r\n" % \
+            (from_addr, to_addr, subject) + body
+        try:
+            s = smtplib.SMTP(self.smtp_host())
+            s.sendmail(from_addr, [to_addr], msg)
+        except smtplib.SMTPException as se:
+            raise error('sending mail: %s' % (str(se)))
+        except socket.error as se:
+            raise error('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('error reading mail body: %s' % (name))
+        if intro is not None:
+            body = intro + body
+        self.send(to_addr, subject, ''.join(body))
+
+try:
+    ec = 0
+    notice = None
+
+    args = argparse.ArgumentParser(prog = 'rtems-mailer',
+                                   description = 'Tool to email a file to an specified SMTP host')
+    args.add_argument('-s', '--subject',
+                      help = 'Mail subject.',
+                      type = str, required = True, default = None)
+    args.add_argument('-t', '--to',
+                      help = 'Mail to, comma separated list.',
+                      type = str, required = True, default = None)
+    args.add_argument('-f', '--from',
+                      dest = 'mail_from',
+                      help = 'Mail from.',
+                      type = str, required = True, default = None)
+    args.add_argument('-S', '--smtp-host',
+                      help = 'SMTP host.',
+                      type = str, default = None)
+    args.add_argument('body',
+                      help = 'Email body.',
+                      type = str)
+
+    opts = args.parse_args()
+
+    m = mail(opts)
+    for to in opts.to.split(','):
+        m.send_file_as_body(to, opts.subject, opts.body)
+
+except error as err:
+    notice = str(err)
+    ec = 1
+except argparse.ArgumentError as ae:
+    notice = str(ae)
+    ec = 2
+except KeyboardInterrupt:
+    notice = 'abort: user terminated'
+    ec = 3
+except:
+    raise
+    notice = 'abort: unknown error'
+    ec = 1
+if notice is not None:
+    print(notice, file = sys.stderr)
+sys.exit(ec)
diff --git a/rtems-release-cron b/rtems-release-cron
new file mode 100755
index 0000000..8ab2594
--- /dev/null
+++ b/rtems-release-cron
@@ -0,0 +1,153 @@
+# RTEMS Tools Project (http://www.rtems.org/)
+# Copyright 2019 Chris Johns (chrisj at rtems.org)
+# All rights reserved.
+#
+# This file is part of the RTEMS Tools package in 'rtems-tools'.
+#
+# Redistribution and use in source and binary forms, with or without
+# modification, are permitted provided that the following conditions are met:
+#
+# 1. Redistributions of source code must retain the above copyright notice,
+# this list of conditions and the following disclaimer.
+#
+# 2. Redistributions in binary form must reproduce the above copyright notice,
+# this list of conditions and the following disclaimer in the documentation
+# and/or other materials provided with the distribution.
+#
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+# AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+# ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
+# LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+# CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+# SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+# INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+# CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+# ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+# POSSIBILITY OF SUCH DAMAGE.
+#
+
+set -e
+
+#
+# Cron wrapper for releasing each month.
+#
+
+live=yes
+
+#
+# RTEMS release
+#
+rtems_major=5
+rtems_minor=0
+rtems_dot=0
+rtems_snapshot=$(date +"m%y%m")
+
+#
+# Email addresses
+#
+from="chrisj at rtems.org"
+if [ ${live} = yes ]; then
+ build_to="build at rtems.org"
+ announce_to="users at rtems.org,devel at rtems.org"
+ smtphost="--smtp-host=192.168.80.141"
+else
+ build_to="chrisj at rtems.org"
+ announce_to="chrisj at rtems.org"
+fi
+#
+# Announce template
+#
+announce="snapshot-announce.txt"
+
+#
+# Upload path
+#
+if [ ${live} = yes ]; then
+ upload_path="/data/ftp/pub/rtems/releases"
+else
+ upload_path="/xdata/ftp/pub/rtems/releases"
+fi
+
+#
+# The version and the revision
+#
+version=${rtems_major}
+revision=${rtems_minor}.${rtems_dot}
+snapshot=${rtems_minor}.${rtems_dot}-${rtems_snapshot}
+release="${version}.${snapshot}"
+
+#
+# Work in the release sandbox
+#
+release_top=$(dirname $0)
+cd ${release_top}
+
+#
+# Activate the virtualenv for building the documentation.
+#
+. ../release/bin/activate
+
+#
+# Clean the work
+#
+rm -rf ${release}
+
+. ${release_top}/rtems-release-version
+
+git_hash=$(git log --pretty=format:'%h' -n 1)
+
+#
+# Build log
+#
+BUILD_LOG=rtems-release-build-log-${rtems_snapshot}.txt
+
+#
+# The lock file, used to stop cron running this script on top of itself.
+#
+LOCK=.cron-lock-rtems-release
+
+if [ ! -f ${LOCK} ]; then
+ trap "rm -f ${LOCK} ${BUILD_LOG} ${announce}" EXIT
+ trap "rm -f ${LOCK} ${BUILD_LOG} ${announce}; exit 1" INT TERM STOP INFO USR1 USR2
+ touch ${LOCK}
+ echo "RTEMS Release Cron builder, v${rtems_release_version} (${git_hash})" > ${BUILD_LOG}
+ echo "" >> ${BUILD_LOG}
+ set +e
+ ./rtems-release ${version} ${snapshot} >> ${BUILD_LOG} 2>&1
+ ec=$?
+ ec=0
+ set -e
+ if [ $ec -eq 0 ]; then
+  result="PASS"
+ else
+  result="FAIL"
+ fi
+ subject="RTEMS Release Snapshot Build: ${release} - ${result}"
+ ${release_top}/rtems-mailer --to=${build_to} \
+                             --from=${from} \
+                             --subject="${subject}" \
+                             ${smtphost} \
+                             ${BUILD_LOG}
+ if [ $ec -eq 0 ]; then
+  if [ -d ${upload_path} ]; then
+   dstdir=${upload_path}/${rtems_major}/${rtems_major}.${revision}
+   mkdir -p ${destdir}
+   cp -r ${release} ${destdir}/
+   cat ${announce}.in | \
+       sed -e "s/@VERSION@/${version}/g" \
+	   -e "s/@SNAPSHOT@/${snapshot}/g" \
+	   -e "s/@RTEMS_SNAPSHOT@/${rtems_snapshot}/g" \
+	   -e "s/@RELEASE@/${release}/g" > ${announce}
+   now=$(date +"%d %b %Y")
+   subject="RTEMS Release Snapshot: ${release} (${now})"
+   ${release_top}/rtems-mailer --to=${announce_to} \
+                               --from=${from} \
+                               --subject="${subject}" \
+                               ${smtphost} \
+                               ${announce}
+  fi
+ fi
+fi
+
+exit 0
diff --git a/snapshot-announce.txt.in b/snapshot-announce.txt.in
new file mode 100644
index 0000000..14f3fd2
--- /dev/null
+++ b/snapshot-announce.txt.in
@@ -0,0 +1,17 @@
+RTEMS Release Build - @RELEASE@
+
+RTEMS @VERSION@ Release snapshot @RTEMS_SNAPSHOT@ is avaliable for testing.
+It can be found at:
+
+ https://ftp.rtems.org/pub/rtems/releases/@VERSION@/@VERSION@.@REVISION@/@RELEASE@
+
+Please test and report any issues to the user at rtems.org or devel at rtems.org
+mailing lists or please raise a ticket.
+
+If you are part of the RTEMS testing program please build on your preferred
+host posting build and BSP test results to build at rtems.org.
+
+This is a development release and may have errors and be unstable.
+
+Thanks
+Chris



More information about the vc mailing list