changeset 311:7f6fc38e14ff

More assertions in `Build` model methods.
author cmlenz
date Wed, 23 Nov 2005 11:19:24 +0000
parents 0ffdab3a7032
children 1016c3d12cbc
files bitten/model.py bitten/trac_ext/web_ui.py bitten/util/beep.py
diffstat 3 files changed, 65 insertions(+), 71 deletions(-) [+]
line wrap: on
line diff
--- a/bitten/model.py
+++ b/bitten/model.py
@@ -367,6 +367,7 @@
 
     def delete(self, db=None):
         """Remove the build from the database."""
+        assert self.exists, 'Cannot delete a non-existing build'
         if not db:
             db = self.env.get_db_cnx()
             handle_ta = True
@@ -385,6 +386,7 @@
 
     def insert(self, db=None):
         """Insert a new build into the database."""
+        assert not self.exists, 'Cannot insert an existing build'
         if not db:
             db = self.env.get_db_cnx()
             handle_ta = True
@@ -415,6 +417,7 @@
 
     def update(self, db=None):
         """Save changes to an existing build."""
+        assert self.exists, 'Cannot update a non-existing build'
         if not db:
             db = self.env.get_db_cnx()
             handle_ta = True
--- a/bitten/trac_ext/web_ui.py
+++ b/bitten/trac_ext/web_ui.py
@@ -598,67 +598,69 @@
             yield ('build', 'Builds')
 
     def get_timeline_events(self, req, start, stop, filters):
-        if 'build' in filters:
-            add_stylesheet(req, 'bitten/bitten.css')
-
-            db = self.env.get_db_cnx()
-            cursor = db.cursor()
-            cursor.execute("SELECT b.id,b.config,c.label,b.rev,p.name,"
-                           "b.stopped,b.status FROM bitten_build AS b"
-                           "  INNER JOIN bitten_config AS c ON (c.name=b.config) "
-                           "  INNER JOIN bitten_platform AS p ON (p.id=b.platform) "
-                           "WHERE b.stopped>=%s AND b.stopped<=%s "
-                           "AND b.status IN (%s, %s) ORDER BY b.stopped",
-                           (start, stop, Build.SUCCESS, Build.FAILURE))
-
-            event_kinds = {Build.SUCCESS: 'successbuild',
-                           Build.FAILURE: 'failedbuild'}
-            for id, config, label, rev, platform, stopped, status in cursor:
-
-                errors = []
-                if status == Build.FAILURE:
-                    for step in BuildStep.select(self.env, build=id,
-                                                 status=BuildStep.FAILURE,
-                                                 db=db):
-                        errors += [(escape(step.name), escape(error)) for error
-                                   in step.errors]
+        if 'build' not in filters:
+            return
 
-                title = 'Build of <em>%s [%s]</em> on %s %s' \
-                        % (escape(label), escape(rev), escape(platform),
-                           _status_label[status])
-                message = ''
-                if req.args.get('format') == 'rss':
-                    href = self.env.abs_href.build(config, id)
-                    if errors:
-                        buf = StringIO()
-                        prev_step = None
-                        for step, error in errors:
-                            if step != prev_step:
-                                if prev_step is not None:
-                                    buf.write('</ul>')
-                                buf.write('<p>Step %s failed:</p><ul>' % step)
-                                prev_step = step
-                            buf.write('<li>%s</li>' % escape(error))
-                        buf.write('</ul>')
-                        message = buf.getvalue()
-                else:
-                    href = self.env.href.build(config, id)
-                    if errors:
-                        steps = []
-                        for step, error in errors:
-                            if step not in steps:
-                                steps.append(step)
-                        steps = ['<em>%s</em>' % step for step in steps]
-                        if len(steps) < 2:
-                            message = steps[0]
-                        elif len(steps) == 2:
-                            message = ' and '.join(steps)
-                        elif len(steps) > 2:
-                            message = ', '.join(steps[:-1]) + ', and ' + \
-                                      steps[-1]
-                        message = 'Step%s ' % (len(steps) != 1 and 's' or '') \
-                                  + message + ' failed'
-                yield event_kinds[status], href, title, stopped, None, message
+        add_stylesheet(req, 'bitten/bitten.css')
+
+        db = self.env.get_db_cnx()
+        cursor = db.cursor()
+        cursor.execute("SELECT b.id,b.config,c.label,b.rev,p.name,"
+                       "b.stopped,b.status FROM bitten_build AS b"
+                       "  INNER JOIN bitten_config AS c ON (c.name=b.config) "
+                       "  INNER JOIN bitten_platform AS p ON (p.id=b.platform) "
+                       "WHERE b.stopped>=%s AND b.stopped<=%s "
+                       "AND b.status IN (%s, %s) ORDER BY b.stopped",
+                       (start, stop, Build.SUCCESS, Build.FAILURE))
+
+        event_kinds = {Build.SUCCESS: 'successbuild',
+                       Build.FAILURE: 'failedbuild'}
+        for id, config, label, rev, platform, stopped, status in cursor:
+
+            errors = []
+            if status == Build.FAILURE:
+                for step in BuildStep.select(self.env, build=id,
+                                             status=BuildStep.FAILURE,
+                                             db=db):
+                    errors += [(escape(step.name), escape(error)) for error
+                               in step.errors]
+
+            title = 'Build of <em>%s [%s]</em> on %s %s' \
+                    % (escape(label), escape(rev), escape(platform),
+                       _status_label[status])
+            message = ''
+            if req.args.get('format') == 'rss':
+                href = self.env.abs_href.build(config, id)
+                if errors:
+                    buf = StringIO()
+                    prev_step = None
+                    for step, error in errors:
+                        if step != prev_step:
+                            if prev_step is not None:
+                                buf.write('</ul>')
+                            buf.write('<p>Step %s failed:</p><ul>' % step)
+                            prev_step = step
+                        buf.write('<li>%s</li>' % escape(error))
+                    buf.write('</ul>')
+                    message = buf.getvalue()
+            else:
+                href = self.env.href.build(config, id)
+                if errors:
+                    steps = []
+                    for step, error in errors:
+                        if step not in steps:
+                            steps.append(step)
+                    steps = ['<em>%s</em>' % step for step in steps]
+                    if len(steps) < 2:
+                        message = steps[0]
+                    elif len(steps) == 2:
+                        message = ' and '.join(steps)
+                    elif len(steps) > 2:
+                        message = ', '.join(steps[:-1]) + ', and ' + \
+                                  steps[-1]
+                    message = 'Step%s ' % (len(steps) != 1 and 's' or '') \
+                              + message + ' failed'
+            yield event_kinds[status], href, title, stopped, None, message
 
     # Internal methods
 
--- a/bitten/util/beep.py
+++ b/bitten/util/beep.py
@@ -380,17 +380,6 @@
         @param profiles: A list of URIs of the profiles the peer claims to
                          support.
         """
-        pass
-
-    def run(self):
-        """Start this peer, which will try to connect to the server and send a
-        greeting.
-        """
-        try:
-            asyncore.loop()
-        except TerminateSession:
-            log.info('Terminating session')
-            self.terminate()
 
     def quit(self):
         self.terminate()
Copyright (C) 2012-2017 Edgewall Software