/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: Adeodato Simó
  • Date: 2007-07-03 22:19:26 UTC
  • Revision ID: dato@net.com.org.es-20070703221926-agtx1dc3h1bkg19o
Mention the package the gtksourceview python bindings live in.

Show diffs side-by-side

added added

removed removed

Lines of Context:
12
12
# along with this program; if not, write to the Free Software
13
13
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
14
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 os
38
 
import sys
39
 
 
40
 
if getattr(sys, "frozen", None) is not None: # we run bzr.exe
41
 
 
42
 
    # FIXME: Unless a better packaging solution is found, the following
43
 
    # provides a workaround for https://bugs.launchpad.net/bzr/+bug/388790 Also
44
 
    # see https://code.edge.launchpad.net/~vila/bzr-gtk/388790-windows-setup
45
 
    # for more details about while it's needed.
46
 
 
47
 
    # NOTE: _lib must be ahead of bzrlib or sax.saxutils (in olive) fails
48
 
    here = os.path.dirname(__file__)
49
 
    sys.path.insert(0, os.path.join(here, '_lib'))
50
 
    sys.path.append(os.path.join(here, '_lib/gtk-2.0'))
51
 
 
 
15
"""GTK+ frontends to Bazaar commands """
52
16
 
53
17
import bzrlib
54
 
import bzrlib.api
 
18
 
 
19
__version__ = '0.17.0'
 
20
version_info = tuple(int(n) for n in __version__.split('.'))
 
21
 
 
22
 
 
23
def check_bzrlib_version(desired):
 
24
    """Check that bzrlib is compatible.
 
25
 
 
26
    If version is < bzr-gtk version, assume incompatible.
 
27
    If version == bzr-gtk version, assume completely compatible
 
28
    If version == bzr-gtk version + 1, assume compatible, with deprecations
 
29
    Otherwise, assume incompatible.
 
30
    """
 
31
    desired_plus = (desired[0], desired[1]+1)
 
32
    bzrlib_version = bzrlib.version_info[:2]
 
33
    if bzrlib_version == desired or (bzrlib_version == desired_plus and
 
34
                                     bzrlib.version_info[3] == 'dev'):
 
35
        return
 
36
    try:
 
37
        from bzrlib.trace import warning
 
38
    except ImportError:
 
39
        # get the message out any way we can
 
40
        from warnings import warn as warning
 
41
    if bzrlib_version < desired:
 
42
        from bzrlib.errors import BzrError
 
43
        warning('Installed bzr version %s is too old to be used with bzr-gtk'
 
44
                ' %s.' % (bzrlib.__version__, __version__))
 
45
        raise BzrError('Version mismatch: %r' % version_info)
 
46
    else:
 
47
        warning('bzr-gtk is not up to date with installed bzr version %s.'
 
48
                ' \nThere should be a newer version available, e.g. %i.%i.' 
 
49
                % (bzrlib.__version__, bzrlib_version[0], bzrlib_version[1]))
 
50
        if bzrlib_version != desired_plus:
 
51
            raise Exception, 'Version mismatch'
 
52
 
 
53
 
 
54
check_bzrlib_version(version_info[:2])
 
55
 
 
56
from bzrlib.trace import warning
 
57
if __name__ != 'bzrlib.plugins.gtk':
 
58
    warning("Not running as bzrlib.plugins.gtk, things may break.")
 
59
 
 
60
from bzrlib.lazy_import import lazy_import
 
61
lazy_import(globals(), """
55
62
from bzrlib import (
56
63
    branch,
57
 
    config,
58
64
    errors,
 
65
    workingtree,
59
66
    )
60
 
from bzrlib.commands import plugin_cmds
61
 
 
62
 
 
63
 
version_info = (0, 98, 0, 'dev', 1)
64
 
 
65
 
if version_info[3] == 'final':
66
 
    version_string = '%d.%d.%d' % version_info[:3]
67
 
else:
68
 
    version_string = '%d.%d.%d%s%d' % version_info
69
 
__version__ = version_string
70
 
 
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
 
                           ]
77
 
 
78
 
bzrlib.api.require_any_api(bzrlib, COMPATIBLE_BZR_VERSIONS)
79
 
 
80
 
if __name__ != 'bzrlib.plugins.gtk':
81
 
    from bzrlib.trace import warning
82
 
    warning("Not running as bzrlib.plugins.gtk, things may break.")
 
67
""")
 
68
 
 
69
from bzrlib.commands import Command, register_command, display_command
 
70
from bzrlib.errors import NotVersionedError, BzrCommandError, NoSuchFile
 
71
from bzrlib.option import Option
 
72
 
 
73
import os.path
83
74
 
84
75
def import_pygtk():
85
76
    try:
97
88
    bzrlib.ui.ui_factory = GtkUIFactory()
98
89
 
99
90
 
100
 
def data_basedirs():
101
 
    return [os.path.dirname(__file__),
102
 
             "/usr/share/bzr-gtk", 
103
 
             "/usr/local/share/bzr-gtk"]
104
 
 
105
 
 
106
 
def data_path(*args):
107
 
    for basedir in data_basedirs():
108
 
        path = os.path.join(basedir, *args)
109
 
        if os.path.exists(path):
110
 
            return path
111
 
    return None
112
 
 
113
 
 
114
 
def icon_path(*args):
115
 
    return data_path(os.path.join('icons', *args))
116
 
 
117
 
 
118
 
def open_display():
119
 
    pygtk = import_pygtk()
120
 
    try:
121
 
        import gtk
122
 
    except RuntimeError, e:
123
 
        if str(e) == "could not open display":
124
 
            raise NoDisplayError
125
 
    set_ui_factory()
126
 
    return gtk
127
 
 
128
 
 
129
 
commands = {
130
 
    "gannotate": ["gblame", "gpraise"],
131
 
    "gbranch": [],
132
 
    "gcheckout": [],
133
 
    "gcommit": ["gci"],
134
 
    "gconflicts": [],
135
 
    "gdiff": [],
136
 
    "ginit": [],
137
 
    "ginfo": [],
138
 
    "gmerge": [],
139
 
    "gmissing": [],
140
 
    "gpreferences": [],
141
 
    "gpush": [],
142
 
    "gselftest": [],
143
 
    "gsend": [],
144
 
    "gstatus": ["gst"],
145
 
    "gtags": [],
146
 
    "visualise": ["visualize", "vis", "viz"],
147
 
    }
148
 
 
149
 
try:
150
 
    from bzrlib.plugins import loom
151
 
except ImportError:
152
 
    pass # Loom plugin doesn't appear to be present
153
 
else:
154
 
    commands["gloom"] = []
155
 
 
156
 
for cmd, aliases in commands.iteritems():
157
 
    plugin_cmds.register_lazy("cmd_%s" % cmd, aliases,
158
 
                              "bzrlib.plugins.gtk.commands")
159
 
 
160
 
def save_commit_messages(*args):
161
 
    from bzrlib.plugins.gtk import commit
162
 
    commit.save_commit_messages(*args)
163
 
 
164
 
branch.Branch.hooks.install_named_hook('post_uncommit',
165
 
                                       save_commit_messages,
166
 
                                       "Saving commit messages for gcommit")
 
91
class GTKCommand(Command):
 
92
    """Abstract class providing GTK specific run commands."""
 
93
 
 
94
    def open_display(self):
 
95
        pygtk = import_pygtk()
 
96
        try:
 
97
            import gtk
 
98
        except RuntimeError, e:
 
99
            if str(e) == "could not open display":
 
100
                raise NoDisplayError
 
101
        set_ui_factory()
 
102
        return gtk
 
103
 
 
104
    def run(self):
 
105
        self.open_display()
 
106
        dialog = self.get_gtk_dialog(os.path.abspath('.'))
 
107
        dialog.run()
 
108
 
 
109
 
 
110
class cmd_gbranch(GTKCommand):
 
111
    """GTK+ branching.
 
112
    
 
113
    """
 
114
 
 
115
    def get_gtk_dialog(self, path):
 
116
        from bzrlib.plugins.gtk.branch import BranchDialog
 
117
        return BranchDialog(path)
 
118
 
 
119
 
 
120
class cmd_gcheckout(GTKCommand):
 
121
    """ GTK+ checkout.
 
122
    
 
123
    """
 
124
    
 
125
    def get_gtk_dialog(self, path):
 
126
        from bzrlib.plugins.gtk.checkout import CheckoutDialog
 
127
        return CheckoutDialog(path)
 
128
 
 
129
 
 
130
 
 
131
class cmd_gpush(GTKCommand):
 
132
    """ GTK+ push.
 
133
    
 
134
    """
 
135
    takes_args = [ "location?" ]
 
136
 
 
137
    def run(self, location="."):
 
138
        (br, path) = branch.Branch.open_containing(location)
 
139
        self.open_display()
 
140
        from push import PushDialog
 
141
        dialog = PushDialog(br)
 
142
        dialog.run()
 
143
 
 
144
 
 
145
 
 
146
class cmd_gdiff(GTKCommand):
 
147
    """Show differences in working tree in a GTK+ Window.
 
148
    
 
149
    Otherwise, all changes for the tree are listed.
 
150
    """
 
151
    takes_args = ['filename?']
 
152
    takes_options = ['revision']
 
153
 
 
154
    @display_command
 
155
    def run(self, revision=None, filename=None):
 
156
        set_ui_factory()
 
157
        wt = workingtree.WorkingTree.open_containing(".")[0]
 
158
        wt.lock_read()
 
159
        try:
 
160
            branch = wt.branch
 
161
            if revision is not None:
 
162
                if len(revision) == 1:
 
163
                    tree1 = wt
 
164
                    revision_id = revision[0].in_history(branch).rev_id
 
165
                    tree2 = branch.repository.revision_tree(revision_id)
 
166
                elif len(revision) == 2:
 
167
                    revision_id_0 = revision[0].in_history(branch).rev_id
 
168
                    tree2 = branch.repository.revision_tree(revision_id_0)
 
169
                    revision_id_1 = revision[1].in_history(branch).rev_id
 
170
                    tree1 = branch.repository.revision_tree(revision_id_1)
 
171
            else:
 
172
                tree1 = wt
 
173
                tree2 = tree1.basis_tree()
 
174
 
 
175
            from diff import DiffWindow
 
176
            import gtk
 
177
            window = DiffWindow()
 
178
            window.connect("destroy", gtk.main_quit)
 
179
            window.set_diff("Working Tree", tree1, tree2)
 
180
            if filename is not None:
 
181
                tree_filename = wt.relpath(filename)
 
182
                try:
 
183
                    window.set_file(tree_filename)
 
184
                except NoSuchFile:
 
185
                    if (tree1.path2id(tree_filename) is None and 
 
186
                        tree2.path2id(tree_filename) is None):
 
187
                        raise NotVersionedError(filename)
 
188
                    raise BzrCommandError('No changes found for file "%s"' % 
 
189
                                          filename)
 
190
            window.show()
 
191
 
 
192
            gtk.main()
 
193
        finally:
 
194
            wt.unlock()
 
195
 
 
196
 
 
197
class cmd_visualise(Command):
 
198
    """Graphically visualise this branch.
 
199
 
 
200
    Opens a graphical window to allow you to see the history of the branch
 
201
    and relationships between revisions in a visual manner,
 
202
 
 
203
    The default starting point is latest revision on the branch, you can
 
204
    specify a starting point with -r revision.
 
205
    """
 
206
    takes_options = [
 
207
        "revision",
 
208
        Option('limit', "maximum number of revisions to display",
 
209
               int, 'count')]
 
210
    takes_args = [ "location?" ]
 
211
    aliases = [ "visualize", "vis", "viz" ]
 
212
 
 
213
    def run(self, location=".", revision=None, limit=None):
 
214
        set_ui_factory()
 
215
        (br, path) = branch.Branch.open_containing(location)
 
216
        br.lock_read()
 
217
        br.repository.lock_read()
 
218
        try:
 
219
            if revision is None:
 
220
                revid = br.last_revision()
 
221
                if revid is None:
 
222
                    return
 
223
            else:
 
224
                (revno, revid) = revision[0].in_history(br)
 
225
 
 
226
            from viz.branchwin import BranchWindow
 
227
            import gtk
 
228
                
 
229
            pp = BranchWindow()
 
230
            pp.set_branch(br, revid, limit)
 
231
            pp.connect("destroy", lambda w: gtk.main_quit())
 
232
            pp.show()
 
233
            gtk.main()
 
234
        finally:
 
235
            br.repository.unlock()
 
236
            br.unlock()
 
237
 
 
238
 
 
239
class cmd_gannotate(GTKCommand):
 
240
    """GTK+ annotate.
 
241
    
 
242
    Browse changes to FILENAME line by line in a GTK+ window.
 
243
    """
 
244
 
 
245
    takes_args = ["filename", "line?"]
 
246
    takes_options = [
 
247
        Option("all", help="show annotations on all lines"),
 
248
        Option("plain", help="don't highlight annotation lines"),
 
249
        Option("line", type=int, argname="lineno",
 
250
               help="jump to specified line number"),
 
251
        "revision",
 
252
    ]
 
253
    aliases = ["gblame", "gpraise"]
 
254
    
 
255
    def run(self, filename, all=False, plain=False, line='1', revision=None):
 
256
        gtk = self.open_display()
 
257
 
 
258
        try:
 
259
            line = int(line)
 
260
        except ValueError:
 
261
            raise BzrCommandError('Line argument ("%s") is not a number.' % 
 
262
                                  line)
 
263
 
 
264
        from annotate.gannotate import GAnnotateWindow
 
265
        from annotate.config import GAnnotateConfig
 
266
        from bzrlib.bzrdir import BzrDir
 
267
 
 
268
        wt, br, path = BzrDir.open_containing_tree_or_branch(filename)
 
269
        if wt is not None:
 
270
            tree = wt
 
271
        else:
 
272
            tree = br.basis_tree()
 
273
 
 
274
        file_id = tree.path2id(path)
 
275
 
 
276
        if file_id is None:
 
277
            raise NotVersionedError(filename)
 
278
        if revision is not None:
 
279
            if len(revision) != 1:
 
280
                raise BzrCommandError("Only 1 revion may be specified.")
 
281
            revision_id = revision[0].in_history(br).rev_id
 
282
            tree = br.repository.revision_tree(revision_id)
 
283
        else:
 
284
            revision_id = getattr(tree, 'get_revision_id', lambda: None)()
 
285
 
 
286
        window = GAnnotateWindow(all, plain)
 
287
        window.connect("destroy", lambda w: gtk.main_quit())
 
288
        window.set_title(path + " - gannotate")
 
289
        config = GAnnotateConfig(window)
 
290
        window.show()
 
291
        br.lock_read()
 
292
        if wt is not None:
 
293
            wt.lock_read()
 
294
        try:
 
295
            window.annotate(tree, br, file_id)
 
296
            window.jump_to_line(line)
 
297
            gtk.main()
 
298
        finally:
 
299
            br.unlock()
 
300
            if wt is not None:
 
301
                wt.unlock()
 
302
 
 
303
 
 
304
 
 
305
class cmd_gcommit(GTKCommand):
 
306
    """GTK+ commit dialog
 
307
 
 
308
    Graphical user interface for committing revisions"""
 
309
    
 
310
    aliases = [ "gci" ]
 
311
    takes_args = []
 
312
    takes_options = []
 
313
 
 
314
    def run(self, filename=None):
 
315
        import os
 
316
        self.open_display()
 
317
        from commit import CommitDialog
 
318
        from bzrlib.errors import (BzrCommandError,
 
319
                                   NotBranchError,
 
320
                                   NoWorkingTree)
 
321
 
 
322
        wt = None
 
323
        br = None
 
324
        try:
 
325
            (wt, path) = workingtree.WorkingTree.open_containing(filename)
 
326
            br = wt.branch
 
327
        except NoWorkingTree, e:
 
328
            path = e.base
 
329
            (br, path) = branch.Branch.open_containing(path)
 
330
 
 
331
        commit = CommitDialog(wt, path, not br)
 
332
        commit.run()
 
333
 
 
334
 
 
335
 
 
336
class cmd_gstatus(GTKCommand):
 
337
    """GTK+ status dialog
 
338
 
 
339
    Graphical user interface for showing status 
 
340
    information."""
 
341
    
 
342
    aliases = [ "gst" ]
 
343
    takes_args = ['PATH?']
 
344
    takes_options = []
 
345
 
 
346
    def run(self, path='.'):
 
347
        import os
 
348
        gtk = self.open_display()
 
349
        from status import StatusDialog
 
350
        (wt, wt_path) = workingtree.WorkingTree.open_containing(path)
 
351
        status = StatusDialog(wt, wt_path)
 
352
        status.connect("destroy", gtk.main_quit)
 
353
        status.run()
 
354
 
 
355
 
 
356
 
 
357
class cmd_gconflicts(GTKCommand):
 
358
    """ GTK+ push.
 
359
    
 
360
    """
 
361
    def run(self):
 
362
        (wt, path) = workingtree.WorkingTree.open_containing('.')
 
363
        self.open_display()
 
364
        from bzrlib.plugins.gtk.conflicts import ConflictsDialog
 
365
        dialog = ConflictsDialog(wt)
 
366
        dialog.run()
 
367
 
 
368
 
 
369
 
 
370
class cmd_gpreferences(GTKCommand):
 
371
    """ GTK+ preferences dialog.
 
372
 
 
373
    """
 
374
    def run(self):
 
375
        self.open_display()
 
376
        from bzrlib.plugins.gtk.preferences import PreferencesWindow
 
377
        dialog = PreferencesWindow()
 
378
        dialog.run()
 
379
 
 
380
 
 
381
 
 
382
class cmd_gmissing(Command):
 
383
    """ GTK+ missing revisions dialog.
 
384
 
 
385
    """
 
386
    takes_args = ["other_branch?"]
 
387
    def run(self, other_branch=None):
 
388
        pygtk = import_pygtk()
 
389
        try:
 
390
            import gtk
 
391
        except RuntimeError, e:
 
392
            if str(e) == "could not open display":
 
393
                raise NoDisplayError
 
394
 
 
395
        from bzrlib.plugins.gtk.missing import MissingWindow
 
396
        from bzrlib.branch import Branch
 
397
 
 
398
        local_branch = Branch.open_containing(".")[0]
 
399
        if other_branch is None:
 
400
            other_branch = local_branch.get_parent()
 
401
            
 
402
            if other_branch is None:
 
403
                raise errors.BzrCommandError("No peer location known or specified.")
 
404
        remote_branch = Branch.open_containing(other_branch)[0]
 
405
        set_ui_factory()
 
406
        local_branch.lock_read()
 
407
        try:
 
408
            remote_branch.lock_read()
 
409
            try:
 
410
                dialog = MissingWindow(local_branch, remote_branch)
 
411
                dialog.run()
 
412
            finally:
 
413
                remote_branch.unlock()
 
414
        finally:
 
415
            local_branch.unlock()
 
416
 
 
417
 
 
418
class cmd_ginit(GTKCommand):
 
419
    def run(self):
 
420
        self.open_display()
 
421
        from initialize import InitDialog
 
422
        dialog = InitDialog(os.path.abspath(os.path.curdir))
 
423
        dialog.run()
 
424
 
 
425
 
 
426
class cmd_gtags(GTKCommand):
 
427
    def run(self):
 
428
        br = branch.Branch.open_containing('.')[0]
 
429
        
 
430
        gtk = self.open_display()
 
431
        from tags import TagsWindow
 
432
        window = TagsWindow(br)
 
433
        window.show()
 
434
        gtk.main()
 
435
 
 
436
 
 
437
commands = [
 
438
    cmd_gmissing, 
 
439
    cmd_gpreferences, 
 
440
    cmd_gconflicts, 
 
441
    cmd_gstatus,
 
442
    cmd_gcommit, 
 
443
    cmd_gannotate, 
 
444
    cmd_visualise, 
 
445
    cmd_gdiff,
 
446
    cmd_gpush, 
 
447
    cmd_gcheckout, 
 
448
    cmd_gbranch,
 
449
    cmd_ginit,
 
450
    cmd_gtags
 
451
    ]
 
452
 
 
453
for cmd in commands:
 
454
    register_command(cmd)
 
455
 
 
456
 
 
457
class cmd_commit_notify(GTKCommand):
 
458
    """Run the bzr commit notifier.
 
459
 
 
460
    This is a background program which will pop up a notification on the users
 
461
    screen when a commit occurs.
 
462
    """
 
463
 
 
464
    def run(self):
 
465
        gtk = self.open_display()
 
466
        import cgi
 
467
        import dbus
 
468
        import dbus.service
 
469
        import pynotify
 
470
        from bzrlib.bzrdir import BzrDir
 
471
        from bzrlib import errors
 
472
        from bzrlib.osutils import format_date
 
473
        from bzrlib.transport import get_transport
 
474
        if getattr(dbus, 'version', (0,0,0)) >= (0,41,0):
 
475
            import dbus.glib
 
476
        from bzrlib.plugins.dbus import activity
 
477
        bus = dbus.SessionBus()
 
478
        # get the object so we can subscribe to callbacks from it.
 
479
        broadcast_service = bus.get_object(
 
480
            activity.Broadcast.DBUS_NAME,
 
481
            activity.Broadcast.DBUS_PATH)
 
482
        def catch_branch(revision_id, urls):
 
483
            # TODO: show all the urls, or perhaps choose the 'best'.
 
484
            url = urls[0]
 
485
            try:
 
486
                if isinstance(revision_id, unicode):
 
487
                    revision_id = revision_id.encode('utf8')
 
488
                transport = get_transport(url)
 
489
                a_dir = BzrDir.open_from_transport(transport)
 
490
                branch = a_dir.open_branch()
 
491
                revno = branch.revision_id_to_revno(revision_id)
 
492
                revision = branch.repository.get_revision(revision_id)
 
493
                summary = 'New revision %d in %s' % (revno, url)
 
494
                body  = 'Committer: %s\n' % revision.committer
 
495
                body += 'Date: %s\n' % format_date(revision.timestamp,
 
496
                    revision.timezone)
 
497
                body += '\n'
 
498
                body += revision.message
 
499
                body = cgi.escape(body)
 
500
                nw = pynotify.Notification(summary, body)
 
501
                nw.set_timeout(5000)
 
502
                nw.show()
 
503
            except Exception, e:
 
504
                print e
 
505
                raise
 
506
        broadcast_service.connect_to_signal("Revision", catch_branch,
 
507
            dbus_interface=activity.Broadcast.DBUS_INTERFACE)
 
508
        pynotify.init("bzr commit-notify")
 
509
        gtk.main()
 
510
 
 
511
register_command(cmd_commit_notify)
 
512
 
167
513
 
168
514
import gettext
169
515
gettext.install('olive-gtk')
170
516
 
171
 
# Let's create a specialized alias to protect '_' from being erased by other
172
 
# uses of '_' as an anonymous variable (think pdb for one).
173
 
_i18n = gettext.gettext
174
517
 
175
 
class NoDisplayError(errors.BzrCommandError):
 
518
class NoDisplayError(BzrCommandError):
176
519
    """gtk could not find a proper display"""
177
520
 
178
521
    def __str__(self):
179
522
        return "No DISPLAY. Unable to run GTK+ application."
180
523
 
181
524
 
182
 
credential_store_registry = getattr(config, "credential_store_registry", None)
183
 
if credential_store_registry is not None:
184
 
    try:
185
 
        credential_store_registry.register_lazy(
186
 
            "gnome-keyring", "bzrlib.plugins.gtk.keyring", "GnomeKeyringCredentialStore",
187
 
            help="The GNOME Keyring.", fallback=True)
188
 
    except TypeError:
189
 
    # Fallback credentials stores were introduced in Bazaar 1.15
190
 
        credential_store_registry.register_lazy(
191
 
            "gnome-keyring", "bzrlib.plugins.gtk.keyring", "GnomeKeyringCredentialStore",
192
 
            help="The GNOME Keyring.")
193
 
 
194
 
 
195
 
def load_tests(basic_tests, module, loader):
196
 
    testmod_names = [
197
 
        'tests',
198
 
        ]
 
525
def test_suite():
 
526
    from unittest import TestSuite
 
527
    import tests
199
528
    import sys
200
529
    default_encoding = sys.getdefaultencoding()
201
530
    try:
202
 
        result = basic_tests
203
 
        try:
204
 
            import_pygtk()
205
 
        except errors.BzrCommandError:
206
 
            return basic_tests
207
 
        basic_tests.addTest(loader.loadTestsFromModuleNames(
208
 
                ["%s.%s" % (__name__, tmn) for tmn in testmod_names]))
 
531
        result = TestSuite()
 
532
        result.addTest(tests.test_suite())
209
533
    finally:
210
534
        if sys.getdefaultencoding() != default_encoding:
211
535
            reload(sys)
212
536
            sys.setdefaultencoding(default_encoding)
213
 
    return basic_tests
 
537
    return result