/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: Jelmer Vernooij
  • Date: 2010-05-25 17:09:02 UTC
  • mto: This revision was merged to the branch mainline in revision 691.
  • Revision ID: jelmer@samba.org-20100525170902-3to8g5iw7ovw79kh
Split out olive into a separate directory.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
"""Graphical support for Bazaar using GTK.
16
16
 
17
17
This plugin includes:
18
 
gannotate         GTK+ annotate.
19
 
gbranch           GTK+ branching.
20
 
gcheckout         GTK+ checkout.
 
18
gannotate         GTK+ annotate. 
 
19
gbranch           GTK+ branching. 
 
20
gcheckout         GTK+ checkout. 
21
21
gcommit           GTK+ commit dialog.
22
 
gconflicts        GTK+ conflicts.
23
 
gdiff             Show differences in working tree in a GTK+ Window.
 
22
gconflicts        GTK+ conflicts. 
 
23
gdiff             Show differences in working tree in a GTK+ Window. 
24
24
ginit             Initialise a new branch.
 
25
ginfo             GTK+ branch info dialog
25
26
gloom             GTK+ loom browse dialog
26
27
gmerge            GTK+ merge dialog
27
 
gmissing          GTK+ missing revisions dialog.
28
 
gpreferences      GTK+ preferences dialog.
 
28
gmissing          GTK+ missing revisions dialog. 
 
29
gpreferences      GTK+ preferences dialog. 
29
30
gpush             GTK+ push.
30
31
gsend             GTK+ send merge directive.
31
32
gstatus           GTK+ status dialog.
32
33
gtags             Manage branch tags.
33
 
visualise         Graphically visualise this branch.
 
34
visualise         Graphically visualise this branch. 
34
35
"""
35
36
 
36
 
from __future__ import absolute_import
37
 
 
38
37
import os
39
38
import sys
40
39
 
56
55
from bzrlib import (
57
56
    branch,
58
57
    config,
 
58
    errors,
59
59
    )
60
60
from bzrlib.commands import plugin_cmds
61
61
 
62
 
from bzrlib.plugins.gtk.info import (
63
 
    bzr_plugin_version as version_info,
64
 
    bzr_compatible_versions,
65
 
    )
 
62
 
 
63
version_info = (0, 99, 0, 'dev', 1)
66
64
 
67
65
if version_info[3] == 'final':
68
66
    version_string = '%d.%d.%d' % version_info[:3]
70
68
    version_string = '%d.%d.%d%s%d' % version_info
71
69
__version__ = version_string
72
70
 
73
 
bzrlib.api.require_any_api(bzrlib, bzr_compatible_versions)
 
71
COMPATIBLE_BZR_VERSIONS = [(1, 6, 0), (1, 7, 0), (1, 8, 0), (1, 9, 0),
 
72
                           (1, 10, 0), (1, 11, 0), (1, 12, 0), (1, 13, 0),
 
73
                           (1, 15, 0),
 
74
                           (1, 17, 0),
 
75
                           (2, 1, 0),
 
76
                           (2, 2, 0),
 
77
                           ]
 
78
 
 
79
bzrlib.api.require_any_api(bzrlib, COMPATIBLE_BZR_VERSIONS)
74
80
 
75
81
if __name__ != 'bzrlib.plugins.gtk':
76
82
    from bzrlib.trace import warning
77
83
    warning("Not running as bzrlib.plugins.gtk, things may break.")
78
84
 
 
85
def import_pygtk():
 
86
    try:
 
87
        import pygtk
 
88
    except ImportError:
 
89
        raise errors.BzrCommandError("PyGTK not installed.")
 
90
    pygtk.require('2.0')
 
91
    return pygtk
 
92
 
79
93
 
80
94
def set_ui_factory():
81
 
    from bzrlib.plugins.gtk.ui import GtkUIFactory
 
95
    import_pygtk()
 
96
    from ui import GtkUIFactory
82
97
    import bzrlib.ui
83
98
    bzrlib.ui.ui_factory = GtkUIFactory()
84
99
 
101
116
    return data_path(os.path.join('icons', *args))
102
117
 
103
118
 
 
119
def open_display():
 
120
    pygtk = import_pygtk()
 
121
    try:
 
122
        import gtk
 
123
    except RuntimeError, e:
 
124
        if str(e) == "could not open display":
 
125
            raise NoDisplayError
 
126
    set_ui_factory()
 
127
    return gtk
 
128
 
 
129
 
104
130
commands = {
105
131
    "gannotate": ["gblame", "gpraise"],
106
132
    "gbranch": [],
109
135
    "gconflicts": [],
110
136
    "gdiff": [],
111
137
    "ginit": [],
 
138
    "ginfo": [],
112
139
    "gmerge": [],
113
140
    "gmissing": [],
114
141
    "gpreferences": [],
115
142
    "gpush": [],
 
143
    "gselftest": [],
116
144
    "gsend": [],
117
145
    "gstatus": ["gst"],
118
146
    "gtags": [],
131
159
                              "bzrlib.plugins.gtk.commands")
132
160
 
133
161
def save_commit_messages(*args):
134
 
    from bzrlib.plugins.gtk import commitmsgs
135
 
    commitmsgs.save_commit_messages(*args)
 
162
    from bzrlib.plugins.gtk import commit
 
163
    commit.save_commit_messages(*args)
136
164
 
137
165
branch.Branch.hooks.install_named_hook('post_uncommit',
138
166
                                       save_commit_messages,
139
167
                                       "Saving commit messages for gcommit")
140
168
 
141
 
option_registry = getattr(config, "option_registry", None)
142
 
if option_registry is not None:
143
 
    config.option_registry.register_lazy('nautilus_integration',
144
 
            'bzrlib.plugins.gtk.config', 'opt_nautilus_integration')
 
169
class NoDisplayError(errors.BzrCommandError):
 
170
    """gtk could not find a proper display"""
 
171
 
 
172
    def __str__(self):
 
173
        return "No DISPLAY. Unable to run GTK+ application."
 
174
 
 
175
 
 
176
credential_store_registry = getattr(config, "credential_store_registry", None)
 
177
if credential_store_registry is not None:
 
178
    try:
 
179
        credential_store_registry.register_lazy(
 
180
            "gnome-keyring", "bzrlib.plugins.gtk.keyring", "GnomeKeyringCredentialStore",
 
181
            help="The GNOME Keyring.", fallback=True)
 
182
    except TypeError:
 
183
    # Fallback credentials stores were introduced in Bazaar 1.15
 
184
        credential_store_registry.register_lazy(
 
185
            "gnome-keyring", "bzrlib.plugins.gtk.keyring", "GnomeKeyringCredentialStore",
 
186
            help="The GNOME Keyring.")
 
187
 
145
188
 
146
189
def load_tests(basic_tests, module, loader):
147
190
    testmod_names = [
152
195
    try:
153
196
        result = basic_tests
154
197
        try:
155
 
            import gi.repository.Gtk
156
 
        except ImportError:
 
198
            import_pygtk()
 
199
        except errors.BzrCommandError:
157
200
            return basic_tests
158
201
        basic_tests.addTest(loader.loadTestsFromModuleNames(
159
202
                ["%s.%s" % (__name__, tmn) for tmn in testmod_names]))
162
205
            reload(sys)
163
206
            sys.setdefaultencoding(default_encoding)
164
207
    return basic_tests
165