changeset 35:67631e1d4d45

Some stubbed out code for the Bitten/Trac-integration. This creates a {{{bitten_build}}} table on database upgrade after the plugin is enabled.
author cmlenz
date Wed, 22 Jun 2005 13:32:46 +0000
parents 6da9468a6879
children 47433f32e1fc
files bitten/model/__init__.py bitten/model/build.py bitten/trac_ext/__init__.py bitten/trac_ext/main.py bitten/trac_ext/web_ui.py bitten/web_ui.py
diffstat 6 files changed, 237 insertions(+), 62 deletions(-) [+]
line wrap: on
line diff
new file mode 100644
--- /dev/null
+++ b/bitten/model/__init__.py
@@ -0,0 +1,23 @@
+# -*- coding: iso8859-1 -*-
+#
+# Copyright (C) 2005 Christopher Lenz <cmlenz@gmx.de>
+#
+# 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 <cmlenz@gmx.de>
+
+from bitten.model.build import *
+
+schema_version = 1
new file mode 100644
--- /dev/null
+++ b/bitten/model/build.py
@@ -0,0 +1,75 @@
+# -*- coding: iso8859-1 -*-
+#
+# Copyright (C) 2005 Christopher Lenz <cmlenz@gmx.de>
+#
+# 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 <cmlenz@gmx.de>
+
+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))
new file mode 100644
--- /dev/null
+++ b/bitten/trac_ext/__init__.py
@@ -0,0 +1,19 @@
+# -*- coding: iso8859-1 -*-
+#
+# Copyright (C) 2005 Christopher Lenz <cmlenz@gmx.de>
+#
+# 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 <cmlenz@gmx.de>
new file mode 100644
--- /dev/null
+++ b/bitten/trac_ext/main.py
@@ -0,0 +1,59 @@
+# -*- coding: iso8859-1 -*-
+#
+# Copyright (C) 2005 Christopher Lenz <cmlenz@gmx.de>
+#
+# 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 <cmlenz@gmx.de>
+
+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()
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 <cmlenz@gmx.de>
+#
+# 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 <cmlenz@gmx.de>
+
+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 = """
+<?cs include:"header.cs" ?>
+ <div id="ctxtnav" class="nav"></div>
+ <div id="content">
+  <h1>Build Status</h1>
+  <p>Not yet implemented</p>
+ </div>
+<?cs include:"footer.cs" ?>
+"""
+
+    # INavigationContributor methods
+
+    def get_active_navigation_item(self, req):
+        return 'build'
+
+    def get_navigation_items(self, req):
+        yield 'mainnav', 'build', '<a href="%s">Build Status</a>' \
+                                  % 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
deleted file mode 100644
--- a/bitten/web_ui.py
+++ /dev/null
@@ -1,62 +0,0 @@
-# -*- coding: iso8859-1 -*-
-#
-# Copyright (C) 2005 Christopher Lenz <cmlenz@gmx.de>
-#
-# 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 <cmlenz@gmx.de>
-
-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 = """
-<?cs include:"header.cs" ?>
-<div id="main">
- <div id="ctxtnav" class="nav"></div>
-  <h1>Build Status</h1>
- <div id="content"></div>
-</div>
-<?cs include:"footer.cs" ?>
-"""
-
-    # INavigationContributor methods
-
-    def get_active_navigation_item(self, req):
-        return 'build'
-
-    def get_navigation_items(self, req):
-        yield 'mainnav', 'build', '<a href="%s">Builds</a>' \
-                                  % 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
Copyright (C) 2012-2017 Edgewall Software