[154419] contrib/buildbot-test/master.cfg

larryv at macports.org larryv at macports.org
Sat Oct 29 03:10:04 CEST 2016


Revision: 154419
          https://trac.macports.org/changeset/154419
Author:   larryv at macports.org
Date:     2016-10-29 03:10:04 +0200 (Sat, 29 Oct 2016)
Log Message:
-----------
buildbot: Improve portWatcherMessageFormatter

- Try not to repeat ourselves.

- Omit the default "s" string format specification.

- Prefer `update()` over repeated `add()`s.

- Use tuple unpacking.

- Test nonempty sequences implicitly instead of using `len()`.

- Continue or exit early from loops to reduce indentation.

- Modifying function arguments is a C-inspired antipattern. Return
  a tuple instead.

Modified Paths:
--------------
    contrib/buildbot-test/master.cfg

Modified: contrib/buildbot-test/master.cfg
===================================================================
--- contrib/buildbot-test/master.cfg	2016-10-29 01:05:45 UTC (rev 154418)
+++ contrib/buildbot-test/master.cfg	2016-10-29 01:10:04 UTC (rev 154419)
@@ -654,9 +654,8 @@
 
     # same as original, but calls portMessageFormatter with access to interested_users
     def buildMessageDict(self, name, build, results):
-        self.interested_users.clear()
-        msgdict = self.portMessageFormatter(
-            self.mode, name, build, results, self.master_status, self.interested_users)
+        msgdict, self.interested_users = self.portMessageFormatter(
+            self.mode, name, build, results, self.master_status)
         return msgdict
 
     def useLookup(self, build):
@@ -670,21 +669,23 @@
 #            dl.append(d)
         return defer.gatherResults(dl)
 
-def portWatcherMessageFormatter(mode, name, build, results, master_status, interested_users):
+def portWatcherMessageFormatter(mode, name, build, results, master_status):
+    interested_users = set()
     result = util.Results[results]
-    subject = 'Build {:s}'.format(result.title())
+    subject = 'Build {}'.format(result.title())
     text = list()
-    text.append('Status:       {:s}'.format(result.title()))
-    text.append('Build slave:  {:s}'.format(build.getSlavename()))
-    if master_status.getURLForThing(build):
-        text.append('Full logs:    {:s}'.format(master_status.getURLForThing(build)))
-        text.append('Build reason: {:s}'.format(build.getReason()))
-        text.append('Port list:    {:s}'.format(build.getProperty('fullportlist')))
-        text.append('Subport list:\n\t- {:s}'.format(build.getProperty('subportlist').replace(' ', '\n\t- ')))
-        text.append('Variants:     {:s}'.format(build.getProperty('variants')))
-        text.append('Revision:     {:s}'.format(build.getProperty('revision')))
-        text.append('Build time:   {:s}'.format(datetime.timedelta(seconds=int(round(build.getTimes()[1] - build.getTimes()[0])))))
-        text.append(u'Committer:    {:s}'.format(','.join(build.getResponsibleUsers())))
+    text.append('Status:       {}'.format(result.title()))
+    text.append('Build slave:  {}'.format(build.getSlavename()))
+    build_url = master_status.getURLForThing(build)
+    if build_url:
+        text.append('Full logs:    {}'.format(build_url))
+        text.append('Build reason: {}'.format(build.getReason()))
+        text.append('Port list:    {}'.format(build.getProperty('fullportlist')))
+        text.append('Subport list:\n\t- {}'.format(build.getProperty('subportlist').replace(' ', '\n\t- ')))
+        text.append('Variants:     {}'.format(build.getProperty('variants')))
+        text.append('Revision:     {}'.format(build.getProperty('revision')))
+        text.append('Build time:   {}'.format(datetime.timedelta(seconds=int(round(build.getTimes()[1] - build.getTimes()[0])))))
+        text.append(u'Committer:    {}'.format(','.join(build.getResponsibleUsers())))
 
         text.append('\nLog from failed builds:')
         summary_step = [x for x in build.getSteps() if x.getName() == 'summary'][0]
@@ -694,47 +695,44 @@
         pattern = re.compile(r"^Building '(?P<port>.*?)'.*?(\(failed to install dependency '(?P<dependency>.*?)'\))?( maintainers: (?P<maintainers>.*?)[.])?$")
         # iterate through all the ports being built
         for line in summary_log.getText().splitlines():
+            if 'ERROR' not in line:
+                continue
             # in case of a build error, print the error and add the broken port(s) to the list
-            if 'ERROR' in line:
-                line = line.replace(';', '@')
-                text.append('\t' + line.replace(' maintainers:', '\n\t> maintainers:'))
-                match = pattern.match(line)
-                if match:
-                    for key in ['port', 'dependency']:
-                        port = match.groupdict().get(key)
-                        if port:
-                            failed_ports.add(port)
-                    maintainers = match.groupdict().get('maintainers')
-                    if maintainers:
-                        for maintainer in maintainers.split(','):
-                            maintainers_to_notify.add(maintainer)
-        if len(failed_ports) > 0:
-            text.append('\nBroken ports:\n\t- {:s}'.format('\n\t- '.join(sorted(failed_ports))))
+            line = line.replace(';', '@')
+            text.append('\t' + line.replace(' maintainers:', '\n\t> maintainers:'))
+            match = pattern.match(line)
+            if match:
+                port, dependency, maintainers = match.group('port', 'dependency', 'maintainers')
+                failed_ports.add(port)
+                if dependency:
+                    failed_ports.add(dependency)
+                if maintainers:
+                    maintainers_to_notify.update(maintainers.split(','))
 
-        if len(maintainers_to_notify) > 0:
+        if failed_ports:
+            text.append('\nBroken ports:\n\t- {}'.format('\n\t- '.join(sorted(failed_ports))))
+        if maintainers_to_notify:
             text.append('\nResponsible maintainers:\n\t- {}'.format('\n\t- '.join(sorted(maintainers_to_notify))))
-            for user in maintainers_to_notify:
-                interested_users.add(user)
+            interested_users.update(maintainers_to_notify)
 
         # links to individual builds
         text.append('\nLinks to individual build jobs:')
         trigger_step = [x for x in build.getSteps() if x.getName() == 'trigger'][0]
-        build_urls_dict = trigger_step.getURLs()
-        # TODO; sorting won't work properly for
+        # FIXME Sorting is lexicographic and won't work properly for
         # - ports-10.11-x86_64-builder #99
         # - ports-10.11-x86_64-builder #100
-        build_urls_keys = sorted(build_urls_dict.keys())
-        for k in build_urls_keys:
-            text.append('- {:s}\n  {:s}'.format(k, build_urls_dict[k]))
-        text.append('\n-- \nBest regards,\nMacPorts Buildbot\n{:s}'.format(c['buildbotURL']))
+        for label, url in sorted(trigger_step.getURLs().iteritems()):
+            text.append('- {}\n  {}'.format(label, url))
+        text.append('\n-- \nBest regards,\nMacPorts Buildbot\n{}'.format(c['buildbotURL']))
 
         if failed_ports:
-            subject += ': '
-            subject += ', '.join(sorted(failed_ports)[:10])
+            subject += ': ' + ', '.join(sorted(failed_ports)[:10])
             if len(failed_ports) > 10:
                 subject +=  ', and {} more'.format(len(failed_ports) - 10)
-    return {'body': '\n'.join(text), 'type': 'plain', 'subject': subject}
 
+    return ({'body': '\n'.join(text), 'type': 'plain', 'subject': subject},
+            interested_users)
+
 if config['production']:
     # send mail about base failures to users on the blamelist
     mn = status.MailNotifier(
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.macports.org/pipermail/macports-changes/attachments/20161029/8c22cdd1/attachment-0002.html>


More information about the macports-changes mailing list