/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to __init__.py

  • Committer: Vincent Ladeuil
  • Date: 2009-05-06 11:51:38 UTC
  • mfrom: (628.1.2 gtk)
  • Revision ID: v.ladeuil+lp@free.fr-20090506115138-7abxvg2qz4gzraup
UpgradeĀ COMPATIBLE_BZR_VERSIONS

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
 
 
15
"""Graphical support for Bazaar using GTK.
 
16
 
 
17
This plugin includes:
 
18
gannotate         GTK+ annotate. 
 
19
gbranch           GTK+ branching. 
 
20
gcheckout         GTK+ checkout. 
 
21
gcommit           GTK+ commit dialog.
 
22
gconflicts        GTK+ conflicts. 
 
23
gdiff             Show differences in working tree in a GTK+ Window. 
 
24
ginit             Initialise a new branch.
 
25
ginfo             GTK+ branch info dialog
 
26
gloom             GTK+ loom browse dialog
 
27
gmerge            GTK+ merge dialog
 
28
gmissing          GTK+ missing revisions dialog. 
 
29
gpreferences      GTK+ preferences dialog. 
 
30
gpush             GTK+ push.
 
31
gsend             GTK+ send merge directive.
 
32
gstatus           GTK+ status dialog.
 
33
gtags             Manage branch tags.
 
34
visualise         Graphically visualise this branch. 
 
35
"""
 
36
 
 
37
import bzrlib
 
38
import bzrlib.api
 
39
from bzrlib import errors
 
40
from bzrlib.commands import plugin_cmds
 
41
 
 
42
import os.path
 
43
 
 
44
version_info = (0, 96, 0, 'dev', 1)
 
45
 
 
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
 
51
 
 
52
COMPATIBLE_BZR_VERSIONS = [(1, 6, 0), (1, 7, 0), (1, 8, 0), (1, 9, 0),
 
53
                           (1, 10, 0), (1, 11, 0), (1, 12, 0), (1, 13, 0),
 
54
                           (1, 15, 0),]
 
55
 
 
56
bzrlib.api.require_any_api(bzrlib, COMPATIBLE_BZR_VERSIONS)
 
57
 
 
58
if __name__ != 'bzrlib.plugins.gtk':
 
59
    from bzrlib.trace import warning
 
60
    warning("Not running as bzrlib.plugins.gtk, things may break.")
 
61
 
 
62
def import_pygtk():
 
63
    try:
 
64
        import pygtk
 
65
    except ImportError:
 
66
        raise errors.BzrCommandError("PyGTK not installed.")
 
67
    pygtk.require('2.0')
 
68
    return pygtk
 
69
 
 
70
 
 
71
def set_ui_factory():
 
72
    import_pygtk()
 
73
    from ui import GtkUIFactory
 
74
    import bzrlib.ui
 
75
    bzrlib.ui.ui_factory = GtkUIFactory()
 
76
 
 
77
 
 
78
def data_basedirs():
 
79
    return [os.path.dirname(__file__),
 
80
             "/usr/share/bzr-gtk", 
 
81
             "/usr/local/share/bzr-gtk"]
 
82
 
 
83
 
 
84
def data_path(*args):
 
85
    for basedir in data_basedirs():
 
86
        path = os.path.join(basedir, *args)
 
87
        if os.path.exists(path):
 
88
            return path
 
89
    return None
 
90
 
 
91
 
 
92
def icon_path(*args):
 
93
    return data_path(os.path.join('icons', *args))
 
94
 
 
95
 
 
96
def open_display():
 
97
    pygtk = import_pygtk()
 
98
    try:
 
99
        import gtk
 
100
    except RuntimeError, e:
 
101
        if str(e) == "could not open display":
 
102
            raise NoDisplayError
 
103
    set_ui_factory()
 
104
    return gtk
 
105
 
 
106
 
 
107
commands = {
 
108
    "gannotate": ["gblame", "gpraise"],
 
109
    "gbranch": [],
 
110
    "gcheckout": [], 
 
111
    "gcommit": ["gci"], 
 
112
    "gconflicts": [], 
 
113
    "gdiff": [],
 
114
    "ginit": [],
 
115
    "ginfo": [],
 
116
    "gmerge": [],
 
117
    "gmissing": [], 
 
118
    "gpreferences": [], 
 
119
    "gpush": [], 
 
120
    "gselftest": [],
 
121
    "gsend": [],
 
122
    "gstatus": ["gst"],
 
123
    "gtags": [],
 
124
    "visualise": ["visualize", "vis", "viz"],
 
125
    }
 
126
 
 
127
try:
 
128
    from bzrlib.plugins import loom
 
129
except ImportError:
 
130
    pass # Loom plugin doesn't appear to be present
 
131
else:
 
132
    commands["gloom"] = []
 
133
 
 
134
for cmd, aliases in commands.iteritems():
 
135
    plugin_cmds.register_lazy("cmd_%s" % cmd, aliases, "bzrlib.plugins.gtk.commands")
 
136
 
 
137
 
 
138
import gettext
 
139
gettext.install('olive-gtk')
 
140
 
 
141
# Let's create a specialized alias to protect '_' from being erased by other
 
142
# uses of '_' as an anonymous variable (think pdb for one).
 
143
_i18n = gettext.gettext
 
144
 
 
145
class NoDisplayError(errors.BzrCommandError):
 
146
    """gtk could not find a proper display"""
 
147
 
 
148
    def __str__(self):
 
149
        return "No DISPLAY. Unable to run GTK+ application."
 
150
 
 
151
 
 
152
def test_suite():
 
153
    from unittest import TestSuite
 
154
    import tests
 
155
    import sys
 
156
    default_encoding = sys.getdefaultencoding()
 
157
    try:
 
158
        result = TestSuite()
 
159
        try:
 
160
            import_pygtk()
 
161
        except errors.BzrCommandError:
 
162
            return result
 
163
        result.addTest(tests.test_suite())
 
164
    finally:
 
165
        if sys.getdefaultencoding() != default_encoding:
 
166
            reload(sys)
 
167
            sys.setdefaultencoding(default_encoding)
 
168
    return result