/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: Szilveszter Farkas (Phanatic)
  • Date: 2007-03-15 12:43:48 UTC
  • mto: (126.1.38 bzr-gtk)
  • mto: This revision was merged to the branch mainline in revision 172.
  • Revision ID: szilveszter.farkas@gmail.com-20070315124348-0nx0zb7fv4pa8xk6
Fix the indentation error in the TortoiseBZR test.

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
import bzrlib
18
18
 
19
 
__version__ = '0.15.0'
 
19
__version__ = '0.16.0'
20
20
version_info = tuple(int(n) for n in __version__.split('.'))
21
21
 
22
22
 
56
56
if __name__ != 'bzrlib.plugins.gtk':
57
57
    warning("Not running as bzrlib.plugins.gtk, things may break.")
58
58
 
59
 
from bzrlib import errors
 
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
 
60
68
from bzrlib.commands import Command, register_command, display_command
61
69
from bzrlib.errors import NotVersionedError, BzrCommandError, NoSuchFile
62
70
from bzrlib.commands import Command, register_command
63
71
from bzrlib.option import Option
64
 
from bzrlib.branch import Branch
65
 
from bzrlib.workingtree import WorkingTree
66
72
from bzrlib.bzrdir import BzrDir
67
73
 
68
74
import os.path
130
136
    
131
137
    """
132
138
    takes_args = [ "location?" ]
133
 
    
 
139
 
134
140
    def run(self, location="."):
135
 
        (branch, path) = Branch.open_containing(location)
136
 
        
 
141
        (br, path) = branch.Branch.open_containing(location)
 
142
 
137
143
        pygtk = import_pygtk()
138
144
        try:
139
145
            import gtk
144
150
        from push import PushDialog
145
151
 
146
152
        set_ui_factory()
147
 
        dialog = PushDialog(branch)
 
153
        dialog = PushDialog(br)
148
154
        dialog.run()
149
155
 
150
156
register_command(cmd_gpush)
160
166
    @display_command
161
167
    def run(self, revision=None, filename=None):
162
168
        set_ui_factory()
163
 
        wt = WorkingTree.open_containing(".")[0]
164
 
        branch = wt.branch
165
 
        if revision is not None:
166
 
            if len(revision) == 1:
 
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:
167
184
                tree1 = wt
168
 
                revision_id = revision[0].in_history(branch).rev_id
169
 
                tree2 = branch.repository.revision_tree(revision_id)
170
 
            elif len(revision) == 2:
171
 
                revision_id_0 = revision[0].in_history(branch).rev_id
172
 
                tree2 = branch.repository.revision_tree(revision_id_0)
173
 
                revision_id_1 = revision[1].in_history(branch).rev_id
174
 
                tree1 = branch.repository.revision_tree(revision_id_1)
175
 
        else:
176
 
            tree1 = wt
177
 
            tree2 = tree1.basis_tree()
178
 
 
179
 
        from diff import DiffWindow
180
 
        import gtk
181
 
        window = DiffWindow()
182
 
        window.connect("destroy", gtk.main_quit)
183
 
        window.set_diff("Working Tree", tree1, tree2)
184
 
        if filename is not None:
185
 
            tree_filename = wt.relpath(filename)
186
 
            try:
187
 
                window.set_file(tree_filename)
188
 
            except NoSuchFile:
189
 
                if (tree1.inventory.path2id(tree_filename) is None and 
190
 
                    tree2.inventory.path2id(tree_filename) is None):
191
 
                    raise NotVersionedError(filename)
192
 
                raise BzrCommandError('No changes found for file "%s"' % 
193
 
                                      filename)
194
 
        window.show()
195
 
 
196
 
        gtk.main()
 
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()
197
207
 
198
208
register_command(cmd_gdiff)
199
209
 
215
225
 
216
226
    def run(self, location=".", revision=None, limit=None):
217
227
        set_ui_factory()
218
 
        (branch, path) = Branch.open_containing(location)
219
 
        branch.lock_read()
220
 
        branch.repository.lock_read()
 
228
        (br, path) = branch.Branch.open_containing(location)
 
229
        br.lock_read()
 
230
        br.repository.lock_read()
221
231
        try:
222
232
            if revision is None:
223
 
                revid = branch.last_revision()
 
233
                revid = br.last_revision()
224
234
                if revid is None:
225
235
                    return
226
236
            else:
227
 
                (revno, revid) = revision[0].in_history(branch)
 
237
                (revno, revid) = revision[0].in_history(br)
228
238
 
229
239
            from viz.branchwin import BranchWindow
230
240
            import gtk
231
241
                
232
242
            pp = BranchWindow()
233
 
            pp.set_branch(branch, revid, limit)
 
243
            pp.set_branch(br, revid, limit)
234
244
            pp.connect("destroy", lambda w: gtk.main_quit())
235
245
            pp.show()
236
246
            gtk.main()
237
247
        finally:
238
 
            branch.repository.unlock()
239
 
            branch.unlock()
 
248
            br.repository.unlock()
 
249
            br.unlock()
240
250
 
241
251
 
242
252
register_command(cmd_visualise)
276
286
        from annotate.gannotate import GAnnotateWindow
277
287
        from annotate.config import GAnnotateConfig
278
288
 
279
 
        try:
280
 
            (tree, path) = WorkingTree.open_containing(filename)
281
 
            branch = tree.branch
282
 
        except errors.NoWorkingTree:
283
 
            (branch, path) = Branch.open_containing(filename)
284
 
            tree = branch.basis_tree()
 
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()
285
294
 
286
295
        file_id = tree.path2id(path)
287
296
 
290
299
        if revision is not None:
291
300
            if len(revision) != 1:
292
301
                raise BzrCommandError("Only 1 revion may be specified.")
293
 
            revision_id = revision[0].in_history(branch).rev_id
294
 
            tree = branch.repository.revision_tree(revision_id)
 
302
            revision_id = revision[0].in_history(br).rev_id
 
303
            tree = br.repository.revision_tree(revision_id)
295
304
        else:
296
305
            revision_id = getattr(tree, 'get_revision_id', lambda: None)()
297
306
 
300
309
        window.set_title(path + " - gannotate")
301
310
        config = GAnnotateConfig(window)
302
311
        window.show()
303
 
        branch.lock_read()
 
312
        br.lock_read()
 
313
        if wt is not None:
 
314
            wt.lock_read()
304
315
        try:
305
 
            window.annotate(tree, branch, file_id)
 
316
            window.annotate(tree, br, file_id)
 
317
            window.jump_to_line(line)
 
318
            gtk.main()
306
319
        finally:
307
 
            branch.unlock()
308
 
        window.jump_to_line(line)
309
 
        
310
 
        gtk.main()
 
320
            br.unlock()
 
321
            if wt is not None:
 
322
                wt.unlock()
311
323
 
312
324
register_command(cmd_gannotate)
313
325
 
341
353
                                   StrictCommitFailed)
342
354
 
343
355
        wt = None
344
 
        branch = None
 
356
        br = None
345
357
        try:
346
 
            (wt, path) = WorkingTree.open_containing(filename)
347
 
            branch = wt.branch
 
358
            (wt, path) = workingtree.WorkingTree.open_containing(filename)
 
359
            br = wt.branch
348
360
        except NotBranchError, e:
349
361
            path = e.path
350
362
        except NoWorkingTree, e:
351
363
            path = e.base
352
364
            try:
353
 
                (branch, path) = Branch.open_containing(path)
 
365
                (br, path) = branch.Branch.open_containing(path)
354
366
            except NotBranchError, e:
355
367
                path = e.path
356
368
 
357
369
 
358
 
        commit = CommitDialog(wt, path, not branch)
 
370
        commit = CommitDialog(wt, path, not br)
359
371
        commit.run()
360
372
 
361
373
register_command(cmd_gcommit)
362
374
 
 
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
 
363
426
import gettext
364
427
gettext.install('olive-gtk')
365
428
 
372
435
def test_suite():
373
436
    from unittest import TestSuite
374
437
    import tests
375
 
    result = TestSuite()
376
 
    result.addTest(tests.test_suite())
 
438
    import sys
 
439
    default_encoding = sys.getdefaultencoding()
 
440
    try:
 
441
        result = TestSuite()
 
442
        result.addTest(tests.test_suite())
 
443
    finally:
 
444
        reload(sys)
 
445
        sys.setdefaultencoding(default_encoding)
377
446
    return result