/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
49 by Jelmer Vernooij
Merge in Dan Loda's gannotate plugin and put it in annotate/
1
# This program is free software; you can redistribute it and/or modify
2
# it under the terms of the GNU General Public License as published by
3
# the Free Software Foundation; either version 2 of the License, or
4
# (at your option) any later version.
5
6
# This program is distributed in the hope that it will be useful,
7
# but WITHOUT ANY WARRANTY; without even the implied warranty of
8
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
9
# GNU General Public License for more details.
10
11
# You should have received a copy of the GNU General Public License
12
# along with this program; if not, write to the Free Software
13
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
14
208.2.1 by Robert Collins
Better module docstring.
15
"""Graphical support for Bazaar using GTK.
16
17
This plugin includes:
18
gannotate         GTK+ annotate. 
19
gbranch           GTK+ branching. 
20
gcheckout         GTK+ checkout. 
323 by Jelmer Vernooij
Add gsend command.
21
gcommit           GTK+ commit dialog.
242.1.2 by Adeodato Simó
Fix gconflicts docstring.
22
gconflicts        GTK+ conflicts. 
208.2.1 by Robert Collins
Better module docstring.
23
gdiff             Show differences in working tree in a GTK+ Window. 
24
ginit             Initialise a new branch.
592.4.1 by Jasper Groenewegen
Add ginfo command to bzr, shows info dialog
25
ginfo             GTK+ branch info dialog
580.1.1 by Jelmer Vernooij
Add gloom command.
26
gloom             GTK+ loom browse dialog
571.1.1 by Jasper Groenewegen
Add gmerge command and change MergeDialog to set parent as default if available
27
gmerge            GTK+ merge dialog
208.2.1 by Robert Collins
Better module docstring.
28
gmissing          GTK+ missing revisions dialog. 
29
gpreferences      GTK+ preferences dialog. 
323 by Jelmer Vernooij
Add gsend command.
30
gpush             GTK+ push.
31
gsend             GTK+ send merge directive.
32
gstatus           GTK+ status dialog.
208.2.1 by Robert Collins
Better module docstring.
33
gtags             Manage branch tags.
34
visualise         Graphically visualise this branch. 
35
"""
73 by Jelmer Vernooij
Release 0.9, list myself as maintainer.
36
137 by Jelmer Vernooij
Warn about incompatible versions (taken from bzrtools, thanks Aaron).
37
import bzrlib
625.1.1 by Jelmer Vernooij
Use bzrlib.api.require_any_version() rather than doing our own version checking.
38
import bzrlib.api
625.2.1 by Jelmer Vernooij
Move commands to a separate module and register them lazily.
39
from bzrlib import errors
40
from bzrlib.commands import plugin_cmds
41
42
import os.path
137 by Jelmer Vernooij
Warn about incompatible versions (taken from bzrtools, thanks Aaron).
43
590 by Jelmer Vernooij
Open 0.96.0 for development.
44
version_info = (0, 96, 0, 'dev', 1)
137 by Jelmer Vernooij
Warn about incompatible versions (taken from bzrtools, thanks Aaron).
45
287 by Jelmer Vernooij
Use standard version tuple.
46
if version_info[3] == 'final':
47
    version_string = '%d.%d.%d' % version_info[:3]
48
else:
49
    version_string = '%d.%d.%d%s%d' % version_info
50
__version__ = version_string
137 by Jelmer Vernooij
Warn about incompatible versions (taken from bzrtools, thanks Aaron).
51
625.1.1 by Jelmer Vernooij
Use bzrlib.api.require_any_version() rather than doing our own version checking.
52
COMPATIBLE_BZR_VERSIONS = [(1, 6, 0), (1, 7, 0), (1, 8, 0), (1, 9, 0),
625.1.3 by Jelmer Vernooij
Mark as compatible with bzr 1.13.
53
                           (1, 10, 0), (1, 11, 0), (1, 12, 0), (1, 13, 0)]
625.1.1 by Jelmer Vernooij
Use bzrlib.api.require_any_version() rather than doing our own version checking.
54
55
bzrlib.api.require_any_api(bzrlib, COMPATIBLE_BZR_VERSIONS)
137 by Jelmer Vernooij
Warn about incompatible versions (taken from bzrtools, thanks Aaron).
56
146 by Jelmer Vernooij
Move more code to top-level directory.
57
if __name__ != 'bzrlib.plugins.gtk':
625.2.1 by Jelmer Vernooij
Move commands to a separate module and register them lazily.
58
    from bzrlib.trace import warning
146 by Jelmer Vernooij
Move more code to top-level directory.
59
    warning("Not running as bzrlib.plugins.gtk, things may break.")
60
66.2.20 by Aaron Bentley
Nicer error when PyGTK not installed
61
def import_pygtk():
62
    try:
63
        import pygtk
64
    except ImportError:
65
        raise errors.BzrCommandError("PyGTK not installed.")
66
    pygtk.require('2.0')
67
    return pygtk
68
69
133 by Jelmer Vernooij
Actually use the ui factory.
70
def set_ui_factory():
177 by Jelmer Vernooij
Register commands all at once.
71
    import_pygtk()
142 by Jelmer Vernooij
Move some files to the top-level directory, add first test.
72
    from ui import GtkUIFactory
133 by Jelmer Vernooij
Actually use the ui factory.
73
    import bzrlib.ui
74
    bzrlib.ui.ui_factory = GtkUIFactory()
75
76
531.6.1 by Jelmer Vernooij
Try harder to find license and credits files.
77
def data_basedirs():
78
    return [os.path.dirname(__file__),
399.1.19 by Jelmer Vernooij
Add utility function for finding icon paths.
79
             "/usr/share/bzr-gtk", 
80
             "/usr/local/share/bzr-gtk"]
531.6.1 by Jelmer Vernooij
Try harder to find license and credits files.
81
82
83
def data_path(*args):
84
    for basedir in data_basedirs():
85
        path = os.path.join(basedir, *args)
399.1.19 by Jelmer Vernooij
Add utility function for finding icon paths.
86
        if os.path.exists(path):
87
            return path
88
    return None
89
90
531.6.1 by Jelmer Vernooij
Try harder to find license and credits files.
91
def icon_path(*args):
92
    return data_path(os.path.join('icons', *args))
93
94
505.1.1 by Jelmer Vernooij
Make handle-patch not dependend on the users name being abentley and install it.
95
def open_display():
96
    pygtk = import_pygtk()
97
    try:
98
        import gtk
99
    except RuntimeError, e:
100
        if str(e) == "could not open display":
101
            raise NoDisplayError
102
    set_ui_factory()
103
    return gtk
104
 
105
625.2.1 by Jelmer Vernooij
Move commands to a separate module and register them lazily.
106
commands = {
107
    "gannotate": ["gblame", "gpraise"],
108
    "gbranch": [],
109
    "gcheckout": [], 
110
    "gcommit": ["gci"], 
111
    "gconflicts": [], 
112
    "gdiff": [],
113
    "ginit": [],
114
    "ginfo": [],
115
    "gmerge": [],
116
    "gmissing": [], 
117
    "gpreferences": [], 
118
    "gpush": [], 
119
    "gselftest": [],
120
    "gsend": [],
121
    "gstatus": ["gst"],
122
    "gtags": [],
123
    "visualise": ["visualize", "vis", "viz"],
124
    }
177 by Jelmer Vernooij
Register commands all at once.
125
580.1.5 by Jelmer Vernooij
Try to import rather than use getattr to avoid problems wrt the order in which plugins are loaded.
126
try:
127
    from bzrlib.plugins import loom
128
except ImportError:
129
    pass # Loom plugin doesn't appear to be present
130
else:
625.2.1 by Jelmer Vernooij
Move commands to a separate module and register them lazily.
131
    commands["gloom"] = []
132
133
for cmd, aliases in commands.iteritems():
134
    plugin_cmds.register_lazy("cmd_%s" % cmd, aliases, "bzrlib.plugins.gtk.commands")
249 by Aaron Bentley
Add gselftest command
135
136
152 by Jelmer Vernooij
Cleanup some more code.
137
import gettext
138
gettext.install('olive-gtk')
139
475.1.2 by Vincent Ladeuil
Fix bug #187283 fix replacing _() by _i18n().
140
# Let's create a specialized alias to protect '_' from being erased by other
141
# uses of '_' as an anonymous variable (think pdb for one).
142
_i18n = gettext.gettext
173.1.2 by Robert Collins
Minor refactoring of __init__ to have less duplication.
143
625.2.1 by Jelmer Vernooij
Move commands to a separate module and register them lazily.
144
class NoDisplayError(errors.BzrCommandError):
55.1.2 by Jelmer Vernooij
Move commands to top-level __init__
145
    """gtk could not find a proper display"""
146
147
    def __str__(self):
133 by Jelmer Vernooij
Actually use the ui factory.
148
        return "No DISPLAY. Unable to run GTK+ application."
149
173.1.2 by Robert Collins
Minor refactoring of __init__ to have less duplication.
150
140 by Jelmer Vernooij
add framework for tests.
151
def test_suite():
152
    from unittest import TestSuite
153
    import tests
163 by Aaron Bentley
Prevent test suite from causing default-encoding changes
154
    import sys
155
    default_encoding = sys.getdefaultencoding()
156
    try:
157
        result = TestSuite()
330.6.4 by Aaron Bentley
Allow test suite to run without pygtk
158
        try:
159
            import_pygtk()
160
        except errors.BzrCommandError:
161
            return result
163 by Aaron Bentley
Prevent test suite from causing default-encoding changes
162
        result.addTest(tests.test_suite())
163
    finally:
170.1.2 by Aaron Bentley
Test suite only fixes encoding if it's changed. Fixes test_selftest bug.
164
        if sys.getdefaultencoding() != default_encoding:
165
            reload(sys)
166
            sys.setdefaultencoding(default_encoding)
140 by Jelmer Vernooij
add framework for tests.
167
    return result