annotate bitten/model.py @ 904:288791ac7f02 0.6.x

0.6dev: Merge r984 from trunk.
author hodgestar
date Fri, 11 Mar 2011 13:24:35 +0000
parents f4d07544722b
children
rev   line source
379
0df178e07fdb Use UTF-8 as encoding of source files.
cmlenz
parents: 377
diff changeset
1 # -*- coding: utf-8 -*-
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
2 #
408
933105ab516b Update file headers and other stuff pointing to the old home.
cmlenz
parents: 379
diff changeset
3 # Copyright (C) 2005-2007 Christopher Lenz <cmlenz@gmx.de>
833
f4d07544722b 0.6dev: Merged [910] from trunk.
osimons
parents: 809
diff changeset
4 # Copyright (C) 2007-2010 Edgewall Software
163
634be6cbb808 Flip the switch: Bitten is now BSD-licensed.
cmlenz
parents: 157
diff changeset
5 # All rights reserved.
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
6 #
163
634be6cbb808 Flip the switch: Bitten is now BSD-licensed.
cmlenz
parents: 157
diff changeset
7 # This software is licensed as described in the file COPYING, which
634be6cbb808 Flip the switch: Bitten is now BSD-licensed.
cmlenz
parents: 157
diff changeset
8 # you should have received as part of this distribution. The terms
408
933105ab516b Update file headers and other stuff pointing to the old home.
cmlenz
parents: 379
diff changeset
9 # are also available at http://bitten.edgewall.org/wiki/License.
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
10
316
87c9b1e8f086 More docstring improvements.
cmlenz
parents: 311
diff changeset
11 """Model classes for objects persisted in the database."""
87c9b1e8f086 More docstring improvements.
cmlenz
parents: 311
diff changeset
12
629
f3bb52da9e3c 0.6dev: Adding support for attachments to configurations and build - full web implementation that mirrors what is available in Ticket and Wiki. Also added a new generic `<attach/>` command that enables attaching files to be part of a recipe and uploaded by slaves as part of build.
osimons
parents: 606
diff changeset
13 from trac.attachment import Attachment
236
34202d89f57d For some very weird reason, this import confused the code coverage collection via `trace.py`.
cmlenz
parents: 227
diff changeset
14 from trac.db import Table, Column, Index
629
f3bb52da9e3c 0.6dev: Adding support for attachments to configurations and build - full web implementation that mirrors what is available in Ticket and Wiki. Also added a new generic `<attach/>` command that enables attaching files to be part of a recipe and uploaded by slaves as part of build.
osimons
parents: 606
diff changeset
15 from trac.resource import Resource
519
384e59137bf8 Support unicode by converting everything to UTF-8 on write and back to unicode on read - should fix #369
dfraser
parents: 516
diff changeset
16 from trac.util.text import to_unicode
757
ab1f18d0e98c Merge of [834] to 0.6
wbell
parents: 736
diff changeset
17 from trac.util.datefmt import to_timestamp, utcmin, utcmax
ab1f18d0e98c Merge of [834] to 0.6
wbell
parents: 736
diff changeset
18 from datetime import datetime
519
384e59137bf8 Support unicode by converting everything to UTF-8 on write and back to unicode on read - should fix #369
dfraser
parents: 516
diff changeset
19 import codecs
516
2f3b7c17d3c3 Switch to storing log messages in files rather than in database rows:
dfraser
parents: 450
diff changeset
20 import os
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
21
411
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
22 __docformat__ = 'restructuredtext en'
a169d2e96463 Use reStructuredText as the API documentation syntax.
cmlenz
parents: 408
diff changeset
23
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
24
45
80bc0fae3ed1 Renamed {{{Configuration}}} to {{{BuildConfig}}}.
cmlenz
parents: 41
diff changeset
25 class BuildConfig(object):
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
26 """Representation of a build configuration."""
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
27
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
28 _schema = [
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
29 Table('bitten_config', key='name')[
147
395b67aa072e Build recipes are now stored in the database with the build configuration. This means that it is no longer necessary to store the recipe in the repository. Closes #41.
cmlenz
parents: 119
diff changeset
30 Column('name'), Column('path'), Column('active', type='int'),
395b67aa072e Build recipes are now stored in the database with the build configuration. This means that it is no longer necessary to store the recipe in the repository. Closes #41.
cmlenz
parents: 119
diff changeset
31 Column('recipe'), Column('min_rev'), Column('max_rev'),
395b67aa072e Build recipes are now stored in the database with the build configuration. This means that it is no longer necessary to store the recipe in the repository. Closes #41.
cmlenz
parents: 119
diff changeset
32 Column('label'), Column('description')
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
33 ]
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
34 ]
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
35
147
395b67aa072e Build recipes are now stored in the database with the build configuration. This means that it is no longer necessary to store the recipe in the repository. Closes #41.
cmlenz
parents: 119
diff changeset
36 def __init__(self, env, name=None, path=None, active=False, recipe=None,
395b67aa072e Build recipes are now stored in the database with the build configuration. This means that it is no longer necessary to store the recipe in the repository. Closes #41.
cmlenz
parents: 119
diff changeset
37 min_rev=None, max_rev=None, label=None, description=None):
157
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
38 """Initialize a new build configuration with the specified attributes.
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
39
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
40 To actually create this configuration in the database, the `insert`
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
41 method needs to be called.
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
42 """
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
43 self.env = env
96
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
44 self._old_name = None
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
45 self.name = name
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
46 self.path = path or ''
147
395b67aa072e Build recipes are now stored in the database with the build configuration. This means that it is no longer necessary to store the recipe in the repository. Closes #41.
cmlenz
parents: 119
diff changeset
47 self.active = bool(active)
395b67aa072e Build recipes are now stored in the database with the build configuration. This means that it is no longer necessary to store the recipe in the repository. Closes #41.
cmlenz
parents: 119
diff changeset
48 self.recipe = recipe or ''
395b67aa072e Build recipes are now stored in the database with the build configuration. This means that it is no longer necessary to store the recipe in the repository. Closes #41.
cmlenz
parents: 119
diff changeset
49 self.min_rev = min_rev or None
395b67aa072e Build recipes are now stored in the database with the build configuration. This means that it is no longer necessary to store the recipe in the repository. Closes #41.
cmlenz
parents: 119
diff changeset
50 self.max_rev = max_rev or None
96
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
51 self.label = label or ''
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
52 self.description = description or ''
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
53
450
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 437
diff changeset
54 def __repr__(self):
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 437
diff changeset
55 return '<%s %r>' % (type(self).__name__, self.name)
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 437
diff changeset
56
316
87c9b1e8f086 More docstring improvements.
cmlenz
parents: 311
diff changeset
57 exists = property(fget=lambda self: self._old_name is not None,
87c9b1e8f086 More docstring improvements.
cmlenz
parents: 311
diff changeset
58 doc='Whether this configuration exists in the database')
629
f3bb52da9e3c 0.6dev: Adding support for attachments to configurations and build - full web implementation that mirrors what is available in Ticket and Wiki. Also added a new generic `<attach/>` command that enables attaching files to be part of a recipe and uploaded by slaves as part of build.
osimons
parents: 606
diff changeset
59 resource = property(fget=lambda self: Resource('build', '%s' % self.name),
f3bb52da9e3c 0.6dev: Adding support for attachments to configurations and build - full web implementation that mirrors what is available in Ticket and Wiki. Also added a new generic `<attach/>` command that enables attaching files to be part of a recipe and uploaded by slaves as part of build.
osimons
parents: 606
diff changeset
60 doc='Build Config resource identification')
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
61
195
bd6234ed6ac5 Allow deletion of build configurations from the web interface. Closes #27.
cmlenz
parents: 174
diff changeset
62 def delete(self, db=None):
bd6234ed6ac5 Allow deletion of build configurations from the web interface. Closes #27.
cmlenz
parents: 174
diff changeset
63 """Remove a build configuration and all dependent objects from the
bd6234ed6ac5 Allow deletion of build configurations from the web interface. Closes #27.
cmlenz
parents: 174
diff changeset
64 database."""
bd6234ed6ac5 Allow deletion of build configurations from the web interface. Closes #27.
cmlenz
parents: 174
diff changeset
65 assert self.exists, 'Cannot delete non-existing configuration'
bd6234ed6ac5 Allow deletion of build configurations from the web interface. Closes #27.
cmlenz
parents: 174
diff changeset
66 if not db:
bd6234ed6ac5 Allow deletion of build configurations from the web interface. Closes #27.
cmlenz
parents: 174
diff changeset
67 db = self.env.get_db_cnx()
bd6234ed6ac5 Allow deletion of build configurations from the web interface. Closes #27.
cmlenz
parents: 174
diff changeset
68 handle_ta = True
bd6234ed6ac5 Allow deletion of build configurations from the web interface. Closes #27.
cmlenz
parents: 174
diff changeset
69 else:
bd6234ed6ac5 Allow deletion of build configurations from the web interface. Closes #27.
cmlenz
parents: 174
diff changeset
70 handle_ta = False
bd6234ed6ac5 Allow deletion of build configurations from the web interface. Closes #27.
cmlenz
parents: 174
diff changeset
71
203
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
72 for platform in list(TargetPlatform.select(self.env, self.name, db=db)):
195
bd6234ed6ac5 Allow deletion of build configurations from the web interface. Closes #27.
cmlenz
parents: 174
diff changeset
73 platform.delete(db=db)
bd6234ed6ac5 Allow deletion of build configurations from the web interface. Closes #27.
cmlenz
parents: 174
diff changeset
74
203
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
75 for build in list(Build.select(self.env, config=self.name, db=db)):
195
bd6234ed6ac5 Allow deletion of build configurations from the web interface. Closes #27.
cmlenz
parents: 174
diff changeset
76 build.delete(db=db)
bd6234ed6ac5 Allow deletion of build configurations from the web interface. Closes #27.
cmlenz
parents: 174
diff changeset
77
629
f3bb52da9e3c 0.6dev: Adding support for attachments to configurations and build - full web implementation that mirrors what is available in Ticket and Wiki. Also added a new generic `<attach/>` command that enables attaching files to be part of a recipe and uploaded by slaves as part of build.
osimons
parents: 606
diff changeset
78 # Delete attachments
f3bb52da9e3c 0.6dev: Adding support for attachments to configurations and build - full web implementation that mirrors what is available in Ticket and Wiki. Also added a new generic `<attach/>` command that enables attaching files to be part of a recipe and uploaded by slaves as part of build.
osimons
parents: 606
diff changeset
79 Attachment.delete_all(self.env, 'build', self.resource.id, db)
f3bb52da9e3c 0.6dev: Adding support for attachments to configurations and build - full web implementation that mirrors what is available in Ticket and Wiki. Also added a new generic `<attach/>` command that enables attaching files to be part of a recipe and uploaded by slaves as part of build.
osimons
parents: 606
diff changeset
80
195
bd6234ed6ac5 Allow deletion of build configurations from the web interface. Closes #27.
cmlenz
parents: 174
diff changeset
81 cursor = db.cursor()
bd6234ed6ac5 Allow deletion of build configurations from the web interface. Closes #27.
cmlenz
parents: 174
diff changeset
82 cursor.execute("DELETE FROM bitten_config WHERE name=%s", (self.name,))
bd6234ed6ac5 Allow deletion of build configurations from the web interface. Closes #27.
cmlenz
parents: 174
diff changeset
83
bd6234ed6ac5 Allow deletion of build configurations from the web interface. Closes #27.
cmlenz
parents: 174
diff changeset
84 if handle_ta:
bd6234ed6ac5 Allow deletion of build configurations from the web interface. Closes #27.
cmlenz
parents: 174
diff changeset
85 db.commit()
bd6234ed6ac5 Allow deletion of build configurations from the web interface. Closes #27.
cmlenz
parents: 174
diff changeset
86 self._old_name = None
bd6234ed6ac5 Allow deletion of build configurations from the web interface. Closes #27.
cmlenz
parents: 174
diff changeset
87
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
88 def insert(self, db=None):
157
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
89 """Insert a new configuration into the database."""
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
90 assert not self.exists, 'Cannot insert existing configuration'
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
91 assert self.name, 'Configuration requires a name'
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
92 if not db:
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
93 db = self.env.get_db_cnx()
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
94 handle_ta = True
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
95 else:
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
96 handle_ta = False
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
97
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
98 cursor = db.cursor()
147
395b67aa072e Build recipes are now stored in the database with the build configuration. This means that it is no longer necessary to store the recipe in the repository. Closes #41.
cmlenz
parents: 119
diff changeset
99 cursor.execute("INSERT INTO bitten_config (name,path,active,"
395b67aa072e Build recipes are now stored in the database with the build configuration. This means that it is no longer necessary to store the recipe in the repository. Closes #41.
cmlenz
parents: 119
diff changeset
100 "recipe,min_rev,max_rev,label,description) "
395b67aa072e Build recipes are now stored in the database with the build configuration. This means that it is no longer necessary to store the recipe in the repository. Closes #41.
cmlenz
parents: 119
diff changeset
101 "VALUES (%s,%s,%s,%s,%s,%s,%s,%s)",
395b67aa072e Build recipes are now stored in the database with the build configuration. This means that it is no longer necessary to store the recipe in the repository. Closes #41.
cmlenz
parents: 119
diff changeset
102 (self.name, self.path, int(self.active or 0),
395b67aa072e Build recipes are now stored in the database with the build configuration. This means that it is no longer necessary to store the recipe in the repository. Closes #41.
cmlenz
parents: 119
diff changeset
103 self.recipe or '', self.min_rev, self.max_rev,
395b67aa072e Build recipes are now stored in the database with the build configuration. This means that it is no longer necessary to store the recipe in the repository. Closes #41.
cmlenz
parents: 119
diff changeset
104 self.label or '', self.description or ''))
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
105
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
106 if handle_ta:
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
107 db.commit()
147
395b67aa072e Build recipes are now stored in the database with the build configuration. This means that it is no longer necessary to store the recipe in the repository. Closes #41.
cmlenz
parents: 119
diff changeset
108 self._old_name = self.name
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
109
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
110 def update(self, db=None):
157
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
111 """Save changes to an existing build configuration."""
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
112 assert self.exists, 'Cannot update a non-existing configuration'
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
113 assert self.name, 'Configuration requires a name'
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
114 if not db:
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
115 db = self.env.get_db_cnx()
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
116 handle_ta = True
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
117 else:
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
118 handle_ta = False
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
119
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
120 cursor = db.cursor()
147
395b67aa072e Build recipes are now stored in the database with the build configuration. This means that it is no longer necessary to store the recipe in the repository. Closes #41.
cmlenz
parents: 119
diff changeset
121 cursor.execute("UPDATE bitten_config SET name=%s,path=%s,active=%s,"
395b67aa072e Build recipes are now stored in the database with the build configuration. This means that it is no longer necessary to store the recipe in the repository. Closes #41.
cmlenz
parents: 119
diff changeset
122 "recipe=%s,min_rev=%s,max_rev=%s,label=%s,"
395b67aa072e Build recipes are now stored in the database with the build configuration. This means that it is no longer necessary to store the recipe in the repository. Closes #41.
cmlenz
parents: 119
diff changeset
123 "description=%s WHERE name=%s",
395b67aa072e Build recipes are now stored in the database with the build configuration. This means that it is no longer necessary to store the recipe in the repository. Closes #41.
cmlenz
parents: 119
diff changeset
124 (self.name, self.path, int(self.active or 0),
395b67aa072e Build recipes are now stored in the database with the build configuration. This means that it is no longer necessary to store the recipe in the repository. Closes #41.
cmlenz
parents: 119
diff changeset
125 self.recipe, self.min_rev, self.max_rev,
395b67aa072e Build recipes are now stored in the database with the build configuration. This means that it is no longer necessary to store the recipe in the repository. Closes #41.
cmlenz
parents: 119
diff changeset
126 self.label, self.description, self._old_name))
285
4fabcaf75787 Fix a bug that prevented a build configuration to be renamed after target platforms have been added, and maybe even builds executed.
cmlenz
parents: 282
diff changeset
127 if self.name != self._old_name:
4fabcaf75787 Fix a bug that prevented a build configuration to be renamed after target platforms have been added, and maybe even builds executed.
cmlenz
parents: 282
diff changeset
128 cursor.execute("UPDATE bitten_platform SET config=%s "
4fabcaf75787 Fix a bug that prevented a build configuration to be renamed after target platforms have been added, and maybe even builds executed.
cmlenz
parents: 282
diff changeset
129 "WHERE config=%s", (self.name, self._old_name))
4fabcaf75787 Fix a bug that prevented a build configuration to be renamed after target platforms have been added, and maybe even builds executed.
cmlenz
parents: 282
diff changeset
130 cursor.execute("UPDATE bitten_build SET config=%s "
4fabcaf75787 Fix a bug that prevented a build configuration to be renamed after target platforms have been added, and maybe even builds executed.
cmlenz
parents: 282
diff changeset
131 "WHERE config=%s", (self.name, self._old_name))
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
132
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
133 if handle_ta:
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
134 db.commit()
147
395b67aa072e Build recipes are now stored in the database with the build configuration. This means that it is no longer necessary to store the recipe in the repository. Closes #41.
cmlenz
parents: 119
diff changeset
135 self._old_name = self.name
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
136
96
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
137 def fetch(cls, env, name, db=None):
157
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
138 """Retrieve an existing build configuration from the database by
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
139 name.
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
140 """
96
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
141 if not db:
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
142 db = env.get_db_cnx()
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
143
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
144 cursor = db.cursor()
147
395b67aa072e Build recipes are now stored in the database with the build configuration. This means that it is no longer necessary to store the recipe in the repository. Closes #41.
cmlenz
parents: 119
diff changeset
145 cursor.execute("SELECT path,active,recipe,min_rev,max_rev,label,"
395b67aa072e Build recipes are now stored in the database with the build configuration. This means that it is no longer necessary to store the recipe in the repository. Closes #41.
cmlenz
parents: 119
diff changeset
146 "description FROM bitten_config WHERE name=%s", (name,))
96
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
147 row = cursor.fetchone()
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
148 if not row:
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
149 return None
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
150
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
151 config = BuildConfig(env)
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
152 config.name = config._old_name = name
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
153 config.path = row[0] or ''
433
201f467e0ec1 More unit tests for admin module.
cmlenz
parents: 411
diff changeset
154 config.active = bool(row[1])
147
395b67aa072e Build recipes are now stored in the database with the build configuration. This means that it is no longer necessary to store the recipe in the repository. Closes #41.
cmlenz
parents: 119
diff changeset
155 config.recipe = row[2] or ''
433
201f467e0ec1 More unit tests for admin module.
cmlenz
parents: 411
diff changeset
156 config.min_rev = row[3] or None
201f467e0ec1 More unit tests for admin module.
cmlenz
parents: 411
diff changeset
157 config.max_rev = row[4] or None
147
395b67aa072e Build recipes are now stored in the database with the build configuration. This means that it is no longer necessary to store the recipe in the repository. Closes #41.
cmlenz
parents: 119
diff changeset
158 config.label = row[5] or ''
395b67aa072e Build recipes are now stored in the database with the build configuration. This means that it is no longer necessary to store the recipe in the repository. Closes #41.
cmlenz
parents: 119
diff changeset
159 config.description = row[6] or ''
96
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
160 return config
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
161
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
162 fetch = classmethod(fetch)
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
163
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
164 def select(cls, env, include_inactive=False, db=None):
157
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
165 """Retrieve existing build configurations from the database that match
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
166 the specified criteria.
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
167 """
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
168 if not db:
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
169 db = env.get_db_cnx()
147
395b67aa072e Build recipes are now stored in the database with the build configuration. This means that it is no longer necessary to store the recipe in the repository. Closes #41.
cmlenz
parents: 119
diff changeset
170
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
171 cursor = db.cursor()
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
172 if include_inactive:
147
395b67aa072e Build recipes are now stored in the database with the build configuration. This means that it is no longer necessary to store the recipe in the repository. Closes #41.
cmlenz
parents: 119
diff changeset
173 cursor.execute("SELECT name,path,active,recipe,min_rev,max_rev,"
395b67aa072e Build recipes are now stored in the database with the build configuration. This means that it is no longer necessary to store the recipe in the repository. Closes #41.
cmlenz
parents: 119
diff changeset
174 "label,description FROM bitten_config ORDER BY name")
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
175 else:
147
395b67aa072e Build recipes are now stored in the database with the build configuration. This means that it is no longer necessary to store the recipe in the repository. Closes #41.
cmlenz
parents: 119
diff changeset
176 cursor.execute("SELECT name,path,active,recipe,min_rev,max_rev,"
395b67aa072e Build recipes are now stored in the database with the build configuration. This means that it is no longer necessary to store the recipe in the repository. Closes #41.
cmlenz
parents: 119
diff changeset
177 "label,description FROM bitten_config "
395b67aa072e Build recipes are now stored in the database with the build configuration. This means that it is no longer necessary to store the recipe in the repository. Closes #41.
cmlenz
parents: 119
diff changeset
178 "WHERE active=1 ORDER BY name")
395b67aa072e Build recipes are now stored in the database with the build configuration. This means that it is no longer necessary to store the recipe in the repository. Closes #41.
cmlenz
parents: 119
diff changeset
179 for name, path, active, recipe, min_rev, max_rev, label, description \
395b67aa072e Build recipes are now stored in the database with the build configuration. This means that it is no longer necessary to store the recipe in the repository. Closes #41.
cmlenz
parents: 119
diff changeset
180 in cursor:
97
03c8b5e3f111 Mark build configuration as existing when retrieved using {{{select()}}}.
cmlenz
parents: 96
diff changeset
181 config = BuildConfig(env, name=name, path=path or '',
147
395b67aa072e Build recipes are now stored in the database with the build configuration. This means that it is no longer necessary to store the recipe in the repository. Closes #41.
cmlenz
parents: 119
diff changeset
182 active=bool(active), recipe=recipe or '',
395b67aa072e Build recipes are now stored in the database with the build configuration. This means that it is no longer necessary to store the recipe in the repository. Closes #41.
cmlenz
parents: 119
diff changeset
183 min_rev=min_rev or None,
395b67aa072e Build recipes are now stored in the database with the build configuration. This means that it is no longer necessary to store the recipe in the repository. Closes #41.
cmlenz
parents: 119
diff changeset
184 max_rev=max_rev or None, label=label or '',
97
03c8b5e3f111 Mark build configuration as existing when retrieved using {{{select()}}}.
cmlenz
parents: 96
diff changeset
185 description=description or '')
03c8b5e3f111 Mark build configuration as existing when retrieved using {{{select()}}}.
cmlenz
parents: 96
diff changeset
186 config._old_name = name
03c8b5e3f111 Mark build configuration as existing when retrieved using {{{select()}}}.
cmlenz
parents: 96
diff changeset
187 yield config
96
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
188
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
189 select = classmethod(select)
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
190
757
ab1f18d0e98c Merge of [834] to 0.6
wbell
parents: 736
diff changeset
191 def min_rev_time(self, env):
ab1f18d0e98c Merge of [834] to 0.6
wbell
parents: 736
diff changeset
192 """Returns the time of the minimum revision being built for this
ab1f18d0e98c Merge of [834] to 0.6
wbell
parents: 736
diff changeset
193 configuration. Returns utcmin if not specified.
ab1f18d0e98c Merge of [834] to 0.6
wbell
parents: 736
diff changeset
194 """
ab1f18d0e98c Merge of [834] to 0.6
wbell
parents: 736
diff changeset
195 repos = env.get_repository()
805
4a1e2d555626 0.6dev: Merged [882] from trunk. Basic Trac 0.12 support.
osimons
parents: 763
diff changeset
196 assert repos, 'No "(default)" Repository: Add a repository or alias ' \
4a1e2d555626 0.6dev: Merged [882] from trunk. Basic Trac 0.12 support.
osimons
parents: 763
diff changeset
197 'named "(default)" to Trac.'
757
ab1f18d0e98c Merge of [834] to 0.6
wbell
parents: 736
diff changeset
198
ab1f18d0e98c Merge of [834] to 0.6
wbell
parents: 736
diff changeset
199 min_time = utcmin
809
9a4deb714478 0.6dev: Merged [886] from trunk.
osimons
parents: 805
diff changeset
200 if self.min_rev:
757
ab1f18d0e98c Merge of [834] to 0.6
wbell
parents: 736
diff changeset
201 min_time = repos.get_changeset(self.min_rev).date
ab1f18d0e98c Merge of [834] to 0.6
wbell
parents: 736
diff changeset
202
ab1f18d0e98c Merge of [834] to 0.6
wbell
parents: 736
diff changeset
203 if isinstance(min_time, datetime): # Trac>=0.11
ab1f18d0e98c Merge of [834] to 0.6
wbell
parents: 736
diff changeset
204 min_time = to_timestamp(min_time)
ab1f18d0e98c Merge of [834] to 0.6
wbell
parents: 736
diff changeset
205
ab1f18d0e98c Merge of [834] to 0.6
wbell
parents: 736
diff changeset
206 return min_time
ab1f18d0e98c Merge of [834] to 0.6
wbell
parents: 736
diff changeset
207
ab1f18d0e98c Merge of [834] to 0.6
wbell
parents: 736
diff changeset
208 def max_rev_time(self, env):
ab1f18d0e98c Merge of [834] to 0.6
wbell
parents: 736
diff changeset
209 """Returns the time of the maximum revision being built for this
ab1f18d0e98c Merge of [834] to 0.6
wbell
parents: 736
diff changeset
210 configuration. Returns utcmax if not specified.
ab1f18d0e98c Merge of [834] to 0.6
wbell
parents: 736
diff changeset
211 """
ab1f18d0e98c Merge of [834] to 0.6
wbell
parents: 736
diff changeset
212 repos = env.get_repository()
805
4a1e2d555626 0.6dev: Merged [882] from trunk. Basic Trac 0.12 support.
osimons
parents: 763
diff changeset
213 assert repos, 'No "(default)" Repository: Add a repository or alias ' \
4a1e2d555626 0.6dev: Merged [882] from trunk. Basic Trac 0.12 support.
osimons
parents: 763
diff changeset
214 'named "(default)" to Trac.'
757
ab1f18d0e98c Merge of [834] to 0.6
wbell
parents: 736
diff changeset
215
ab1f18d0e98c Merge of [834] to 0.6
wbell
parents: 736
diff changeset
216 max_time = utcmax
809
9a4deb714478 0.6dev: Merged [886] from trunk.
osimons
parents: 805
diff changeset
217 if self.max_rev:
757
ab1f18d0e98c Merge of [834] to 0.6
wbell
parents: 736
diff changeset
218 max_time = repos.get_changeset(self.max_rev).date
ab1f18d0e98c Merge of [834] to 0.6
wbell
parents: 736
diff changeset
219
ab1f18d0e98c Merge of [834] to 0.6
wbell
parents: 736
diff changeset
220 if isinstance(max_time, datetime): # Trac>=0.11
ab1f18d0e98c Merge of [834] to 0.6
wbell
parents: 736
diff changeset
221 max_time = to_timestamp(max_time)
ab1f18d0e98c Merge of [834] to 0.6
wbell
parents: 736
diff changeset
222
ab1f18d0e98c Merge of [834] to 0.6
wbell
parents: 736
diff changeset
223 return max_time
ab1f18d0e98c Merge of [834] to 0.6
wbell
parents: 736
diff changeset
224
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
225
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
226 class TargetPlatform(object):
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
227 """Target platform for a build configuration."""
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
228
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
229 _schema = [
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
230 Table('bitten_platform', key='id')[
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
231 Column('id', auto_increment=True), Column('config'), Column('name')
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
232 ],
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
233 Table('bitten_rule', key=('id', 'propname'))[
565
78109beea395 Type fixes for Postgres 8.x (we noticed issues on 8.3. Newer versions of Postgres don't auto massage integers from Python to string values in the database. In Bitten, this was causing issues with the 'id' field of bitten_rule, which was actually an integer (coming from the id field of the bitten_platform table.) Without explicitly converting it to a string, you'd see the error reported in #390. Added upgrade steps, tested on Postgres8.3. Closes #390. We may want to rename this field to 'platform' later.
wbell
parents: 553
diff changeset
234 Column('id', type='int'), Column('propname'), Column('pattern'),
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
235 Column('orderno', type='int')
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
236 ]
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
237 ]
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
238
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents: 213
diff changeset
239 def __init__(self, env, config=None, name=None):
157
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
240 """Initialize a new target platform with the specified attributes.
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
241
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
242 To actually create this platform in the database, the `insert` method
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
243 needs to be called.
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
244 """
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
245 self.env = env
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents: 213
diff changeset
246 self.id = None
96
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
247 self.config = config
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
248 self.name = name
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
249 self.rules = []
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
250
450
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 437
diff changeset
251 def __repr__(self):
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 437
diff changeset
252 return '<%s %r>' % (type(self).__name__, self.id)
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 437
diff changeset
253
316
87c9b1e8f086 More docstring improvements.
cmlenz
parents: 311
diff changeset
254 exists = property(fget=lambda self: self.id is not None,
87c9b1e8f086 More docstring improvements.
cmlenz
parents: 311
diff changeset
255 doc='Whether this target platform exists in the database')
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
256
74
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
257 def delete(self, db=None):
157
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
258 """Remove the target platform from the database."""
74
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
259 if not db:
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
260 db = self.env.get_db_cnx()
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
261 handle_ta = True
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
262 else:
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
263 handle_ta = False
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
264
553
98151eb9f1a5 If a target platform is deleted, any pending builds for that platform should be removed `[silk]` - fixes #382
dfraser
parents: 530
diff changeset
265 for build in Build.select(self.env, platform=self.id, status=Build.PENDING, db=db):
98151eb9f1a5 If a target platform is deleted, any pending builds for that platform should be removed `[silk]` - fixes #382
dfraser
parents: 530
diff changeset
266 build.delete()
98151eb9f1a5 If a target platform is deleted, any pending builds for that platform should be removed `[silk]` - fixes #382
dfraser
parents: 530
diff changeset
267
74
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
268 cursor = db.cursor()
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
269 cursor.execute("DELETE FROM bitten_rule WHERE id=%s", (self.id,))
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
270 cursor.execute("DELETE FROM bitten_platform WHERE id=%s", (self.id,))
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
271 if handle_ta:
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
272 db.commit()
1d4fa4c32afa Add template and static resources, hooked up using the new {{{ITemplateProvider}}} extension point in Trac.
cmlenz
parents: 73
diff changeset
273
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
274 def insert(self, db=None):
157
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
275 """Insert a new target platform into the database."""
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
276 if not db:
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
277 db = self.env.get_db_cnx()
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
278 handle_ta = True
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
279 else:
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
280 handle_ta = False
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
281
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
282 assert not self.exists, 'Cannot insert existing target platform'
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
283 assert self.config, 'Target platform needs to be associated with a ' \
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
284 'configuration'
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
285 assert self.name, 'Target platform requires a name'
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
286
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
287 cursor = db.cursor()
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
288 cursor.execute("INSERT INTO bitten_platform (config,name) "
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
289 "VALUES (%s,%s)", (self.config, self.name))
101
0ae9a10f9d88 More fixes following [http://projects.edgewall.com/trac/changeset/1995 Trac r1995], plus fixes for PySQLite 2 compatibility.
cmlenz
parents: 97
diff changeset
290 self.id = db.get_last_id(cursor, 'bitten_platform')
0ae9a10f9d88 More fixes following [http://projects.edgewall.com/trac/changeset/1995 Trac r1995], plus fixes for PySQLite 2 compatibility.
cmlenz
parents: 97
diff changeset
291 if self.rules:
0ae9a10f9d88 More fixes following [http://projects.edgewall.com/trac/changeset/1995 Trac r1995], plus fixes for PySQLite 2 compatibility.
cmlenz
parents: 97
diff changeset
292 cursor.executemany("INSERT INTO bitten_rule VALUES (%s,%s,%s,%s)",
0ae9a10f9d88 More fixes following [http://projects.edgewall.com/trac/changeset/1995 Trac r1995], plus fixes for PySQLite 2 compatibility.
cmlenz
parents: 97
diff changeset
293 [(self.id, propname, pattern, idx)
0ae9a10f9d88 More fixes following [http://projects.edgewall.com/trac/changeset/1995 Trac r1995], plus fixes for PySQLite 2 compatibility.
cmlenz
parents: 97
diff changeset
294 for idx, (propname, pattern)
0ae9a10f9d88 More fixes following [http://projects.edgewall.com/trac/changeset/1995 Trac r1995], plus fixes for PySQLite 2 compatibility.
cmlenz
parents: 97
diff changeset
295 in enumerate(self.rules)])
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
296
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
297 if handle_ta:
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
298 db.commit()
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
299
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
300 def update(self, db=None):
157
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
301 """Save changes to an existing target platform."""
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
302 assert self.exists, 'Cannot update a non-existing platform'
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
303 assert self.config, 'Target platform needs to be associated with a ' \
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
304 'configuration'
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
305 assert self.name, 'Target platform requires a name'
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
306 if not db:
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
307 db = self.env.get_db_cnx()
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
308 handle_ta = True
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
309 else:
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
310 handle_ta = False
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
311
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
312 cursor = db.cursor()
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
313 cursor.execute("UPDATE bitten_platform SET name=%s WHERE id=%s",
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
314 (self.name, self.id))
101
0ae9a10f9d88 More fixes following [http://projects.edgewall.com/trac/changeset/1995 Trac r1995], plus fixes for PySQLite 2 compatibility.
cmlenz
parents: 97
diff changeset
315 cursor.execute("DELETE FROM bitten_rule WHERE id=%s", (self.id,))
0ae9a10f9d88 More fixes following [http://projects.edgewall.com/trac/changeset/1995 Trac r1995], plus fixes for PySQLite 2 compatibility.
cmlenz
parents: 97
diff changeset
316 if self.rules:
0ae9a10f9d88 More fixes following [http://projects.edgewall.com/trac/changeset/1995 Trac r1995], plus fixes for PySQLite 2 compatibility.
cmlenz
parents: 97
diff changeset
317 cursor.executemany("INSERT INTO bitten_rule VALUES (%s,%s,%s,%s)",
0ae9a10f9d88 More fixes following [http://projects.edgewall.com/trac/changeset/1995 Trac r1995], plus fixes for PySQLite 2 compatibility.
cmlenz
parents: 97
diff changeset
318 [(self.id, propname, pattern, idx)
0ae9a10f9d88 More fixes following [http://projects.edgewall.com/trac/changeset/1995 Trac r1995], plus fixes for PySQLite 2 compatibility.
cmlenz
parents: 97
diff changeset
319 for idx, (propname, pattern)
0ae9a10f9d88 More fixes following [http://projects.edgewall.com/trac/changeset/1995 Trac r1995], plus fixes for PySQLite 2 compatibility.
cmlenz
parents: 97
diff changeset
320 in enumerate(self.rules)])
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
321
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
322 if handle_ta:
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
323 db.commit()
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
324
96
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
325 def fetch(cls, env, id, db=None):
157
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
326 """Retrieve an existing target platform from the database by ID."""
96
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
327 if not db:
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
328 db = env.get_db_cnx()
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
329
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
330 cursor = db.cursor()
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
331 cursor.execute("SELECT config,name FROM bitten_platform "
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
332 "WHERE id=%s", (id,))
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
333 row = cursor.fetchone()
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
334 if not row:
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
335 return None
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
336
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents: 213
diff changeset
337 platform = TargetPlatform(env, config=row[0], name=row[1])
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents: 213
diff changeset
338 platform.id = id
96
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
339 cursor.execute("SELECT propname,pattern FROM bitten_rule "
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
340 "WHERE id=%s ORDER BY orderno", (id,))
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
341 for propname, pattern in cursor:
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
342 platform.rules.append((propname, pattern))
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
343 return platform
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
344
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
345 fetch = classmethod(fetch)
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
346
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
347 def select(cls, env, config=None, db=None):
157
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
348 """Retrieve existing target platforms from the database that match the
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
349 specified criteria.
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
350 """
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
351 if not db:
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
352 db = env.get_db_cnx()
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
353
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
354 where_clauses = []
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
355 if config is not None:
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
356 where_clauses.append(("config=%s", config))
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
357 if where_clauses:
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
358 where = "WHERE " + " AND ".join([wc[0] for wc in where_clauses])
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
359 else:
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
360 where = ""
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
361
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
362 cursor = db.cursor()
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
363 cursor.execute("SELECT id FROM bitten_platform %s ORDER BY name"
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
364 % where, [wc[1] for wc in where_clauses])
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
365 for (id,) in cursor:
96
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
366 yield TargetPlatform.fetch(env, id)
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
367
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
368 select = classmethod(select)
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
369
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
370
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
371 class Build(object):
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
372 """Representation of a build."""
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
373
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
374 _schema = [
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
375 Table('bitten_build', key='id')[
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
376 Column('id', auto_increment=True), Column('config'), Column('rev'),
76
ffa1ffd8c7db * Implement basic slave selection based on configured target platforms. Closes #15.
cmlenz
parents: 74
diff changeset
377 Column('rev_time', type='int'), Column('platform', type='int'),
ffa1ffd8c7db * Implement basic slave selection based on configured target platforms. Closes #15.
cmlenz
parents: 74
diff changeset
378 Column('slave'), Column('started', type='int'),
80
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
379 Column('stopped', type='int'), Column('status', size=1),
763
de466e590545 Port of [638], [639], [640] to 0.6.x
wbell
parents: 757
diff changeset
380 Column('last_activity', type='int'),
650
b1a50f2d92eb 0.6dev: Database upgrade to ensure no duplicate builds are created due to thread race condition when populating builds. Threaded test included.
osimons
parents: 649
diff changeset
381 Index(['config', 'rev', 'platform'], unique=True)
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
382 ],
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
383 Table('bitten_slave', key=('build', 'propname'))[
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
384 Column('build', type='int'), Column('propname'), Column('propvalue')
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
385 ]
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
386 ]
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
387
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
388 # Build status codes
47
083e848088ee * Improvements to the model classes, and a couple of unit tests.
cmlenz
parents: 45
diff changeset
389 PENDING = 'P'
083e848088ee * Improvements to the model classes, and a couple of unit tests.
cmlenz
parents: 45
diff changeset
390 IN_PROGRESS = 'I'
083e848088ee * Improvements to the model classes, and a couple of unit tests.
cmlenz
parents: 45
diff changeset
391 SUCCESS = 'S'
083e848088ee * Improvements to the model classes, and a couple of unit tests.
cmlenz
parents: 45
diff changeset
392 FAILURE = 'F'
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
393
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
394 # Standard slave properties
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
395 IP_ADDRESS = 'ipnr'
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
396 MAINTAINER = 'owner'
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
397 OS_NAME = 'os'
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
398 OS_FAMILY = 'family'
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
399 OS_VERSION = 'version'
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
400 MACHINE = 'machine'
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
401 PROCESSOR = 'processor'
649
eed0149c302a 0.6dev: Switching to use the new cookie-support, and using trac auth/session ID as unique identification for linking builds with slaves. This overcomes problems with IP address not being unique behind NAT, and also where IP address may change during a build. Closes #421.
osimons
parents: 640
diff changeset
402 TOKEN = 'token'
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
403
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents: 213
diff changeset
404 def __init__(self, env, config=None, rev=None, platform=None, slave=None,
763
de466e590545 Port of [638], [639], [640] to 0.6.x
wbell
parents: 757
diff changeset
405 started=0, stopped=0, last_activity=0,
de466e590545 Port of [638], [639], [640] to 0.6.x
wbell
parents: 757
diff changeset
406 rev_time=0, status=PENDING):
157
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
407 """Initialize a new build with the specified attributes.
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
408
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
409 To actually create this build in the database, the `insert` method needs
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
410 to be called.
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
411 """
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
412 self.env = env
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents: 213
diff changeset
413 self.id = None
96
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
414 self.config = config
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents: 213
diff changeset
415 self.rev = rev and str(rev) or None
96
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
416 self.platform = platform
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
417 self.slave = slave
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
418 self.started = started or 0
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
419 self.stopped = stopped or 0
763
de466e590545 Port of [638], [639], [640] to 0.6.x
wbell
parents: 757
diff changeset
420 self.last_activity = last_activity or 0
96
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
421 self.rev_time = rev_time
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
422 self.status = status
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents: 213
diff changeset
423 self.slave_info = {}
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
424
450
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 437
diff changeset
425 def __repr__(self):
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 437
diff changeset
426 return '<%s %r>' % (type(self).__name__, self.id)
9d0651c819a8 Proper fix for #165, [493] was broken. This time with added tests.
cmlenz
parents: 437
diff changeset
427
316
87c9b1e8f086 More docstring improvements.
cmlenz
parents: 311
diff changeset
428 exists = property(fget=lambda self: self.id is not None,
87c9b1e8f086 More docstring improvements.
cmlenz
parents: 311
diff changeset
429 doc='Whether this build exists in the database')
87c9b1e8f086 More docstring improvements.
cmlenz
parents: 311
diff changeset
430 completed = property(fget=lambda self: self.status != Build.IN_PROGRESS,
87c9b1e8f086 More docstring improvements.
cmlenz
parents: 311
diff changeset
431 doc='Whether the build has been completed')
87c9b1e8f086 More docstring improvements.
cmlenz
parents: 311
diff changeset
432 successful = property(fget=lambda self: self.status == Build.SUCCESS,
87c9b1e8f086 More docstring improvements.
cmlenz
parents: 311
diff changeset
433 doc='Whether the build was successful')
629
f3bb52da9e3c 0.6dev: Adding support for attachments to configurations and build - full web implementation that mirrors what is available in Ticket and Wiki. Also added a new generic `<attach/>` command that enables attaching files to be part of a recipe and uploaded by slaves as part of build.
osimons
parents: 606
diff changeset
434 resource = property(fget=lambda self: Resource('build', '%s/%s' % (self.config, self.id)),
f3bb52da9e3c 0.6dev: Adding support for attachments to configurations and build - full web implementation that mirrors what is available in Ticket and Wiki. Also added a new generic `<attach/>` command that enables attaching files to be part of a recipe and uploaded by slaves as part of build.
osimons
parents: 606
diff changeset
435 doc='Build resource identification')
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
436
47
083e848088ee * Improvements to the model classes, and a couple of unit tests.
cmlenz
parents: 45
diff changeset
437 def delete(self, db=None):
157
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
438 """Remove the build from the database."""
311
7f6fc38e14ff More assertions in `Build` model methods.
cmlenz
parents: 285
diff changeset
439 assert self.exists, 'Cannot delete a non-existing build'
47
083e848088ee * Improvements to the model classes, and a couple of unit tests.
cmlenz
parents: 45
diff changeset
440 if not db:
083e848088ee * Improvements to the model classes, and a couple of unit tests.
cmlenz
parents: 45
diff changeset
441 db = self.env.get_db_cnx()
083e848088ee * Improvements to the model classes, and a couple of unit tests.
cmlenz
parents: 45
diff changeset
442 handle_ta = True
083e848088ee * Improvements to the model classes, and a couple of unit tests.
cmlenz
parents: 45
diff changeset
443 else:
083e848088ee * Improvements to the model classes, and a couple of unit tests.
cmlenz
parents: 45
diff changeset
444 handle_ta = False
083e848088ee * Improvements to the model classes, and a couple of unit tests.
cmlenz
parents: 45
diff changeset
445
203
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
446 for step in list(BuildStep.select(self.env, build=self.id)):
119
430c518ebb14 * More logging in master and slave about the build status.
cmlenz
parents: 117
diff changeset
447 step.delete(db=db)
430c518ebb14 * More logging in master and slave about the build status.
cmlenz
parents: 117
diff changeset
448
629
f3bb52da9e3c 0.6dev: Adding support for attachments to configurations and build - full web implementation that mirrors what is available in Ticket and Wiki. Also added a new generic `<attach/>` command that enables attaching files to be part of a recipe and uploaded by slaves as part of build.
osimons
parents: 606
diff changeset
449 # Delete attachments
f3bb52da9e3c 0.6dev: Adding support for attachments to configurations and build - full web implementation that mirrors what is available in Ticket and Wiki. Also added a new generic `<attach/>` command that enables attaching files to be part of a recipe and uploaded by slaves as part of build.
osimons
parents: 606
diff changeset
450 Attachment.delete_all(self.env, 'build', self.resource.id, db)
f3bb52da9e3c 0.6dev: Adding support for attachments to configurations and build - full web implementation that mirrors what is available in Ticket and Wiki. Also added a new generic `<attach/>` command that enables attaching files to be part of a recipe and uploaded by slaves as part of build.
osimons
parents: 606
diff changeset
451
47
083e848088ee * Improvements to the model classes, and a couple of unit tests.
cmlenz
parents: 45
diff changeset
452 cursor = db.cursor()
119
430c518ebb14 * More logging in master and slave about the build status.
cmlenz
parents: 117
diff changeset
453 cursor.execute("DELETE FROM bitten_slave WHERE build=%s", (self.id,))
69
b92d7c7d70fd Record build slave properties in database.
cmlenz
parents: 56
diff changeset
454 cursor.execute("DELETE FROM bitten_build WHERE id=%s", (self.id,))
119
430c518ebb14 * More logging in master and slave about the build status.
cmlenz
parents: 117
diff changeset
455
47
083e848088ee * Improvements to the model classes, and a couple of unit tests.
cmlenz
parents: 45
diff changeset
456 if handle_ta:
083e848088ee * Improvements to the model classes, and a couple of unit tests.
cmlenz
parents: 45
diff changeset
457 db.commit()
083e848088ee * Improvements to the model classes, and a couple of unit tests.
cmlenz
parents: 45
diff changeset
458
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
459 def insert(self, db=None):
157
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
460 """Insert a new build into the database."""
311
7f6fc38e14ff More assertions in `Build` model methods.
cmlenz
parents: 285
diff changeset
461 assert not self.exists, 'Cannot insert an existing build'
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
462 if not db:
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
463 db = self.env.get_db_cnx()
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
464 handle_ta = True
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
465 else:
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
466 handle_ta = False
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
467
76
ffa1ffd8c7db * Implement basic slave selection based on configured target platforms. Closes #15.
cmlenz
parents: 74
diff changeset
468 assert self.config and self.rev and self.rev_time and self.platform
47
083e848088ee * Improvements to the model classes, and a couple of unit tests.
cmlenz
parents: 45
diff changeset
469 assert self.status in (self.PENDING, self.IN_PROGRESS, self.SUCCESS,
083e848088ee * Improvements to the model classes, and a couple of unit tests.
cmlenz
parents: 45
diff changeset
470 self.FAILURE)
083e848088ee * Improvements to the model classes, and a couple of unit tests.
cmlenz
parents: 45
diff changeset
471 if not self.slave:
083e848088ee * Improvements to the model classes, and a couple of unit tests.
cmlenz
parents: 45
diff changeset
472 assert self.status == self.PENDING
083e848088ee * Improvements to the model classes, and a couple of unit tests.
cmlenz
parents: 45
diff changeset
473
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
474 cursor = db.cursor()
76
ffa1ffd8c7db * Implement basic slave selection based on configured target platforms. Closes #15.
cmlenz
parents: 74
diff changeset
475 cursor.execute("INSERT INTO bitten_build (config,rev,rev_time,platform,"
763
de466e590545 Port of [638], [639], [640] to 0.6.x
wbell
parents: 757
diff changeset
476 "slave,started,stopped,last_activity,status) "
de466e590545 Port of [638], [639], [640] to 0.6.x
wbell
parents: 757
diff changeset
477 "VALUES (%s,%s,%s,%s,%s,%s,%s,%s,%s)",
437
6d5ac24061dc Fix build queue population compatiblity with Trac 0.11, where revision timestamps are `datetime` objects.
cmlenz
parents: 436
diff changeset
478 (self.config, self.rev, int(self.rev_time),
6d5ac24061dc Fix build queue population compatiblity with Trac 0.11, where revision timestamps are `datetime` objects.
cmlenz
parents: 436
diff changeset
479 self.platform, self.slave or '', self.started or 0,
763
de466e590545 Port of [638], [639], [640] to 0.6.x
wbell
parents: 757
diff changeset
480 self.stopped or 0, self.last_activity or 0,
de466e590545 Port of [638], [639], [640] to 0.6.x
wbell
parents: 757
diff changeset
481 self.status))
101
0ae9a10f9d88 More fixes following [http://projects.edgewall.com/trac/changeset/1995 Trac r1995], plus fixes for PySQLite 2 compatibility.
cmlenz
parents: 97
diff changeset
482 self.id = db.get_last_id(cursor, 'bitten_build')
0ae9a10f9d88 More fixes following [http://projects.edgewall.com/trac/changeset/1995 Trac r1995], plus fixes for PySQLite 2 compatibility.
cmlenz
parents: 97
diff changeset
483 if self.slave_info:
0ae9a10f9d88 More fixes following [http://projects.edgewall.com/trac/changeset/1995 Trac r1995], plus fixes for PySQLite 2 compatibility.
cmlenz
parents: 97
diff changeset
484 cursor.executemany("INSERT INTO bitten_slave VALUES (%s,%s,%s)",
0ae9a10f9d88 More fixes following [http://projects.edgewall.com/trac/changeset/1995 Trac r1995], plus fixes for PySQLite 2 compatibility.
cmlenz
parents: 97
diff changeset
485 [(self.id, name, value) for name, value
0ae9a10f9d88 More fixes following [http://projects.edgewall.com/trac/changeset/1995 Trac r1995], plus fixes for PySQLite 2 compatibility.
cmlenz
parents: 97
diff changeset
486 in self.slave_info.items()])
73
6d7753ea1798 Implemented basic management of target platforms. Closes #14.
cmlenz
parents: 71
diff changeset
487
47
083e848088ee * Improvements to the model classes, and a couple of unit tests.
cmlenz
parents: 45
diff changeset
488 if handle_ta:
083e848088ee * Improvements to the model classes, and a couple of unit tests.
cmlenz
parents: 45
diff changeset
489 db.commit()
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
490
47
083e848088ee * Improvements to the model classes, and a couple of unit tests.
cmlenz
parents: 45
diff changeset
491 def update(self, db=None):
157
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
492 """Save changes to an existing build."""
311
7f6fc38e14ff More assertions in `Build` model methods.
cmlenz
parents: 285
diff changeset
493 assert self.exists, 'Cannot update a non-existing build'
47
083e848088ee * Improvements to the model classes, and a couple of unit tests.
cmlenz
parents: 45
diff changeset
494 if not db:
083e848088ee * Improvements to the model classes, and a couple of unit tests.
cmlenz
parents: 45
diff changeset
495 db = self.env.get_db_cnx()
083e848088ee * Improvements to the model classes, and a couple of unit tests.
cmlenz
parents: 45
diff changeset
496 handle_ta = True
083e848088ee * Improvements to the model classes, and a couple of unit tests.
cmlenz
parents: 45
diff changeset
497 else:
083e848088ee * Improvements to the model classes, and a couple of unit tests.
cmlenz
parents: 45
diff changeset
498 handle_ta = False
083e848088ee * Improvements to the model classes, and a couple of unit tests.
cmlenz
parents: 45
diff changeset
499
083e848088ee * Improvements to the model classes, and a couple of unit tests.
cmlenz
parents: 45
diff changeset
500 assert self.config and self.rev
083e848088ee * Improvements to the model classes, and a couple of unit tests.
cmlenz
parents: 45
diff changeset
501 assert self.status in (self.PENDING, self.IN_PROGRESS, self.SUCCESS,
083e848088ee * Improvements to the model classes, and a couple of unit tests.
cmlenz
parents: 45
diff changeset
502 self.FAILURE)
083e848088ee * Improvements to the model classes, and a couple of unit tests.
cmlenz
parents: 45
diff changeset
503 if not self.slave:
083e848088ee * Improvements to the model classes, and a couple of unit tests.
cmlenz
parents: 45
diff changeset
504 assert self.status == self.PENDING
083e848088ee * Improvements to the model classes, and a couple of unit tests.
cmlenz
parents: 45
diff changeset
505
083e848088ee * Improvements to the model classes, and a couple of unit tests.
cmlenz
parents: 45
diff changeset
506 cursor = db.cursor()
69
b92d7c7d70fd Record build slave properties in database.
cmlenz
parents: 56
diff changeset
507 cursor.execute("UPDATE bitten_build SET slave=%s,started=%s,"
763
de466e590545 Port of [638], [639], [640] to 0.6.x
wbell
parents: 757
diff changeset
508 "stopped=%s,last_activity=%s,status=%s WHERE id=%s",
69
b92d7c7d70fd Record build slave properties in database.
cmlenz
parents: 56
diff changeset
509 (self.slave or '', self.started or 0,
763
de466e590545 Port of [638], [639], [640] to 0.6.x
wbell
parents: 757
diff changeset
510 self.stopped or 0, self.last_activity or 0,
de466e590545 Port of [638], [639], [640] to 0.6.x
wbell
parents: 757
diff changeset
511 self.status, self.id))
112
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
512 cursor.execute("DELETE FROM bitten_slave WHERE build=%s", (self.id,))
117
2f0f2f006526 Delete build steps when cleaning up pending builds.
cmlenz
parents: 112
diff changeset
513 if self.slave_info:
2f0f2f006526 Delete build steps when cleaning up pending builds.
cmlenz
parents: 112
diff changeset
514 cursor.executemany("INSERT INTO bitten_slave VALUES (%s,%s,%s)",
2f0f2f006526 Delete build steps when cleaning up pending builds.
cmlenz
parents: 112
diff changeset
515 [(self.id, name, value) for name, value
2f0f2f006526 Delete build steps when cleaning up pending builds.
cmlenz
parents: 112
diff changeset
516 in self.slave_info.items()])
47
083e848088ee * Improvements to the model classes, and a couple of unit tests.
cmlenz
parents: 45
diff changeset
517 if handle_ta:
083e848088ee * Improvements to the model classes, and a couple of unit tests.
cmlenz
parents: 45
diff changeset
518 db.commit()
083e848088ee * Improvements to the model classes, and a couple of unit tests.
cmlenz
parents: 45
diff changeset
519
96
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
520 def fetch(cls, env, id, db=None):
157
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
521 """Retrieve an existing build from the database by ID."""
96
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
522 if not db:
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
523 db = env.get_db_cnx()
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
524
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
525 cursor = db.cursor()
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
526 cursor.execute("SELECT config,rev,rev_time,platform,slave,started,"
763
de466e590545 Port of [638], [639], [640] to 0.6.x
wbell
parents: 757
diff changeset
527 "stopped,last_activity,status FROM bitten_build WHERE "
de466e590545 Port of [638], [639], [640] to 0.6.x
wbell
parents: 757
diff changeset
528 "id=%s", (id,))
96
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
529 row = cursor.fetchone()
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
530 if not row:
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
531 return None
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
532
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents: 213
diff changeset
533 build = Build(env, config=row[0], rev=row[1], rev_time=int(row[2]),
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents: 213
diff changeset
534 platform=int(row[3]), slave=row[4],
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents: 213
diff changeset
535 started=row[5] and int(row[5]) or 0,
763
de466e590545 Port of [638], [639], [640] to 0.6.x
wbell
parents: 757
diff changeset
536 stopped=row[6] and int(row[6]) or 0,
de466e590545 Port of [638], [639], [640] to 0.6.x
wbell
parents: 757
diff changeset
537 last_activity=row[7] and int(row[7]) or 0,
de466e590545 Port of [638], [639], [640] to 0.6.x
wbell
parents: 757
diff changeset
538 status=row[8])
227
014bc6c29dff * Factor build queue logic into a class separate from the build master.
cmlenz
parents: 213
diff changeset
539 build.id = int(id)
96
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
540 cursor.execute("SELECT propname,propvalue FROM bitten_slave "
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
541 "WHERE build=%s", (id,))
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
542 for propname, propvalue in cursor:
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
543 build.slave_info[propname] = propvalue
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
544 return build
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
545
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
546 fetch = classmethod(fetch)
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
547
76
ffa1ffd8c7db * Implement basic slave selection based on configured target platforms. Closes #15.
cmlenz
parents: 74
diff changeset
548 def select(cls, env, config=None, rev=None, platform=None, slave=None,
606
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 574
diff changeset
549 status=None, db=None, min_rev_time=None, max_rev_time=None):
157
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
550 """Retrieve existing builds from the database that match the specified
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
551 criteria.
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
552 """
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
553 if not db:
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
554 db = env.get_db_cnx()
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
555
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
556 where_clauses = []
47
083e848088ee * Improvements to the model classes, and a couple of unit tests.
cmlenz
parents: 45
diff changeset
557 if config is not None:
083e848088ee * Improvements to the model classes, and a couple of unit tests.
cmlenz
parents: 45
diff changeset
558 where_clauses.append(("config=%s", config))
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
559 if rev is not None:
567
e1f5a99c41d9 Small build fix.
wbell
parents: 566
diff changeset
560 where_clauses.append(("rev=%s", str(rev)))
76
ffa1ffd8c7db * Implement basic slave selection based on configured target platforms. Closes #15.
cmlenz
parents: 74
diff changeset
561 if platform is not None:
ffa1ffd8c7db * Implement basic slave selection based on configured target platforms. Closes #15.
cmlenz
parents: 74
diff changeset
562 where_clauses.append(("platform=%s", platform))
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
563 if slave is not None:
47
083e848088ee * Improvements to the model classes, and a couple of unit tests.
cmlenz
parents: 45
diff changeset
564 where_clauses.append(("slave=%s", slave))
083e848088ee * Improvements to the model classes, and a couple of unit tests.
cmlenz
parents: 45
diff changeset
565 if status is not None:
083e848088ee * Improvements to the model classes, and a couple of unit tests.
cmlenz
parents: 45
diff changeset
566 where_clauses.append(("status=%s", status))
606
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 574
diff changeset
567 if min_rev_time is not None:
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 574
diff changeset
568 where_clauses.append(("rev_time>=%s", min_rev_time))
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 574
diff changeset
569 if max_rev_time is not None:
07ac9218f649 0.6dev: Fixing numerous problems related to `BuildQueue.should_delete_build()`:
osimons
parents: 574
diff changeset
570 where_clauses.append(("rev_time<=%s", max_rev_time))
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
571 if where_clauses:
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
572 where = "WHERE " + " AND ".join([wc[0] for wc in where_clauses])
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
573 else:
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
574 where = ""
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
575
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
576 cursor = db.cursor()
96
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
577 cursor.execute("SELECT id FROM bitten_build %s "
574
f5ba11158030 0.6dev: Follow-ups to recent commits detected by failing builds:
osimons
parents: 573
diff changeset
578 "ORDER BY rev_time DESC,config,slave"
69
b92d7c7d70fd Record build slave properties in database.
cmlenz
parents: 56
diff changeset
579 % where, [wc[1] for wc in where_clauses])
96
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
580 for (id,) in cursor:
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
581 yield Build.fetch(env, id)
41
16b30ffc5fb9 Add web interface for viewing and managing build configurations. Closes #9.
cmlenz
parents:
diff changeset
582 select = classmethod(select)
69
b92d7c7d70fd Record build slave properties in database.
cmlenz
parents: 56
diff changeset
583
b92d7c7d70fd Record build slave properties in database.
cmlenz
parents: 56
diff changeset
584
80
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
585 class BuildStep(object):
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
586 """Represents an individual step of an executed build."""
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
587
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
588 _schema = [
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
589 Table('bitten_step', key=('build', 'name'))[
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
590 Column('build', type='int'), Column('name'), Column('description'),
112
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
591 Column('status', size=1), Column('started', type='int'),
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
592 Column('stopped', type='int')
245
a22ec8fce6c9 Store the reason(s) for build step failure in the database.
cmlenz
parents: 236
diff changeset
593 ],
a22ec8fce6c9 Store the reason(s) for build step failure in the database.
cmlenz
parents: 236
diff changeset
594 Table('bitten_error', key=('build', 'step', 'orderno'))[
a22ec8fce6c9 Store the reason(s) for build step failure in the database.
cmlenz
parents: 236
diff changeset
595 Column('build', type='int'), Column('step'), Column('message'),
a22ec8fce6c9 Store the reason(s) for build step failure in the database.
cmlenz
parents: 236
diff changeset
596 Column('orderno', type='int')
80
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
597 ]
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
598 ]
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
599
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
600 # Step status codes
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
601 SUCCESS = 'S'
763
de466e590545 Port of [638], [639], [640] to 0.6.x
wbell
parents: 757
diff changeset
602 IN_PROGRESS = 'I'
80
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
603 FAILURE = 'F'
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
604
96
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
605 def __init__(self, env, build=None, name=None, description=None,
246
ebfe660f7cb1 More/better unit tests for `bitten.model.BuildStep`.
cmlenz
parents: 245
diff changeset
606 status=None, started=None, stopped=None):
157
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
607 """Initialize a new build step with the specified attributes.
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
608
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
609 To actually create this build step in the database, the `insert` method
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
610 needs to be called.
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
611 """
80
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
612 self.env = env
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
613 self.build = build
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
614 self.name = name
96
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
615 self.description = description
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
616 self.status = status
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
617 self.started = started
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
618 self.stopped = stopped
246
ebfe660f7cb1 More/better unit tests for `bitten.model.BuildStep`.
cmlenz
parents: 245
diff changeset
619 self.errors = []
245
a22ec8fce6c9 Store the reason(s) for build step failure in the database.
cmlenz
parents: 236
diff changeset
620 self._exists = False
80
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
621
316
87c9b1e8f086 More docstring improvements.
cmlenz
parents: 311
diff changeset
622 exists = property(fget=lambda self: self._exists,
87c9b1e8f086 More docstring improvements.
cmlenz
parents: 311
diff changeset
623 doc='Whether this build step exists in the database')
87c9b1e8f086 More docstring improvements.
cmlenz
parents: 311
diff changeset
624 successful = property(fget=lambda self: self.status == BuildStep.SUCCESS,
87c9b1e8f086 More docstring improvements.
cmlenz
parents: 311
diff changeset
625 doc='Whether the build step was successful')
763
de466e590545 Port of [638], [639], [640] to 0.6.x
wbell
parents: 757
diff changeset
626 completed = property(fget=lambda self: self.status == BuildStep.SUCCESS or self.status == BuildStep.FAILURE,
de466e590545 Port of [638], [639], [640] to 0.6.x
wbell
parents: 757
diff changeset
627 doc='Whether this build step has completed processing')
94
e5d1a792aa45 Cleanup and records when a build is aborted.
cmlenz
parents: 80
diff changeset
628 def delete(self, db=None):
157
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
629 """Remove the build step from the database."""
94
e5d1a792aa45 Cleanup and records when a build is aborted.
cmlenz
parents: 80
diff changeset
630 if not db:
e5d1a792aa45 Cleanup and records when a build is aborted.
cmlenz
parents: 80
diff changeset
631 db = self.env.get_db_cnx()
e5d1a792aa45 Cleanup and records when a build is aborted.
cmlenz
parents: 80
diff changeset
632 handle_ta = True
e5d1a792aa45 Cleanup and records when a build is aborted.
cmlenz
parents: 80
diff changeset
633 else:
e5d1a792aa45 Cleanup and records when a build is aborted.
cmlenz
parents: 80
diff changeset
634 handle_ta = False
e5d1a792aa45 Cleanup and records when a build is aborted.
cmlenz
parents: 80
diff changeset
635
203
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
636 for log in list(BuildLog.select(self.env, build=self.build,
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
637 step=self.name, db=db)):
119
430c518ebb14 * More logging in master and slave about the build status.
cmlenz
parents: 117
diff changeset
638 log.delete(db=db)
203
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
639 for report in list(Report.select(self.env, build=self.build,
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
640 step=self.name, db=db)):
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
641 report.delete(db=db)
119
430c518ebb14 * More logging in master and slave about the build status.
cmlenz
parents: 117
diff changeset
642
94
e5d1a792aa45 Cleanup and records when a build is aborted.
cmlenz
parents: 80
diff changeset
643 cursor = db.cursor()
e5d1a792aa45 Cleanup and records when a build is aborted.
cmlenz
parents: 80
diff changeset
644 cursor.execute("DELETE FROM bitten_step WHERE build=%s AND name=%s",
e5d1a792aa45 Cleanup and records when a build is aborted.
cmlenz
parents: 80
diff changeset
645 (self.build, self.name))
245
a22ec8fce6c9 Store the reason(s) for build step failure in the database.
cmlenz
parents: 236
diff changeset
646 cursor.execute("DELETE FROM bitten_error WHERE build=%s AND step=%s",
a22ec8fce6c9 Store the reason(s) for build step failure in the database.
cmlenz
parents: 236
diff changeset
647 (self.build, self.name))
a22ec8fce6c9 Store the reason(s) for build step failure in the database.
cmlenz
parents: 236
diff changeset
648
94
e5d1a792aa45 Cleanup and records when a build is aborted.
cmlenz
parents: 80
diff changeset
649 if handle_ta:
e5d1a792aa45 Cleanup and records when a build is aborted.
cmlenz
parents: 80
diff changeset
650 db.commit()
245
a22ec8fce6c9 Store the reason(s) for build step failure in the database.
cmlenz
parents: 236
diff changeset
651 self._exists = False
94
e5d1a792aa45 Cleanup and records when a build is aborted.
cmlenz
parents: 80
diff changeset
652
80
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
653 def insert(self, db=None):
157
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
654 """Insert a new build step into the database."""
80
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
655 if not db:
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
656 db = self.env.get_db_cnx()
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
657 handle_ta = True
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
658 else:
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
659 handle_ta = False
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
660
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
661 assert self.build and self.name
763
de466e590545 Port of [638], [639], [640] to 0.6.x
wbell
parents: 757
diff changeset
662 assert self.status in (self.SUCCESS, self.IN_PROGRESS, self.FAILURE)
80
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
663
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
664 cursor = db.cursor()
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
665 cursor.execute("INSERT INTO bitten_step (build,name,description,status,"
112
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
666 "started,stopped) VALUES (%s,%s,%s,%s,%s,%s)",
80
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
667 (self.build, self.name, self.description or '',
112
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
668 self.status, self.started or 0, self.stopped or 0))
245
a22ec8fce6c9 Store the reason(s) for build step failure in the database.
cmlenz
parents: 236
diff changeset
669 if self.errors:
a22ec8fce6c9 Store the reason(s) for build step failure in the database.
cmlenz
parents: 236
diff changeset
670 cursor.executemany("INSERT INTO bitten_error (build,step,message,"
a22ec8fce6c9 Store the reason(s) for build step failure in the database.
cmlenz
parents: 236
diff changeset
671 "orderno) VALUES (%s,%s,%s,%s)",
a22ec8fce6c9 Store the reason(s) for build step failure in the database.
cmlenz
parents: 236
diff changeset
672 [(self.build, self.name, message, idx)
a22ec8fce6c9 Store the reason(s) for build step failure in the database.
cmlenz
parents: 236
diff changeset
673 for idx, message in enumerate(self.errors)])
a22ec8fce6c9 Store the reason(s) for build step failure in the database.
cmlenz
parents: 236
diff changeset
674
80
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
675 if handle_ta:
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
676 db.commit()
245
a22ec8fce6c9 Store the reason(s) for build step failure in the database.
cmlenz
parents: 236
diff changeset
677 self._exists = True
80
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
678
96
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
679 def fetch(cls, env, build, name, db=None):
157
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
680 """Retrieve an existing build from the database by build ID and step
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
681 name."""
96
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
682 if not db:
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
683 db = env.get_db_cnx()
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
684
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
685 cursor = db.cursor()
112
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
686 cursor.execute("SELECT description,status,started,stopped "
96
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
687 "FROM bitten_step WHERE build=%s AND name=%s",
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
688 (build, name))
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
689 row = cursor.fetchone()
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
690 if not row:
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
691 return None
245
a22ec8fce6c9 Store the reason(s) for build step failure in the database.
cmlenz
parents: 236
diff changeset
692 step = BuildStep(env, build, name, row[0] or '', row[1],
a22ec8fce6c9 Store the reason(s) for build step failure in the database.
cmlenz
parents: 236
diff changeset
693 row[2] and int(row[2]), row[3] and int(row[3]))
a22ec8fce6c9 Store the reason(s) for build step failure in the database.
cmlenz
parents: 236
diff changeset
694 step._exists = True
96
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
695
245
a22ec8fce6c9 Store the reason(s) for build step failure in the database.
cmlenz
parents: 236
diff changeset
696 cursor.execute("SELECT message FROM bitten_error WHERE build=%s "
a22ec8fce6c9 Store the reason(s) for build step failure in the database.
cmlenz
parents: 236
diff changeset
697 "AND step=%s ORDER BY orderno", (build, name))
a22ec8fce6c9 Store the reason(s) for build step failure in the database.
cmlenz
parents: 236
diff changeset
698 for row in cursor:
a22ec8fce6c9 Store the reason(s) for build step failure in the database.
cmlenz
parents: 236
diff changeset
699 step.errors.append(row[0] or '')
a22ec8fce6c9 Store the reason(s) for build step failure in the database.
cmlenz
parents: 236
diff changeset
700 return step
a22ec8fce6c9 Store the reason(s) for build step failure in the database.
cmlenz
parents: 236
diff changeset
701
96
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
702 fetch = classmethod(fetch)
c8c36f34ff5a Change model class pattern:
cmlenz
parents: 94
diff changeset
703
250
0271a2b1fc23 Improvements to the web interface:
cmlenz
parents: 246
diff changeset
704 def select(cls, env, build=None, name=None, status=None, db=None):
157
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
705 """Retrieve existing build steps from the database that match the
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
706 specified criteria.
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
707 """
80
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
708 if not db:
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
709 db = env.get_db_cnx()
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
710
763
de466e590545 Port of [638], [639], [640] to 0.6.x
wbell
parents: 757
diff changeset
711 assert status in (None, BuildStep.SUCCESS, BuildStep.IN_PROGRESS, BuildStep.FAILURE)
250
0271a2b1fc23 Improvements to the web interface:
cmlenz
parents: 246
diff changeset
712
80
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
713 where_clauses = []
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
714 if build is not None:
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
715 where_clauses.append(("build=%s", build))
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
716 if name is not None:
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
717 where_clauses.append(("name=%s", name))
250
0271a2b1fc23 Improvements to the web interface:
cmlenz
parents: 246
diff changeset
718 if status is not None:
0271a2b1fc23 Improvements to the web interface:
cmlenz
parents: 246
diff changeset
719 where_clauses.append(("status=%s", status))
80
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
720 if where_clauses:
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
721 where = "WHERE " + " AND ".join([wc[0] for wc in where_clauses])
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
722 else:
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
723 where = ""
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
724
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
725 cursor = db.cursor()
763
de466e590545 Port of [638], [639], [640] to 0.6.x
wbell
parents: 757
diff changeset
726 cursor.execute("SELECT build,name FROM bitten_step %s ORDER BY started"
80
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
727 % where, [wc[1] for wc in where_clauses])
245
a22ec8fce6c9 Store the reason(s) for build step failure in the database.
cmlenz
parents: 236
diff changeset
728 for build, name in cursor:
a22ec8fce6c9 Store the reason(s) for build step failure in the database.
cmlenz
parents: 236
diff changeset
729 yield BuildStep.fetch(env, build, name, db=db)
a22ec8fce6c9 Store the reason(s) for build step failure in the database.
cmlenz
parents: 236
diff changeset
730
112
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
731 select = classmethod(select)
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
732
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
733
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
734 class BuildLog(object):
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
735 """Represents a build log."""
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
736
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
737 _schema = [
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
738 Table('bitten_log', key='id')[
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
739 Column('id', auto_increment=True), Column('build', type='int'),
203
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
740 Column('step'), Column('generator'), Column('orderno', type='int'),
516
2f3b7c17d3c3 Switch to storing log messages in files rather than in database rows:
dfraser
parents: 450
diff changeset
741 Column('filename'),
203
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
742 Index(['build', 'step'])
112
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
743 ],
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
744 ]
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
745
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
746 # Message levels
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
747 DEBUG = 'D'
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
748 INFO = 'I'
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
749 WARNING = 'W'
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
750 ERROR = 'E'
516
2f3b7c17d3c3 Switch to storing log messages in files rather than in database rows:
dfraser
parents: 450
diff changeset
751 UNKNOWN = ''
736
dc51831e6120 0.6dev: Merged [805,813] from trunk.
hodgestar
parents: 650
diff changeset
752 LEVELS_SUFFIX = '.levels'
112
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
753
203
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
754 def __init__(self, env, build=None, step=None, generator=None,
516
2f3b7c17d3c3 Switch to storing log messages in files rather than in database rows:
dfraser
parents: 450
diff changeset
755 orderno=None, filename=None):
157
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
756 """Initialize a new build log with the specified attributes.
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
757
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
758 To actually create this build log in the database, the `insert` method
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
759 needs to be called.
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
760 """
112
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
761 self.env = env
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
762 self.id = None
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
763 self.build = build
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
764 self.step = step
203
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
765 self.generator = generator or ''
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
766 self.orderno = orderno and int(orderno) or 0
516
2f3b7c17d3c3 Switch to storing log messages in files rather than in database rows:
dfraser
parents: 450
diff changeset
767 self.filename = filename or None
112
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
768 self.messages = []
516
2f3b7c17d3c3 Switch to storing log messages in files rather than in database rows:
dfraser
parents: 450
diff changeset
769 self.logs_dir = env.config.get('bitten', 'logs_dir', 'log/bitten')
2f3b7c17d3c3 Switch to storing log messages in files rather than in database rows:
dfraser
parents: 450
diff changeset
770 if not os.path.isabs(self.logs_dir):
2f3b7c17d3c3 Switch to storing log messages in files rather than in database rows:
dfraser
parents: 450
diff changeset
771 self.logs_dir = os.path.join(env.path, self.logs_dir)
527
ab4942089190 Create the bitten logs directory if it doesn't exist. See #329
dfraser
parents: 521
diff changeset
772 if not os.path.exists(self.logs_dir):
529
ed37b6a02897 Automatically create the log dir if it doesn't exist, not just the leaf bitten dir.
wbell
parents: 527
diff changeset
773 os.makedirs(self.logs_dir)
112
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
774
316
87c9b1e8f086 More docstring improvements.
cmlenz
parents: 311
diff changeset
775 exists = property(fget=lambda self: self.id is not None,
87c9b1e8f086 More docstring improvements.
cmlenz
parents: 311
diff changeset
776 doc='Whether this build log exists in the database')
112
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
777
516
2f3b7c17d3c3 Switch to storing log messages in files rather than in database rows:
dfraser
parents: 450
diff changeset
778 def get_log_file(self, filename):
2f3b7c17d3c3 Switch to storing log messages in files rather than in database rows:
dfraser
parents: 450
diff changeset
779 """Returns the full path to the log file"""
2f3b7c17d3c3 Switch to storing log messages in files rather than in database rows:
dfraser
parents: 450
diff changeset
780 if filename != os.path.basename(filename):
2f3b7c17d3c3 Switch to storing log messages in files rather than in database rows:
dfraser
parents: 450
diff changeset
781 raise ValueError("Filename may not contain path: %s" % (filename,))
2f3b7c17d3c3 Switch to storing log messages in files rather than in database rows:
dfraser
parents: 450
diff changeset
782 return os.path.join(self.logs_dir, filename)
2f3b7c17d3c3 Switch to storing log messages in files rather than in database rows:
dfraser
parents: 450
diff changeset
783
112
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
784 def delete(self, db=None):
157
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
785 """Remove the build log from the database."""
112
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
786 assert self.exists, 'Cannot delete a non-existing build log'
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
787 if not db:
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
788 db = self.env.get_db_cnx()
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
789 handle_ta = True
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
790 else:
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
791 handle_ta = False
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
792
640
34776258924e 0.6dev: Fixing proper removal of log+levels files in `BuildLog.delete()`. Added test to verify. Closes #424.
osimons
parents: 629
diff changeset
793 if self.filename:
34776258924e 0.6dev: Fixing proper removal of log+levels files in `BuildLog.delete()`. Added test to verify. Closes #424.
osimons
parents: 629
diff changeset
794 log_file = self.get_log_file(self.filename)
520
a87ff6fc96b9 Handle removing log files only if present, and report error if could not remove in log rather than aborting operation
dfraser
parents: 519
diff changeset
795 if os.path.exists(log_file):
a87ff6fc96b9 Handle removing log files only if present, and report error if could not remove in log rather than aborting operation
dfraser
parents: 519
diff changeset
796 try:
640
34776258924e 0.6dev: Fixing proper removal of log+levels files in `BuildLog.delete()`. Added test to verify. Closes #424.
osimons
parents: 629
diff changeset
797 self.env.log.debug("Deleting log file: %s" % log_file)
520
a87ff6fc96b9 Handle removing log files only if present, and report error if could not remove in log rather than aborting operation
dfraser
parents: 519
diff changeset
798 os.remove(log_file)
a87ff6fc96b9 Handle removing log files only if present, and report error if could not remove in log rather than aborting operation
dfraser
parents: 519
diff changeset
799 except Exception, e:
a87ff6fc96b9 Handle removing log files only if present, and report error if could not remove in log rather than aborting operation
dfraser
parents: 519
diff changeset
800 self.env.log.warning("Error removing log file %s: %s" % (log_file, e))
736
dc51831e6120 0.6dev: Merged [805,813] from trunk.
hodgestar
parents: 650
diff changeset
801 level_file = log_file + self.LEVELS_SUFFIX
640
34776258924e 0.6dev: Fixing proper removal of log+levels files in `BuildLog.delete()`. Added test to verify. Closes #424.
osimons
parents: 629
diff changeset
802 if os.path.exists(level_file):
520
a87ff6fc96b9 Handle removing log files only if present, and report error if could not remove in log rather than aborting operation
dfraser
parents: 519
diff changeset
803 try:
640
34776258924e 0.6dev: Fixing proper removal of log+levels files in `BuildLog.delete()`. Added test to verify. Closes #424.
osimons
parents: 629
diff changeset
804 self.env.log.debug("Deleting level file: %s" % level_file)
520
a87ff6fc96b9 Handle removing log files only if present, and report error if could not remove in log rather than aborting operation
dfraser
parents: 519
diff changeset
805 os.remove(level_file)
a87ff6fc96b9 Handle removing log files only if present, and report error if could not remove in log rather than aborting operation
dfraser
parents: 519
diff changeset
806 except Exception, e:
640
34776258924e 0.6dev: Fixing proper removal of log+levels files in `BuildLog.delete()`. Added test to verify. Closes #424.
osimons
parents: 629
diff changeset
807 self.env.log.warning("Error removing level file %s: %s" \
34776258924e 0.6dev: Fixing proper removal of log+levels files in `BuildLog.delete()`. Added test to verify. Closes #424.
osimons
parents: 629
diff changeset
808 % (level_file, e))
34776258924e 0.6dev: Fixing proper removal of log+levels files in `BuildLog.delete()`. Added test to verify. Closes #424.
osimons
parents: 629
diff changeset
809
34776258924e 0.6dev: Fixing proper removal of log+levels files in `BuildLog.delete()`. Added test to verify. Closes #424.
osimons
parents: 629
diff changeset
810 cursor = db.cursor()
34776258924e 0.6dev: Fixing proper removal of log+levels files in `BuildLog.delete()`. Added test to verify. Closes #424.
osimons
parents: 629
diff changeset
811 cursor.execute("DELETE FROM bitten_log WHERE id=%s", (self.id,))
112
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
812
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
813 if handle_ta:
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
814 db.commit()
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
815 self.id = None
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
816
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
817 def insert(self, db=None):
157
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
818 """Insert a new build log into the database."""
112
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
819 if not db:
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
820 db = self.env.get_db_cnx()
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
821 handle_ta = True
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
822 else:
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
823 handle_ta = False
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
824
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
825 assert self.build and self.step
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
826
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
827 cursor = db.cursor()
203
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
828 cursor.execute("INSERT INTO bitten_log (build,step,generator,orderno) "
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
829 "VALUES (%s,%s,%s,%s)", (self.build, self.step,
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
830 self.generator, self.orderno))
112
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
831 id = db.get_last_id(cursor, 'bitten_log')
516
2f3b7c17d3c3 Switch to storing log messages in files rather than in database rows:
dfraser
parents: 450
diff changeset
832 log_file = "%s.log" % (id,)
2f3b7c17d3c3 Switch to storing log messages in files rather than in database rows:
dfraser
parents: 450
diff changeset
833 cursor.execute("UPDATE bitten_log SET filename=%s WHERE id=%s", (log_file, id))
344
90c79fabe6f1 Fix bug in the model classes where `db.executemany()` was being called with an empty list. This could happen for an empty build log, for example.
cmlenz
parents: 316
diff changeset
834 if self.messages:
516
2f3b7c17d3c3 Switch to storing log messages in files rather than in database rows:
dfraser
parents: 450
diff changeset
835 log_file_name = self.get_log_file(log_file)
736
dc51831e6120 0.6dev: Merged [805,813] from trunk.
hodgestar
parents: 650
diff changeset
836 level_file_name = log_file_name + self.LEVELS_SUFFIX
521
b661ea254972 Ensure log files are stored and read in binary, not text format (otherwise Unicode gets confused):
dfraser
parents: 520
diff changeset
837 codecs.open(log_file_name, "wb", "UTF-8").writelines([to_unicode(msg[1]+"\n") for msg in self.messages])
b661ea254972 Ensure log files are stored and read in binary, not text format (otherwise Unicode gets confused):
dfraser
parents: 520
diff changeset
838 codecs.open(level_file_name, "wb", "UTF-8").writelines([to_unicode(msg[0]+"\n") for msg in self.messages])
112
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
839
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
840 if handle_ta:
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
841 db.commit()
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
842 self.id = id
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
843
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
844 def fetch(cls, env, id, db=None):
157
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
845 """Retrieve an existing build from the database by ID."""
112
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
846 if not db:
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
847 db = env.get_db_cnx()
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
848
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
849 cursor = db.cursor()
516
2f3b7c17d3c3 Switch to storing log messages in files rather than in database rows:
dfraser
parents: 450
diff changeset
850 cursor.execute("SELECT build,step,generator,orderno,filename FROM bitten_log "
112
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
851 "WHERE id=%s", (id,))
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
852 row = cursor.fetchone()
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
853 if not row:
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
854 return None
516
2f3b7c17d3c3 Switch to storing log messages in files rather than in database rows:
dfraser
parents: 450
diff changeset
855 log = BuildLog(env, int(row[0]), row[1], row[2], row[3], row[4])
112
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
856 log.id = id
516
2f3b7c17d3c3 Switch to storing log messages in files rather than in database rows:
dfraser
parents: 450
diff changeset
857 if log.filename:
2f3b7c17d3c3 Switch to storing log messages in files rather than in database rows:
dfraser
parents: 450
diff changeset
858 log_filename = log.get_log_file(log.filename)
2f3b7c17d3c3 Switch to storing log messages in files rather than in database rows:
dfraser
parents: 450
diff changeset
859 if os.path.exists(log_filename):
521
b661ea254972 Ensure log files are stored and read in binary, not text format (otherwise Unicode gets confused):
dfraser
parents: 520
diff changeset
860 log_lines = codecs.open(log_filename, "rb", "UTF-8").readlines()
516
2f3b7c17d3c3 Switch to storing log messages in files rather than in database rows:
dfraser
parents: 450
diff changeset
861 else:
2f3b7c17d3c3 Switch to storing log messages in files rather than in database rows:
dfraser
parents: 450
diff changeset
862 log_lines = []
736
dc51831e6120 0.6dev: Merged [805,813] from trunk.
hodgestar
parents: 650
diff changeset
863 level_filename = log.get_log_file(log.filename + cls.LEVELS_SUFFIX)
516
2f3b7c17d3c3 Switch to storing log messages in files rather than in database rows:
dfraser
parents: 450
diff changeset
864 if os.path.exists(level_filename):
530
81e43e3770e6 Fixing some small issues with level retrieval with the new file based log implementation.
wbell
parents: 529
diff changeset
865 log_levels = dict(enumerate(codecs.open(level_filename, "rb", "UTF-8").readlines()))
516
2f3b7c17d3c3 Switch to storing log messages in files rather than in database rows:
dfraser
parents: 450
diff changeset
866 else:
2f3b7c17d3c3 Switch to storing log messages in files rather than in database rows:
dfraser
parents: 450
diff changeset
867 log_levels = {}
530
81e43e3770e6 Fixing some small issues with level retrieval with the new file based log implementation.
wbell
parents: 529
diff changeset
868 log.messages = [(log_levels.get(line_num, BuildLog.UNKNOWN).rstrip("\n"), line.rstrip("\n")) for line_num, line in enumerate(log_lines)]
516
2f3b7c17d3c3 Switch to storing log messages in files rather than in database rows:
dfraser
parents: 450
diff changeset
869 else:
2f3b7c17d3c3 Switch to storing log messages in files rather than in database rows:
dfraser
parents: 450
diff changeset
870 log.messages = []
112
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
871
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
872 return log
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
873
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
874 fetch = classmethod(fetch)
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
875
203
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
876 def select(cls, env, build=None, step=None, generator=None, db=None):
157
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
877 """Retrieve existing build logs from the database that match the
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
878 specified criteria.
2efdc69e63c3 Some style/documentation improvements to make Pylint happier.
cmlenz
parents: 147
diff changeset
879 """
112
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
880 if not db:
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
881 db = env.get_db_cnx()
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
882
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
883 where_clauses = []
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
884 if build is not None:
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
885 where_clauses.append(("build=%s", build))
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
886 if step is not None:
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
887 where_clauses.append(("step=%s", step))
203
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
888 if generator is not None:
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
889 where_clauses.append(("generator=%s", generator))
112
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
890 if where_clauses:
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
891 where = "WHERE " + " AND ".join([wc[0] for wc in where_clauses])
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
892 else:
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
893 where = ""
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
894
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
895 cursor = db.cursor()
203
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
896 cursor.execute("SELECT id FROM bitten_log %s ORDER BY orderno"
112
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
897 % where, [wc[1] for wc in where_clauses])
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
898 for (id, ) in cursor:
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
899 yield BuildLog.fetch(env, id, db=db)
a38eabd4b6e1 * Store build logs in a structured way, for example to highlight messages on the error stream.
cmlenz
parents: 101
diff changeset
900
80
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
901 select = classmethod(select)
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
902
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
903
203
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
904 class Report(object):
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
905 """Represents a generated report."""
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
906
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
907 _schema = [
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
908 Table('bitten_report', key='id')[
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
909 Column('id', auto_increment=True), Column('build', type='int'),
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
910 Column('step'), Column('category'), Column('generator'),
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
911 Index(['build', 'step', 'category'])
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
912 ],
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
913 Table('bitten_report_item', key=('report', 'item', 'name'))[
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
914 Column('report', type='int'), Column('item', type='int'),
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
915 Column('name'), Column('value')
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
916 ]
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
917 ]
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
918
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
919 def __init__(self, env, build=None, step=None, category=None,
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
920 generator=None):
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
921 """Initialize a new report with the specified attributes.
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
922
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
923 To actually create this build log in the database, the `insert` method
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
924 needs to be called.
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
925 """
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
926 self.env = env
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
927 self.id = None
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
928 self.build = build
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
929 self.step = step
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
930 self.category = category
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
931 self.generator = generator or ''
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
932 self.items = []
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
933
316
87c9b1e8f086 More docstring improvements.
cmlenz
parents: 311
diff changeset
934 exists = property(fget=lambda self: self.id is not None,
87c9b1e8f086 More docstring improvements.
cmlenz
parents: 311
diff changeset
935 doc='Whether this report exists in the database')
203
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
936
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
937 def delete(self, db=None):
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
938 """Remove the report from the database."""
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
939 assert self.exists, 'Cannot delete a non-existing report'
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
940 if not db:
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
941 db = self.env.get_db_cnx()
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
942 handle_ta = True
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
943 else:
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
944 handle_ta = False
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
945
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
946 cursor = db.cursor()
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
947 cursor.execute("DELETE FROM bitten_report_item WHERE report=%s",
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
948 (self.id,))
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
949 cursor.execute("DELETE FROM bitten_report WHERE id=%s", (self.id,))
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
950
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
951 if handle_ta:
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
952 db.commit()
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
953 self.id = None
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
954
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
955 def insert(self, db=None):
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
956 """Insert a new build log into the database."""
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
957 if not db:
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
958 db = self.env.get_db_cnx()
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
959 handle_ta = True
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
960 else:
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
961 handle_ta = False
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
962
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
963 assert self.build and self.step and self.category
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
964
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
965 # Enforce uniqueness of build-step-category.
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
966 # This should be done by the database, but the DB schema helpers in Trac
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
967 # currently don't support UNIQUE() constraints
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
968 assert not list(Report.select(self.env, build=self.build,
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
969 step=self.step, category=self.category,
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
970 db=db)), 'Report already exists'
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
971
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
972 cursor = db.cursor()
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
973 cursor.execute("INSERT INTO bitten_report "
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
974 "(build,step,category,generator) VALUES (%s,%s,%s,%s)",
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
975 (self.build, self.step, self.category, self.generator))
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
976 id = db.get_last_id(cursor, 'bitten_report')
344
90c79fabe6f1 Fix bug in the model classes where `db.executemany()` was being called with an empty list. This could happen for an empty build log, for example.
cmlenz
parents: 316
diff changeset
977 for idx, item in enumerate([item for item in self.items if item]):
203
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
978 cursor.executemany("INSERT INTO bitten_report_item "
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
979 "(report,item,name,value) VALUES (%s,%s,%s,%s)",
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
980 [(id, idx, key, value) for key, value
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
981 in item.items()])
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
982
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
983 if handle_ta:
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
984 db.commit()
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
985 self.id = id
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
986
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
987 def fetch(cls, env, id, db=None):
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
988 """Retrieve an existing build from the database by ID."""
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
989 if not db:
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
990 db = env.get_db_cnx()
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
991
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
992 cursor = db.cursor()
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
993 cursor.execute("SELECT build,step,category,generator "
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
994 "FROM bitten_report WHERE id=%s", (id,))
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
995 row = cursor.fetchone()
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
996 if not row:
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
997 return None
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
998 report = Report(env, int(row[0]), row[1], row[2] or '', row[3] or '')
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
999 report.id = id
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
1000
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
1001 cursor.execute("SELECT item,name,value FROM bitten_report_item "
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
1002 "WHERE report=%s ORDER BY item", (id,))
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
1003 items = {}
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
1004 for item, name, value in cursor:
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
1005 items.setdefault(item, {})[name] = value
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
1006 report.items = items.values()
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
1007
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
1008 return report
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
1009
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
1010 fetch = classmethod(fetch)
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
1011
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
1012 def select(cls, env, config=None, build=None, step=None, category=None,
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
1013 db=None):
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
1014 """Retrieve existing reports from the database that match the specified
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
1015 criteria.
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
1016 """
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
1017 where_clauses = []
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
1018 joins = []
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
1019 if config is not None:
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
1020 where_clauses.append(("config=%s", config))
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
1021 joins.append("INNER JOIN bitten_build ON (bitten_build.id=build)")
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
1022 if build is not None:
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
1023 where_clauses.append(("build=%s", build))
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
1024 if step is not None:
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
1025 where_clauses.append(("step=%s", step))
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
1026 if category is not None:
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
1027 where_clauses.append(("category=%s", category))
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
1028
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
1029 if where_clauses:
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
1030 where = "WHERE " + " AND ".join([wc[0] for wc in where_clauses])
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
1031 else:
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
1032 where = ""
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
1033
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
1034 if not db:
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
1035 db = env.get_db_cnx()
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
1036 cursor = db.cursor()
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
1037 cursor.execute("SELECT bitten_report.id FROM bitten_report %s %s "
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
1038 "ORDER BY category" % (' '.join(joins), where),
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
1039 [wc[1] for wc in where_clauses])
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
1040 for (id, ) in cursor:
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
1041 yield Report.fetch(env, id, db=db)
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
1042
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
1043 select = classmethod(select)
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
1044
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
1045
80
dc1c7fc9b915 Record the output of build steps in the database. See #12. Still need to get better granularity in transmitting the log output from slave to master before #12 can be closed.
cmlenz
parents: 76
diff changeset
1046 schema = BuildConfig._schema + TargetPlatform._schema + Build._schema + \
203
e6ddca1e5712 Huge refactoring to remove dependency on BDB XML. Report data is now stored in the Trac database (SQLite/PostgreSQL).
cmlenz
parents: 195
diff changeset
1047 BuildStep._schema + BuildLog._schema + Report._schema
763
de466e590545 Port of [638], [639], [640] to 0.6.x
wbell
parents: 757
diff changeset
1048 schema_version = 12
Copyright (C) 2012-2017 Edgewall Software