# HG changeset patch # User cmlenz # Date 1119447166 0 # Node ID 67631e1d4d45c9f178ed629c22b93e0b18929c72 # Parent 6da9468a6879b3085cccd7bb0f007819ff37ab6a Some stubbed out code for the Bitten/Trac-integration. This creates a {{{bitten_build}}} table on database upgrade after the plugin is enabled. diff --git a/bitten/model/__init__.py b/bitten/model/__init__.py new file mode 100644 --- /dev/null +++ b/bitten/model/__init__.py @@ -0,0 +1,23 @@ +# -*- coding: iso8859-1 -*- +# +# Copyright (C) 2005 Christopher Lenz +# +# Bitten is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. +# +# Trac is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# Author: Christopher Lenz + +from bitten.model.build import * + +schema_version = 1 diff --git a/bitten/model/build.py b/bitten/model/build.py new file mode 100644 --- /dev/null +++ b/bitten/model/build.py @@ -0,0 +1,75 @@ +# -*- coding: iso8859-1 -*- +# +# Copyright (C) 2005 Christopher Lenz +# +# Bitten is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. +# +# Trac is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# Author: Christopher Lenz + +from trac.db_default import Table, Column + + +class Build(object): + """Representation of a build.""" + + _table = Table('bitten_build', key=('rev', 'path', 'slave'))[ + Column('rev'), Column('path'), Column('slave'), + Column('time', type='int'), Column('duration', type='int'), + Column('status', type='int') + ] + + FAILURE = 'failure' + IN_PROGRESS = 'in-progress' + SUCCESS = 'success' + + def __init__(self, env, rev=None, path=None, slave=None, db=None): + self.env = env + self.rev = self.path = self.slave = None + self.time = self.duration = self.status = None + if rev: + self._fetch(rev, path, slave, db) + + def _fetch(self, rev, path, slave, db=None): + if not db: + db = self.env.get_db_cnx() + + cursor = db.cursor() + cursor.execute("SELECT time,duration,status FROM bitten_build " + "WHERE rev=%s AND path=%s AND slave=%s", + (rev, path, slave)) + row = cursor.fetchone() + if not row: + raise Exception, "Build not found" + self.time = row[0] and int(row[0]) + self.duration = row[1] and int(row[1]) + if row[2] is not None: + self.status = row[2] and Build.SUCCESS or Build.FAILURE + else: + self.status = Build.FAILURE + + completed = property(fget=lambda self: self.status != Build.IN_PROGRESS) + successful = property(fget=lambda self: self.status == Build.SUCCESS) + + def insert(self, db=None): + if not db: + db = self.env.get_db_cnx() + handle_ta = True + else: + handle_ta = False + + cursor = db.cursor() + cursor.execute("INSERT INTO bitten_build VALUES (%s,%s,%s,%s,%s,%s)", + (self.rev, self.path, self.slave, self.time, + self.duration, self.status or Build.IN_PROGRESS)) diff --git a/bitten/trac_ext/__init__.py b/bitten/trac_ext/__init__.py new file mode 100644 --- /dev/null +++ b/bitten/trac_ext/__init__.py @@ -0,0 +1,19 @@ +# -*- coding: iso8859-1 -*- +# +# Copyright (C) 2005 Christopher Lenz +# +# Bitten is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. +# +# Trac is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# Author: Christopher Lenz diff --git a/bitten/trac_ext/main.py b/bitten/trac_ext/main.py new file mode 100644 --- /dev/null +++ b/bitten/trac_ext/main.py @@ -0,0 +1,59 @@ +# -*- coding: iso8859-1 -*- +# +# Copyright (C) 2005 Christopher Lenz +# +# Bitten is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. +# +# Trac is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# Author: Christopher Lenz + +import os.path + +from trac.core import * +from trac.env import IEnvironmentSetupParticipant +from bitten.model import Build, schema_version +from bitten.trac_ext import web_ui + +class BuildSystem(Component): + + implements(IEnvironmentSetupParticipant) + + # IEnvironmentSetupParticipant methods + + def environment_created(self): + # Create the required tables + db = self.env.get_db_cnx() + cursor = db.cursor() + for table in [Build._table]: + cursor.execute(db.to_sql(table)) + + tarballs_dir = os.path.join(self.env.path, 'tarballs') + + cursor.execute("INSERT INTO system (name,value) " + "VALUES ('bitten_version',%s)", (schema_version,)) + db.commit() + + def environment_needs_upgrade(self, db): + cursor = db.cursor() + cursor.execute("SELECT value FROM system WHERE name='bitten_version'") + row = cursor.fetchone() + if not row or int(row[0]) < schema_version: + return True + + def upgrade_environment(self, db): + cursor = db.cursor() + cursor.execute("SELECT value FROM system WHERE name='bitten_version'") + row = cursor.fetchone() + if not row: + self.environment_created() diff --git a/bitten/trac_ext/web_ui.py b/bitten/trac_ext/web_ui.py new file mode 100644 --- /dev/null +++ b/bitten/trac_ext/web_ui.py @@ -0,0 +1,61 @@ +# -*- coding: iso8859-1 -*- +# +# Copyright (C) 2005 Christopher Lenz +# +# Bitten is free software; you can redistribute it and/or +# modify it under the terms of the GNU General Public License as +# published by the Free Software Foundation; either version 2 of the +# License, or (at your option) any later version. +# +# Trac is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# +# Author: Christopher Lenz + +import re + +from trac.core import * +from trac.web.chrome import INavigationContributor +from trac.web.main import IRequestHandler + + +class BuildModule(Component): + + implements(INavigationContributor, IRequestHandler) + + build_cs = """ + + +
+

Build Status

+

Not yet implemented

+
+ +""" + + # INavigationContributor methods + + def get_active_navigation_item(self, req): + return 'build' + + def get_navigation_items(self, req): + yield 'mainnav', 'build', 'Build Status' \ + % self.env.href.build() + + # IRequestHandler methods + + def match_request(self, req): + match = re.match(r'/build(:?/(\w+))?', req.path_info) + if match: + if match.group(1): + req.args['id'] = match.group(1) + return True + + def process_request(self, req): + return req.hdf.parse(self.build_cs), None diff --git a/bitten/web_ui.py b/bitten/web_ui.py deleted file mode 100644 --- a/bitten/web_ui.py +++ /dev/null @@ -1,62 +0,0 @@ -# -*- coding: iso8859-1 -*- -# -# Copyright (C) 2005 Christopher Lenz -# -# Bitten is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License as -# published by the Free Software Foundation; either version 2 of the -# License, or (at your option) any later version. -# -# Trac is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -# General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -# -# Author: Christopher Lenz - -from __future__ import generators -import re - -from trac.core import * -from trac.web.chrome import INavigationContributor -from trac.web.main import AbstractView, IRequestHandler - - -class BuildModule(AbstractView): - - implements(INavigationContributor, IRequestHandler) - - build_cs = """ - -
- -

Build Status

-
-
- -""" - - # INavigationContributor methods - - def get_active_navigation_item(self, req): - return 'build' - - def get_navigation_items(self, req): - yield 'mainnav', 'build', 'Builds' \ - % self.env.href.build() - - # IRequestHandler methods - - def match_request(self, req): - match = re.match(r'/build(:?/(\w+))?', req.path_info) - if match: - if match.group(1): - req.args['id'] = match.group(1) - return True - - def process_request(self, req): - return req.hdf.parse(self.build_cs), None