/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: Aaron Bentley
  • Date: 2007-01-17 06:42:55 UTC
  • mto: This revision was merged to the branch mainline in revision 129.
  • Revision ID: aaron.bentley@utoronto.ca-20070117064255-x4gznz5e0lyjq3gk
Remove usused span selector

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
 
15
15
"""GTK+ frontends to Bazaar commands """
16
16
 
17
 
import bzrlib
18
 
 
19
 
__version__ = '0.16.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:
34
 
        return
35
 
    try:
36
 
        from bzrlib.trace import warning
37
 
    except ImportError:
38
 
        # get the message out any way we can
39
 
        from warnings import warn as warning
40
 
    if bzrlib_version < desired:
41
 
        warning('Installed bzr version %s is too old to be used with bzr-gtk'
42
 
                ' %s.' % (bzrlib.__version__, __version__))
43
 
        # Not using BzrNewError, because it may not exist.
44
 
        raise Exception, ('Version mismatch', version_info)
45
 
    else:
46
 
        warning('bzr-gtk is not up to date with installed bzr version %s.'
47
 
                ' \nThere should be a newer version available, e.g. %i.%i.' 
48
 
                % (bzrlib.__version__, bzrlib_version[0], bzrlib_version[1]))
49
 
        if bzrlib_version != desired_plus:
50
 
            raise Exception, 'Version mismatch'
51
 
 
52
 
 
53
 
check_bzrlib_version(version_info[:2])
54
 
 
55
 
from bzrlib.trace import warning
56
 
if __name__ != 'bzrlib.plugins.gtk':
57
 
    warning("Not running as bzrlib.plugins.gtk, things may break.")
58
 
 
59
 
from bzrlib.lazy_import import lazy_import
60
 
lazy_import(globals(), """
61
 
from bzrlib import (
62
 
    branch,
63
 
    errors,
64
 
    workingtree,
65
 
    )
66
 
""")
67
 
 
 
17
from bzrlib import errors
68
18
from bzrlib.commands import Command, register_command, display_command
69
19
from bzrlib.errors import NotVersionedError, BzrCommandError, NoSuchFile
70
20
from bzrlib.commands import Command, register_command
71
21
from bzrlib.option import Option
 
22
from bzrlib.branch import Branch
 
23
from bzrlib.workingtree import WorkingTree
72
24
from bzrlib.bzrdir import BzrDir
73
25
 
74
 
import os.path
75
 
 
76
 
def import_pygtk():
77
 
    try:
78
 
        import pygtk
79
 
    except ImportError:
80
 
        raise errors.BzrCommandError("PyGTK not installed.")
81
 
    pygtk.require('2.0')
82
 
    return pygtk
83
 
 
84
 
 
85
 
def set_ui_factory():
86
 
    pygtk = import_pygtk()
87
 
    from ui import GtkUIFactory
88
 
    import bzrlib.ui
89
 
    bzrlib.ui.ui_factory = GtkUIFactory()
90
 
 
 
26
__version__ = '0.13.0'
91
27
 
92
28
class cmd_gbranch(Command):
93
29
    """GTK+ branching.
95
31
    """
96
32
 
97
33
    def run(self):
98
 
        pygtk = import_pygtk()
 
34
        import pygtk
 
35
        pygtk.require("2.0")
99
36
        try:
100
37
            import gtk
101
38
        except RuntimeError, e:
102
39
            if str(e) == "could not open display":
103
40
                raise NoDisplayError
104
41
 
105
 
        from bzrlib.plugins.gtk.branch import BranchDialog
 
42
        from bzrlib.plugins.gtk.olive.branch import BranchDialog
106
43
 
107
 
        set_ui_factory()
108
 
        dialog = BranchDialog(os.path.abspath('.'))
109
 
        dialog.run()
 
44
        window = BranchDialog('.')
 
45
        window.display()
110
46
 
111
47
register_command(cmd_gbranch)
112
48
 
113
 
class cmd_gcheckout(Command):
114
 
    """ GTK+ checkout.
115
 
    
116
 
    """
117
 
    
118
 
    def run(self):
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
 
 
126
 
        from bzrlib.plugins.gtk.checkout import CheckoutDialog
127
 
 
128
 
        set_ui_factory()
129
 
        dialog = CheckoutDialog(os.path.abspath('.'))
130
 
        dialog.run()
131
 
 
132
 
register_command(cmd_gcheckout)
133
 
 
134
 
class cmd_gpush(Command):
135
 
    """ GTK+ push.
136
 
    
137
 
    """
138
 
    takes_args = [ "location?" ]
139
 
 
140
 
    def run(self, location="."):
141
 
        (br, path) = branch.Branch.open_containing(location)
142
 
 
143
 
        pygtk = import_pygtk()
144
 
        try:
145
 
            import gtk
146
 
        except RuntimeError, e:
147
 
            if str(e) == "could not open display":
148
 
                raise NoDisplayError
149
 
 
150
 
        from push import PushDialog
151
 
 
152
 
        set_ui_factory()
153
 
        dialog = PushDialog(br)
154
 
        dialog.run()
155
 
 
156
 
register_command(cmd_gpush)
157
 
 
158
49
class cmd_gdiff(Command):
159
50
    """Show differences in working tree in a GTK+ Window.
160
51
    
165
56
 
166
57
    @display_command
167
58
    def run(self, revision=None, filename=None):
168
 
        set_ui_factory()
169
 
        wt = workingtree.WorkingTree.open_containing(".")[0]
170
 
        wt.lock_read()
171
 
        try:
172
 
            branch = wt.branch
173
 
            if revision is not None:
174
 
                if len(revision) == 1:
175
 
                    tree1 = wt
176
 
                    revision_id = revision[0].in_history(branch).rev_id
177
 
                    tree2 = branch.repository.revision_tree(revision_id)
178
 
                elif len(revision) == 2:
179
 
                    revision_id_0 = revision[0].in_history(branch).rev_id
180
 
                    tree2 = branch.repository.revision_tree(revision_id_0)
181
 
                    revision_id_1 = revision[1].in_history(branch).rev_id
182
 
                    tree1 = branch.repository.revision_tree(revision_id_1)
183
 
            else:
 
59
        wt = WorkingTree.open_containing(".")[0]
 
60
        branch = wt.branch
 
61
        if revision is not None:
 
62
            if len(revision) == 1:
184
63
                tree1 = wt
185
 
                tree2 = tree1.basis_tree()
186
 
 
187
 
            from diff import DiffWindow
188
 
            import gtk
189
 
            window = DiffWindow()
190
 
            window.connect("destroy", gtk.main_quit)
191
 
            window.set_diff("Working Tree", tree1, tree2)
192
 
            if filename is not None:
193
 
                tree_filename = wt.relpath(filename)
194
 
                try:
195
 
                    window.set_file(tree_filename)
196
 
                except NoSuchFile:
197
 
                    if (tree1.inventory.path2id(tree_filename) is None and 
198
 
                        tree2.inventory.path2id(tree_filename) is None):
199
 
                        raise NotVersionedError(filename)
200
 
                    raise BzrCommandError('No changes found for file "%s"' % 
201
 
                                          filename)
202
 
            window.show()
203
 
 
204
 
            gtk.main()
205
 
        finally:
206
 
            wt.unlock()
 
64
                revision_id = revision[0].in_history(branch).rev_id
 
65
                tree2 = branch.repository.revision_tree(revision_id)
 
66
            elif len(revision) == 2:
 
67
                revision_id_0 = revision[0].in_history(branch).rev_id
 
68
                tree2 = branch.repository.revision_tree(revision_id_0)
 
69
                revision_id_1 = revision[1].in_history(branch).rev_id
 
70
                tree1 = branch.repository.revision_tree(revision_id_1)
 
71
        else:
 
72
            tree1 = wt
 
73
            tree2 = tree1.basis_tree()
 
74
 
 
75
        from viz.diffwin import DiffWindow
 
76
        import gtk
 
77
        window = DiffWindow()
 
78
        window.connect("destroy", lambda w: gtk.main_quit())
 
79
        window.set_diff("Working Tree", tree1, tree2)
 
80
        if filename is not None:
 
81
            tree_filename = wt.relpath(filename)
 
82
            try:
 
83
                window.set_file(tree_filename)
 
84
            except NoSuchFile:
 
85
                if (tree1.inventory.path2id(tree_filename) is None and 
 
86
                    tree2.inventory.path2id(tree_filename) is None):
 
87
                    raise NotVersionedError(filename)
 
88
                raise BzrCommandError('No changes found for file "%s"' % 
 
89
                                      filename)
 
90
        window.show()
 
91
 
 
92
        gtk.main()
207
93
 
208
94
register_command(cmd_gdiff)
209
95
 
224
110
    aliases = [ "visualize", "vis", "viz" ]
225
111
 
226
112
    def run(self, location=".", revision=None, limit=None):
227
 
        set_ui_factory()
228
 
        (br, path) = branch.Branch.open_containing(location)
229
 
        br.lock_read()
230
 
        br.repository.lock_read()
 
113
        (branch, path) = Branch.open_containing(location)
 
114
        branch.lock_read()
 
115
        branch.repository.lock_read()
231
116
        try:
232
117
            if revision is None:
233
 
                revid = br.last_revision()
 
118
                revid = branch.last_revision()
234
119
                if revid is None:
235
120
                    return
236
121
            else:
237
 
                (revno, revid) = revision[0].in_history(br)
 
122
                (revno, revid) = revision[0].in_history(branch)
238
123
 
239
 
            from viz.branchwin import BranchWindow
240
 
            import gtk
 
124
            from viz.bzrkapp import BzrkApp
241
125
                
242
 
            pp = BranchWindow()
243
 
            pp.set_branch(br, revid, limit)
244
 
            pp.connect("destroy", lambda w: gtk.main_quit())
245
 
            pp.show()
246
 
            gtk.main()
 
126
            app = BzrkApp()
 
127
            app.show(branch, revid, limit)
247
128
        finally:
248
 
            br.repository.unlock()
249
 
            br.unlock()
 
129
            branch.repository.unlock()
 
130
            branch.unlock()
 
131
        app.main()
250
132
 
251
133
 
252
134
register_command(cmd_visualise)
268
150
    aliases = ["gblame", "gpraise"]
269
151
    
270
152
    def run(self, filename, all=False, plain=False, line='1', revision=None):
271
 
        pygtk = import_pygtk()
 
153
        import pygtk
 
154
        pygtk.require("2.0")
272
155
 
273
156
        try:
274
157
            import gtk
275
158
        except RuntimeError, e:
276
159
            if str(e) == "could not open display":
277
160
                raise NoDisplayError
278
 
        set_ui_factory()
279
161
 
280
162
        try:
281
163
            line = int(line)
286
168
        from annotate.gannotate import GAnnotateWindow
287
169
        from annotate.config import GAnnotateConfig
288
170
 
289
 
        wt, br, path = BzrDir.open_containing_tree_or_branch(filename)
290
 
        if wt is not None:
291
 
            tree = wt
292
 
        else:
293
 
            tree = br.basis_tree()
 
171
        try:
 
172
            (tree, path) = WorkingTree.open_containing(filename)
 
173
            branch = tree.branch
 
174
        except errors.NoWorkingTree:
 
175
            (branch, path) = Branch.open_containing(filename)
 
176
            tree = branch.basis_tree()
294
177
 
295
178
        file_id = tree.path2id(path)
296
179
 
299
182
        if revision is not None:
300
183
            if len(revision) != 1:
301
184
                raise BzrCommandError("Only 1 revion may be specified.")
302
 
            revision_id = revision[0].in_history(br).rev_id
303
 
            tree = br.repository.revision_tree(revision_id)
 
185
            revision_id = revision[0].in_history(branch).rev_id
 
186
            tree = branch.repository.revision_tree(revision_id)
304
187
        else:
305
188
            revision_id = getattr(tree, 'get_revision_id', lambda: None)()
306
189
 
309
192
        window.set_title(path + " - gannotate")
310
193
        config = GAnnotateConfig(window)
311
194
        window.show()
312
 
        br.lock_read()
313
 
        if wt is not None:
314
 
            wt.lock_read()
 
195
        branch.lock_read()
315
196
        try:
316
 
            window.annotate(tree, br, file_id)
317
 
            window.jump_to_line(line)
318
 
            gtk.main()
 
197
            window.annotate(tree, branch, file_id)
319
198
        finally:
320
 
            br.unlock()
321
 
            if wt is not None:
322
 
                wt.unlock()
 
199
            branch.unlock()
 
200
        window.jump_to_line(line)
 
201
        
 
202
        gtk.main()
323
203
 
324
204
register_command(cmd_gannotate)
325
205
 
328
208
 
329
209
    Graphical user interface for committing revisions"""
330
210
    
331
 
    aliases = [ "gci" ]
332
211
    takes_args = []
333
212
    takes_options = []
334
213
 
335
214
    def run(self, filename=None):
336
215
        import os
337
 
        pygtk = import_pygtk()
 
216
        import pygtk
 
217
        pygtk.require("2.0")
338
218
 
339
219
        try:
340
220
            import gtk
342
222
            if str(e) == "could not open display":
343
223
                raise NoDisplayError
344
224
 
345
 
        set_ui_factory()
346
 
        from commit import CommitDialog
 
225
        from olive.commit import CommitDialog
347
226
        from bzrlib.commit import Commit
348
227
        from bzrlib.errors import (BzrCommandError,
349
228
                                   NotBranchError,
353
232
                                   StrictCommitFailed)
354
233
 
355
234
        wt = None
356
 
        br = None
 
235
        branch = None
357
236
        try:
358
 
            (wt, path) = workingtree.WorkingTree.open_containing(filename)
359
 
            br = wt.branch
 
237
            (wt, path) = WorkingTree.open_containing(filename)
 
238
            branch = wt.branch
360
239
        except NotBranchError, e:
361
240
            path = e.path
362
241
        except NoWorkingTree, e:
363
242
            path = e.base
364
243
            try:
365
 
                (br, path) = branch.Branch.open_containing(path)
 
244
                (branch, path) = Branch.open_containing(path)
366
245
            except NotBranchError, e:
367
246
                path = e.path
368
247
 
369
 
 
370
 
        commit = CommitDialog(wt, path, not br)
371
 
        commit.run()
 
248
        dialog = CommitDialog(wt, path, not branch)
 
249
        if dialog.display():
 
250
            dialog.window.connect("destroy", lambda w: gtk.main_quit())
 
251
            gtk.main()
372
252
 
373
253
register_command(cmd_gcommit)
374
254
 
375
 
class cmd_gstatus(Command):
376
 
    """GTK+ status dialog
377
 
 
378
 
    Graphical user interface for showing status 
379
 
    information."""
380
 
    
381
 
    aliases = [ "gst" ]
382
 
    takes_args = ['PATH?']
383
 
    takes_options = []
384
 
 
385
 
    def run(self, path='.'):
386
 
        import os
387
 
        pygtk = import_pygtk()
388
 
 
389
 
        try:
390
 
            import gtk
391
 
        except RuntimeError, e:
392
 
            if str(e) == "could not open display":
393
 
                raise NoDisplayError
394
 
 
395
 
        set_ui_factory()
396
 
        from status import StatusDialog
397
 
        (wt, wt_path) = workingtree.WorkingTree.open_containing(path)
398
 
        status = StatusDialog(wt, wt_path)
399
 
        status.connect("destroy", gtk.main_quit)
400
 
        status.run()
401
 
 
402
 
register_command(cmd_gstatus)
403
 
 
404
 
class cmd_gconflicts(Command):
405
 
    """ GTK+ push.
406
 
    
407
 
    """
408
 
    def run(self):
409
 
        (wt, path) = workingtree.WorkingTree.open_containing('.')
410
 
        
411
 
        pygtk = import_pygtk()
412
 
        try:
413
 
            import gtk
414
 
        except RuntimeError, e:
415
 
            if str(e) == "could not open display":
416
 
                raise NoDisplayError
417
 
 
418
 
        from bzrlib.plugins.gtk.conflicts import ConflictsDialog
419
 
 
420
 
        set_ui_factory()
421
 
        dialog = ConflictsDialog(wt)
422
 
        dialog.run()
423
 
 
424
 
register_command(cmd_gconflicts)
425
 
 
426
 
class cmd_gpreferences(Command):
427
 
    """ GTK+ preferences dialog.
428
 
 
429
 
    """
430
 
    def run(self):
431
 
        pygtk = import_pygtk()
432
 
        try:
433
 
            import gtk
434
 
        except RuntimeError, e:
435
 
            if str(e) == "could not open display":
436
 
                raise NoDisplayError
437
 
 
438
 
        from bzrlib.plugins.gtk.preferences import PreferencesWindow
439
 
 
440
 
        set_ui_factory()
441
 
        dialog = PreferencesWindow()
442
 
        dialog.run()
443
 
 
444
 
register_command(cmd_gpreferences)
445
 
 
446
 
import gettext
447
 
gettext.install('olive-gtk')
448
 
 
449
255
class NoDisplayError(BzrCommandError):
450
256
    """gtk could not find a proper display"""
451
257
 
452
258
    def __str__(self):
453
 
        return "No DISPLAY. Unable to run GTK+ application."
454
 
 
455
 
def test_suite():
456
 
    from unittest import TestSuite
457
 
    import tests
458
 
    import sys
459
 
    default_encoding = sys.getdefaultencoding()
460
 
    try:
461
 
        result = TestSuite()
462
 
        result.addTest(tests.test_suite())
463
 
    finally:
464
 
        if sys.getdefaultencoding() != default_encoding:
465
 
            reload(sys)
466
 
            sys.setdefaultencoding(default_encoding)
467
 
    return result
 
259
        return "No DISPLAY. gannotate is disabled."