# HG changeset patch
# User cmlenz
# Date 1132744764 0
# Node ID 7f6fc38e14ff9b09faae9836495fd4b817a3b0c7
# Parent 0ffdab3a70324f5c0920d548f042e51e6420f735
More assertions in `Build` model methods.
diff --git a/bitten/model.py b/bitten/model.py
--- 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
diff --git a/bitten/trac_ext/web_ui.py b/bitten/trac_ext/web_ui.py
--- 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 %s [%s] 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('')
- buf.write('
Step %s failed:
' % step)
- prev_step = step
- buf.write('- %s
' % escape(error))
- buf.write('
')
- 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 = ['%s' % 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 %s [%s] 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('')
+ buf.write('Step %s failed:
' % step)
+ prev_step = step
+ buf.write('- %s
' % escape(error))
+ buf.write('
')
+ 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 = ['%s' % 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
diff --git a/bitten/util/beep.py b/bitten/util/beep.py
--- 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()