bloodhound-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j...@apache.org
Subject svn commit: r1458692 - in /incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct: hooks.py util.py versioncontrol.py
Date Wed, 20 Mar 2013 09:00:26 GMT
Author: jure
Date: Wed Mar 20 09:00:25 2013
New Revision: 1458692

URL: http://svn.apache.org/r1458692
Log:
Productize repositories, monkey patch trac.versioncontrol.api.DbRepositoryProvider and trac.versioncontrol.api.RepositoryManager,
towards #470


Added:
    incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/versioncontrol.py
Modified:
    incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/hooks.py
    incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/util.py

Modified: incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/hooks.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/hooks.py?rev=1458692&r1=1458691&r2=1458692&view=diff
==============================================================================
--- incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/hooks.py
(original)
+++ incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/hooks.py
Wed Mar 20 09:00:25 2013
@@ -15,9 +15,11 @@
 #  specific language governing permissions and limitations
 #  under the License.
 
-# these two imports monkey patch required classes
+# these import monkey patch classes required to enable
+# multi product support
 import multiproduct.env
 import multiproduct.dbcursor
+import multiproduct.versioncontrol
 
 import re
 

Modified: incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/util.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/util.py?rev=1458692&r1=1458691&r2=1458692&view=diff
==============================================================================
--- incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/util.py
(original)
+++ incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/util.py
Wed Mar 20 09:00:25 2013
@@ -22,6 +22,38 @@ from genshi.builder import tag
 
 from trac.util.text import unquote_label
 from trac.wiki.formatter import LinkFormatter
+from trac.core import Component, ComponentMeta
+
+#----------------------------
+# Component replacement base
+#----------------------------
+
+class ReplacementComponentMeta(ComponentMeta):
+    """Component replacement meta class"""
+    def __new__(mcs, name, bases, d):
+        base_class = bases[0]
+        if base_class != Component:
+            # undo what has been done by ComponentMeta.__new___ for the
+            # replacement component base class
+
+            # remove implemented interfaces from registry for the base class
+            for itf in base_class._implements:
+                ComponentMeta._registry[itf] = filter(lambda c: c != base_class,
+                                                      ComponentMeta._registry[itf])
+
+            # remove base class from components list
+            ComponentMeta._components = filter(lambda c: c != base_class,
+                                               ComponentMeta._components)
+
+            base_class._implements = []
+            base_class.abstract = True
+
+        return ComponentMeta.__new__(mcs, name, bases, d)
+
+class ReplacementComponent(Component):
+    """Base class for components that replace existing trac
+    implementations"""
+    __metaclass__ = ReplacementComponentMeta
 
 #--------------------------
 # Custom wiki formatters

Added: incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/versioncontrol.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/versioncontrol.py?rev=1458692&view=auto
==============================================================================
--- incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/versioncontrol.py
(added)
+++ incubator/bloodhound/branches/bep_0003_multiproduct/bloodhound_multiproduct/multiproduct/versioncontrol.py
Wed Mar 20 09:00:25 2013
@@ -0,0 +1,80 @@
+#  Licensed to the Apache Software Foundation (ASF) under one
+#  or more contributor license agreements.  See the NOTICE file
+#  distributed with this work for additional information
+#  regarding copyright ownership.  The ASF licenses this file
+#  to you under the Apache License, Version 2.0 (the
+#  "License"); you may not use this file except in compliance
+#  with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing,
+#  software distributed under the License is distributed on an
+#  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+#  KIND, either express or implied.  See the License for the
+#  specific language governing permissions and limitations
+#  under the License.
+
+"""Bloodhound version control support"""
+
+import os.path
+
+from trac.util.concurrency import threading
+from trac.core import implements
+import trac.versioncontrol.api
+import trac.admin
+import trac.web.api
+import trac.resource
+from multiproduct.util import ReplacementComponent
+
+class DbRepositoryProvider(trac.versioncontrol.api.DbRepositoryProvider, ReplacementComponent):
+    """Inplace replacement for trac.versioncontrol.api.DbRepositoryProvider. Filters
+    repositories based on soft-links to products. Soft links are stored in 'product'
+    repository attribute, separated by comma."""
+
+    repository_attrs = trac.versioncontrol.api.DbRepositoryProvider.repository_attrs + tuple(['product'])
+
+    implements(trac.versioncontrol.api.IRepositoryProvider,
+               trac.admin.IAdminCommandProvider)
+
+    # IRepositoryProvider methods
+    def get_repositories(self):
+        """Retrieve list of repositories specified in the repository
+        table for current product environment
+        """
+        from multiproduct.env import ProductEnvironment
+        if isinstance(self.env, ProductEnvironment):
+            repos = {}
+            for id, name, value in self.env.db_direct_query(
+                "SELECT id, name, value FROM repository WHERE name IN (%s)"
+                % ",".join("'%s'" % each for each in self.repository_attrs)):
+                if value is not None:
+                    repos.setdefault(id, {})[name] = value
+            reponames = {}
+            for id, info in repos.iteritems():
+                if 'product' in info and \
+                   not self.env.product.prefix in info['product'].split(','):
+                    # skip repository if not soft linked from the current
+                    # product environment
+                    continue
+                if 'product' in info:
+                    del info['product']
+                if 'name' in info and ('dir' in info or 'alias' in info):
+                    info['id'] = id
+                    reponames[info['name']] = info
+            return reponames.iteritems()
+        else:
+            return super(DbRepositoryProvider, self).get_repositories()
+
+trac.versioncontrol.api.DbRepositoryProvider = DbRepositoryProvider
+
+class RepositoryManager(trac.versioncontrol.api.RepositoryManager, ReplacementComponent):
+
+    implements(trac.web.api.IRequestFilter,
+               trac.resource.IResourceManager,
+               trac.versioncontrol.api.IRepositoryProvider)
+
+    def __init__(self):
+        super(RepositoryManager, self).__init__()
+
+trac.versioncontrol.api.RepositoryManager = RepositoryManager



Mime
View raw message