/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 olive/info.py

  • Committer: Jelmer Vernooij
  • Date: 2008-06-29 18:12:29 UTC
  • mto: This revision was merged to the branch mainline in revision 519.
  • Revision ID: jelmer@samba.org-20080629181229-1l2m4cf7vvbyh8qg
Simplify progress bar code, use embedded progress bar inside viz window.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
 
import sys
18
 
 
19
17
try:
20
18
    import pygtk
21
19
    pygtk.require("2.0")
22
20
except:
23
21
    pass
24
 
try:
25
 
    import gtk
26
 
    import gtk.glade
27
 
    import gobject
28
 
    import pango
29
 
except:
30
 
    sys.exit(1)
31
 
 
32
 
import olive.backend.errors as errors
33
 
import olive.backend.info as info
 
22
 
 
23
import gtk
 
24
import gtk.glade
 
25
 
 
26
import bzrlib.errors as errors
 
27
 
 
28
from bzrlib.plugins.gtk import _i18n
 
29
from bzrlib.plugins.gtk.dialog import error_dialog
 
30
from guifiles import GLADEFILENAME
 
31
 
 
32
 
 
33
def info(location):
 
34
    """ Get info about branch, working tree, and repository
 
35
    
 
36
    :param location: the location of the branch/working tree/repository
 
37
    
 
38
    :return: the information in dictionary format
 
39
    
 
40
    The following informations are delivered (if available):
 
41
    ret['location']['lightcoroot']: Light checkout root
 
42
    ret['location']['sharedrepo']: Shared repository
 
43
    ret['location']['repobranch']: Repository branch
 
44
    ret['location']['cobranch']: Checkout of branch
 
45
    ret['location']['repoco']: Repository checkout
 
46
    ret['location']['coroot']: Checkout root
 
47
    ret['location']['branchroot']: Branch root
 
48
    ret['related']['parentbranch']: Parent branch
 
49
    ret['related']['publishbranch']: Publish to branch
 
50
    ret['format']['control']: Control format
 
51
    ret['format']['workingtree']: Working tree format
 
52
    ret['format']['branch']: Branch format
 
53
    ret['format']['repository']: Repository format
 
54
    ret['locking']['workingtree']: Working tree lock status
 
55
    ret['locking']['branch']: Branch lock status
 
56
    ret['locking']['repository']: Repository lock status
 
57
    ret['missing']['branch']: Missing revisions in branch
 
58
    ret['missing']['workingtree']: Missing revisions in working tree
 
59
    ret['wtstats']['unchanged']: Unchanged files
 
60
    ret['wtstats']['modified']: Modified files
 
61
    ret['wtstats']['added']: Added files
 
62
    ret['wtstats']['removed']: Removed files
 
63
    ret['wtstats']['renamed']: Renamed files
 
64
    ret['wtstats']['unknown']: Unknown files
 
65
    ret['wtstats']['ignored']: Ingnored files
 
66
    ret['wtstats']['subdirs']: Versioned subdirectories
 
67
    ret['brstats']['revno']: Revisions in branch
 
68
    ret['brstats']['commiters']: Number of commiters
 
69
    ret['brstats']['age']: Age of branch in days
 
70
    ret['brstats']['firstrev']: Time of first revision
 
71
    ret['brstats']['lastrev']: Time of last revision
 
72
    ret['repstats']['revisions']: Revisions in repository
 
73
    ret['repstats']['size']: Size of repository in bytes
 
74
    """
 
75
    import bzrlib.bzrdir as bzrdir
 
76
    
 
77
    import info_helper
 
78
    
 
79
    ret = {}
 
80
    try:
 
81
        a_bzrdir = bzrdir.BzrDir.open_containing(location)[0]
 
82
    except errors.NotBranchError:
 
83
        raise errors.NotBranchError(location)
 
84
 
 
85
    try:
 
86
        working = a_bzrdir.open_workingtree()
 
87
        working.lock_read()
 
88
        try:
 
89
            branch = working.branch
 
90
            repository = branch.repository
 
91
            control = working.bzrdir
 
92
            
 
93
            ret['location'] = info_helper.get_location_info(repository, branch, working)
 
94
            ret['related'] = info_helper.get_related_info(branch)
 
95
            ret['format'] = info_helper.get_format_info(control, repository, branch, working)
 
96
            ret['locking'] = info_helper.get_locking_info(repository, branch, working)
 
97
            ret['missing'] = {}
 
98
            ret['missing']['branch'] = info_helper.get_missing_revisions_branch(branch)
 
99
            ret['missing']['workingtree'] = info_helper.get_missing_revisions_working(working)
 
100
            ret['wtstats'] = info_helper.get_working_stats(working)
 
101
            ret['brstats'] = info_helper.get_branch_stats(branch)
 
102
            ret['repstats'] = info_helper.get_repository_stats(repository)
 
103
        finally:
 
104
            working.unlock()
 
105
            return ret
 
106
        return
 
107
    except (errors.NoWorkingTree, errors.NotLocalUrl):
 
108
        pass
 
109
 
 
110
    try:
 
111
        branch = a_bzrdir.open_branch()
 
112
        repository = branch.repository
 
113
        control = a_bzrdir
 
114
        branch.lock_read()
 
115
        try:
 
116
            ret['location'] = info_helper.get_location_info(repository, branch)
 
117
            ret['related'] = info_helper.get_related_info(branch)
 
118
            ret['format'] = info_helper.get_format_info(control, repository, branch)
 
119
            ret['locking'] = info_helper.get_locking_info(repository, branch)
 
120
            ret['missing']['branch'] = info_helper.get_missing_revisions_branch(branch)
 
121
            ret['brstats'] = info_helper.get_branch_stats(branch)
 
122
            ret['repstats'] = info_helper.get_repository_stats(repository)
 
123
        finally:
 
124
            branch.unlock()
 
125
            return ret
 
126
        return
 
127
    except errors.NotBranchError:
 
128
        pass
 
129
 
 
130
    try:
 
131
        repository = a_bzrdir.open_repository()
 
132
        repository.lock_read()
 
133
        try:
 
134
            ret['location'] = info_helper.get_location_info(repository)
 
135
            ret['format'] = info_helper.get_format_info(control, repository)
 
136
            ret['locking'] = info_helper.get_locking_info(repository)
 
137
            ret['repstats'] = info_helper.get_repository_stats(repository)
 
138
        finally:
 
139
            repository.unlock()
 
140
            return ret
 
141
        return
 
142
    except errors.NoRepositoryPresent:
 
143
        pass
 
144
 
34
145
 
35
146
class OliveInfo:
36
147
    """ Display Informations window and perform the needed actions. """
37
 
    def __init__(self, gladefile, comm, dialog):
 
148
    def __init__(self, branch):
38
149
        """ Initialize the Informations window. """
39
 
        self.gladefile = gladefile
40
 
        self.glade = gtk.glade.XML(self.gladefile, 'window_info', 'olive-gtk')
41
 
        
42
 
        # Communication object
43
 
        self.comm = comm
44
 
        # Dialog object
45
 
        self.dialog = dialog
 
150
        self.glade = gtk.glade.XML(GLADEFILENAME, 'window_info', 'olive-gtk')
46
151
        
47
152
        # Get the Informations window widget
48
153
        self.window = self.glade.get_widget('window_info')
50
155
        # Check if current location is a branch
51
156
        self.notbranch = False
52
157
        try:
53
 
            self.ret = info.info(self.comm.get_path())
 
158
            self.ret = info(branch.base)
54
159
        except errors.NotBranchError:
55
160
            self.notbranch = True
56
161
            return
57
 
        except:
58
 
            raise
59
162
        
60
163
        # Dictionary for signal_autoconnect
61
164
        dic = { "on_button_info_close_clicked": self.close,
84
187
                ll = self.glade.get_widget('label_info_location_lightcoroot_label')
85
188
                l = self.glade.get_widget('label_info_location_lightcoroot')
86
189
                l.set_text(self.ret['location']['lightcoroot'])
87
 
                ll.set_markup('<b>' + ll.get_text() + '</b>')
88
190
                ll.show()
89
191
                l.show()
90
192
                if not display:
95
197
                ll = self.glade.get_widget('label_info_location_sharedrepo_label')
96
198
                l = self.glade.get_widget('label_info_location_sharedrepo')
97
199
                l.set_text(self.ret['location']['sharedrepo'])
98
 
                ll.set_markup('<b>' + ll.get_text() + '</b>')
99
200
                ll.show()
100
201
                l.show()
101
202
                if not display:
106
207
                ll = self.glade.get_widget('label_info_location_repobranch_label')
107
208
                l = self.glade.get_widget('label_info_location_repobranch')
108
209
                l.set_text(self.ret['location']['repobranch'])
109
 
                ll.set_markup('<b>' + ll.get_text() + '</b>')
110
210
                ll.show()
111
211
                l.show()
112
212
                if not display:
117
217
                ll = self.glade.get_widget('label_info_location_cobranch_label')
118
218
                l = self.glade.get_widget('label_info_location_cobranch')
119
219
                l.set_text(self.ret['location']['cobranch'])
120
 
                ll.set_markup('<b>' + ll.get_text() + '</b>')
121
220
                ll.show()
122
221
                l.show()
123
222
                if not display:
128
227
                ll = self.glade.get_widget('label_info_location_repoco_label')
129
228
                l = self.glade.get_widget('label_info_location_repoco')
130
229
                l.set_text(self.ret['location']['repoco'])
131
 
                ll.set_markup('<b>' + ll.get_text() + '</b>')
132
230
                ll.show()
133
231
                l.show()
134
232
                if not display:
139
237
                ll = self.glade.get_widget('label_info_location_coroot_label')
140
238
                l = self.glade.get_widget('label_info_location_coroot')
141
239
                l.set_text(self.ret['location']['coroot'])
142
 
                ll.set_markup('<b>' + ll.get_text() + '</b>')
143
240
                ll.show()
144
241
                l.show()
145
242
                if not display:
150
247
                ll = self.glade.get_widget('label_info_location_branchroot_label')
151
248
                l = self.glade.get_widget('label_info_location_branchroot')
152
249
                l.set_text(self.ret['location']['branchroot'])
153
 
                ll.set_markup('<b>' + ll.get_text() + '</b>')
154
250
                ll.show()
155
251
                l.show()
156
252
                if not display:
165
261
                ll = self.glade.get_widget('label_info_related_parentbranch_label')
166
262
                l = self.glade.get_widget('label_info_related_parentbranch')
167
263
                l.set_text(self.ret['related']['parentbranch'])
168
 
                ll.set_markup('<b>' + ll.get_text() + '</b>')
169
264
                ll.show()
170
265
                l.show()
171
266
                if not display:
176
271
                ll = self.glade.get_widget('label_info_related_publishbranch_label')
177
272
                l = self.glade.get_widget('label_info_related_publishbranch')
178
273
                l.set_text(self.ret['related']['publishbranch'])
179
 
                ll.set_markup('<b>' + ll.get_text() + '</b>')
180
274
                ll.show()
181
275
                l.show()
182
276
                if not display:
191
285
                ll = self.glade.get_widget('label_info_format_control_label')
192
286
                l = self.glade.get_widget('label_info_format_control')
193
287
                l.set_text(self.ret['format']['control'])
194
 
                ll.set_markup('<b>' + ll.get_text() + '</b>')
195
288
                ll.show()
196
289
                l.show()
197
290
                if not display:
202
295
                ll = self.glade.get_widget('label_info_format_workingtree_label')
203
296
                l = self.glade.get_widget('label_info_format_workingtree')
204
297
                l.set_text(self.ret['format']['workingtree'])
205
 
                ll.set_markup('<b>' + ll.get_text() + '</b>')
206
298
                ll.show()
207
299
                l.show()
208
300
                if not display:
213
305
                ll = self.glade.get_widget('label_info_format_branch_label')
214
306
                l = self.glade.get_widget('label_info_format_branch')
215
307
                l.set_text(self.ret['format']['branch'])
216
 
                ll.set_markup('<b>' + ll.get_text() + '</b>')
217
308
                ll.show()
218
309
                l.show()
219
310
                if not display:
224
315
                ll = self.glade.get_widget('label_info_format_repository_label')
225
316
                l = self.glade.get_widget('label_info_format_repository')
226
317
                l.set_text(self.ret['format']['repository'])
227
 
                ll.set_markup('<b>' + ll.get_text() + '</b>')
228
318
                ll.show()
229
319
                l.show()
230
320
                if not display:
239
329
                ll = self.glade.get_widget('label_info_locking_workingtree_label')
240
330
                l = self.glade.get_widget('label_info_locking_workingtree')
241
331
                l.set_text(self.ret['locking']['workingtree'])
242
 
                ll.set_markup('<b>' + ll.get_text() + '</b>')
243
332
                ll.show()
244
333
                l.show()
245
334
                if not display:
250
339
                ll = self.glade.get_widget('label_info_locking_branch_label')
251
340
                l = self.glade.get_widget('label_info_locking_branch')
252
341
                l.set_text(self.ret['locking']['branch'])
253
 
                ll.set_markup('<b>' + ll.get_text() + '</b>')
254
342
                ll.show()
255
343
                l.show()
256
344
                if not display:
261
349
                ll = self.glade.get_widget('label_info_locking_repository_label')
262
350
                l = self.glade.get_widget('label_info_locking_repository')
263
351
                l.set_text(self.ret['locking']['repository'])
264
 
                ll.set_markup('<b>' + ll.get_text() + '</b>')
265
352
                ll.show()
266
353
                l.show()
267
354
                if not display:
304
391
                ll = self.glade.get_widget('label_info_wtstats_unchanged_label')
305
392
                l = self.glade.get_widget('label_info_wtstats_unchanged')
306
393
                l.set_text(str(self.ret['wtstats']['unchanged']))
307
 
                ll.set_markup('<b>' + ll.get_text() + '</b>')
308
394
                ll.show()
309
395
                l.show()
310
396
                if not display:
315
401
                ll = self.glade.get_widget('label_info_wtstats_modified_label')
316
402
                l = self.glade.get_widget('label_info_wtstats_modified')
317
403
                l.set_text(str(self.ret['wtstats']['modified']))
318
 
                ll.set_markup('<b>' + ll.get_text() + '</b>')
319
404
                ll.show()
320
405
                l.show()
321
406
                if not display:
326
411
                ll = self.glade.get_widget('label_info_wtstats_added_label')
327
412
                l = self.glade.get_widget('label_info_wtstats_added')
328
413
                l.set_text(str(self.ret['wtstats']['added']))
329
 
                ll.set_markup('<b>' + ll.get_text() + '</b>')
330
414
                ll.show()
331
415
                l.show()
332
416
                if not display:
337
421
                ll = self.glade.get_widget('label_info_wtstats_removed_label')
338
422
                l = self.glade.get_widget('label_info_wtstats_removed')
339
423
                l.set_text(str(self.ret['wtstats']['removed']))
340
 
                ll.set_markup('<b>' + ll.get_text() + '</b>')
341
424
                ll.show()
342
425
                l.show()
343
426
                if not display:
348
431
                ll = self.glade.get_widget('label_info_wtstats_renamed_label')
349
432
                l = self.glade.get_widget('label_info_wtstats_renamed')
350
433
                l.set_text(str(self.ret['wtstats']['renamed']))
351
 
                ll.set_markup('<b>' + ll.get_text() + '</b>')
352
434
                ll.show()
353
435
                l.show()
354
436
                if not display:
359
441
                ll = self.glade.get_widget('label_info_wtstats_unknown_label')
360
442
                l = self.glade.get_widget('label_info_wtstats_unknown')
361
443
                l.set_text(str(self.ret['wtstats']['unknown']))
362
 
                ll.set_markup('<b>' + ll.get_text() + '</b>')
363
444
                ll.show()
364
445
                l.show()
365
446
                if not display:
370
451
                ll = self.glade.get_widget('label_info_wtstats_ignored_label')
371
452
                l = self.glade.get_widget('label_info_wtstats_ignored')
372
453
                l.set_text(str(self.ret['wtstats']['ignored']))
373
 
                ll.set_markup('<b>' + ll.get_text() + '</b>')
374
454
                ll.show()
375
455
                l.show()
376
456
                if not display:
381
461
                ll = self.glade.get_widget('label_info_wtstats_subdirs_label')
382
462
                l = self.glade.get_widget('label_info_wtstats_subdirs')
383
463
                l.set_text(str(self.ret['wtstats']['subdirs']))
384
 
                ll.set_markup('<b>' + ll.get_text() + '</b>')
385
464
                ll.show()
386
465
                l.show()
387
466
                if not display:
396
475
                ll = self.glade.get_widget('label_info_brstats_revno_label')
397
476
                l = self.glade.get_widget('label_info_brstats_revno')
398
477
                l.set_text(str(self.ret['brstats']['revno']))
399
 
                ll.set_markup('<b>' + ll.get_text() + '</b>')
400
478
                ll.show()
401
479
                l.show()
402
480
                if not display:
407
485
                ll = self.glade.get_widget('label_info_brstats_commiters_label')
408
486
                l = self.glade.get_widget('label_info_brstats_commiters')
409
487
                l.set_text(str(self.ret['brstats']['commiters']))
410
 
                ll.set_markup('<b>' + ll.get_text() + '</b>')
411
488
                ll.show()
412
489
                l.show()
413
490
                if not display:
418
495
                ll = self.glade.get_widget('label_info_brstats_age_label')
419
496
                l = self.glade.get_widget('label_info_brstats_age')
420
497
                l.set_text('%d days' % self.ret['brstats']['age'])
421
 
                ll.set_markup('<b>' + ll.get_text() + '</b>')
422
498
                ll.show()
423
499
                l.show()
424
500
                if not display:
429
505
                ll = self.glade.get_widget('label_info_brstats_firstrev_label')
430
506
                l = self.glade.get_widget('label_info_brstats_firstrev')
431
507
                l.set_text(self.ret['brstats']['firstrev'])
432
 
                ll.set_markup('<b>' + ll.get_text() + '</b>')
433
508
                ll.show()
434
509
                l.show()
435
510
                if not display:
440
515
                ll = self.glade.get_widget('label_info_brstats_lastrev_label')
441
516
                l = self.glade.get_widget('label_info_brstats_lastrev')
442
517
                l.set_text(self.ret['brstats']['lastrev'])
443
 
                ll.set_markup('<b>' + ll.get_text() + '</b>')
444
518
                ll.show()
445
519
                l.show()
446
520
                if not display:
455
529
                ll = self.glade.get_widget('label_info_repstats_revisions_label')
456
530
                l = self.glade.get_widget('label_info_repstats_revisions')
457
531
                l.set_text(str(self.ret['repstats']['revisions']))
458
 
                ll.set_markup('<b>' + ll.get_text() + '</b>')
459
532
                ll.show()
460
533
                l.show()
461
534
                if not display:
466
539
                ll = self.glade.get_widget('label_info_repstats_size_label')
467
540
                l = self.glade.get_widget('label_info_repstats_size')
468
541
                l.set_text('%d KiB' % (self.ret['repstats']['size'] / 1024))
469
 
                ll.set_markup('<b>' + ll.get_text() + '</b>')
470
542
                ll.show()
471
543
                l.show()
472
544
                if not display:
482
554
    def display(self):
483
555
        """ Display the Informations window. """
484
556
        if self.notbranch:
485
 
            self.dialog.error_dialog(_('Directory is not a branch'),
486
 
                                     _('You can perform this action only in a branch.'))
 
557
            error_dialog(_i18n('Directory is not a branch'),
 
558
                         _i18n('You can perform this action only in a branch.'))
487
559
            self.close()
488
560
        else:
489
561
            self.window.show()