| [1694] | 1 | # -*- coding: utf-8 -*- |
|---|
| 2 | # |
|---|
| [1908] | 3 | # Copyright (C) 2006-2007 Emmanuel Blot <emmanuel.blot@free.fr> |
|---|
| [1694] | 4 | # All rights reserved. |
|---|
| 5 | # |
|---|
| 6 | # This software is licensed as described in the file COPYING, which |
|---|
| 7 | # you should have received as part of this distribution. The terms |
|---|
| 8 | # are also available at http://trac.edgewall.com/license.html. |
|---|
| 9 | # |
|---|
| 10 | # This software consists of voluntary contributions made by many |
|---|
| 11 | # individuals. For the exact contribution history, see the revision |
|---|
| 12 | # history and logs, available at http://projects.edgewall.com/trac/. |
|---|
| 13 | # |
|---|
| 14 | |
|---|
| 15 | from trac.config import ExtensionOption |
|---|
| 16 | from trac.core import * |
|---|
| 17 | |
|---|
| [4024] | 18 | __all__ = ['IRevtreeEnhancer', 'IRevtreeOptimizer', 'RevtreeEnhancer', |
|---|
| [2111] | 19 | 'EmptyRangeError', 'BranchPathError', 'RevtreeSystem'] |
|---|
| [1694] | 20 | |
|---|
| [2111] | 21 | |
|---|
| [4024] | 22 | class RevtreeEnhancer(object): |
|---|
| 23 | """Enhancer interface""" |
|---|
| 24 | |
|---|
| 25 | def build(self): |
|---|
| 26 | """Build the widgets""" |
|---|
| 27 | raise NotImplementedError |
|---|
| 28 | |
|---|
| 29 | def render(self, level): |
|---|
| 30 | """Render the widgets""" |
|---|
| 31 | raise NotImplementedError |
|---|
| 32 | |
|---|
| 33 | |
|---|
| [1694] | 34 | class IRevtreeEnhancer(Interface): |
|---|
| 35 | """Provide graphical enhancements to a revision tree""" |
|---|
| [4024] | 36 | |
|---|
| 37 | # Rendering Z levels |
|---|
| 38 | (ZBACK, ZMID, ZFORE) = ZLEVELS = range(3) |
|---|
| [1694] | 39 | |
|---|
| 40 | def create(env, req, repos, svgrevtree): |
|---|
| [4024] | 41 | """Create the internal data from the repository |
|---|
| 42 | Return a RevtreeEnhancer instance |
|---|
| 43 | """ |
|---|
| [1694] | 44 | |
|---|
| 45 | |
|---|
| 46 | class IRevtreeOptimizer(Interface): |
|---|
| 47 | """Provide optimized location for revision tree elements""" |
|---|
| 48 | |
|---|
| 49 | def optimize_branches(repos, branches): |
|---|
| 50 | """Sort the branch elements. |
|---|
| 51 | |
|---|
| 52 | Return an placement ordered list, from the left-most to the right-most |
|---|
| 53 | branch. |
|---|
| 54 | """ |
|---|
| 55 | |
|---|
| 56 | |
|---|
| 57 | class EmptyRangeError(TracError): |
|---|
| 58 | """Defines a RevTree error (no changeset in the selected range)""" |
|---|
| 59 | def __init__(self, msg=None): |
|---|
| 60 | TracError.__init__(self, "%sNo changeset" \ |
|---|
| 61 | % (msg and '%s: ' % msg or '')) |
|---|
| [2111] | 62 | |
|---|
| [1694] | 63 | |
|---|
| [2111] | 64 | class BranchPathError(TracError): |
|---|
| 65 | """Defines a RevTree error (incoherent paths in a branch)""" |
|---|
| 66 | def __init__(self, msg=None): |
|---|
| 67 | TracError.__init__(self, "Incoherent path %s" % (msg or '')) |
|---|
| [1694] | 68 | |
|---|
| [2111] | 69 | |
|---|
| [1694] | 70 | class RevtreeSystem(Component): |
|---|
| [2147] | 71 | """Revision tree constructor""" |
|---|
| [1694] | 72 | |
|---|
| 73 | enhancers = ExtensionPoint(IRevtreeEnhancer) |
|---|
| 74 | optimizer = ExtensionOption('revtree', 'optimizer', IRevtreeOptimizer, |
|---|
| 75 | 'DefaultRevtreeOptimizer', |
|---|
| 76 | """Name of the component implementing `IRevtreeOptimizer`, which is |
|---|
| 77 | used for optimizing revtree element placements.""") |
|---|
| 78 | |
|---|
| [2147] | 79 | def get_revtree(self, repos, req): |
|---|
| [2841] | 80 | # ideally, the repository type should be requested from the repos |
|---|
| 81 | # instance; however it is usually hidden behind the repository cache |
|---|
| 82 | # that does not report the actual repository backend |
|---|
| 83 | if self.config.get('trac', 'repository_type') != 'svn': |
|---|
| 84 | raise TracError, "Revtree only supports Subversion repositories" |
|---|
| [1694] | 85 | self.env.log.debug("Enhancers: %s" % self.enhancers) |
|---|
| 86 | from revtree.svgview import SvgRevtree |
|---|
| [2299] | 87 | return SvgRevtree(self.env, repos, req.href(), |
|---|
| [1694] | 88 | self.enhancers, self.optimizer) |
|---|