1
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic) <szilveszter.farkas@gmail.com>
3
# This program is free software; you can redistribute it and/or modify
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
# GNU General Public License for more details.
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
32
import bzrlib.errors as errors
35
""" Get info about branch, working tree, and repository
37
:param location: the location of the branch/working tree/repository
39
:return: the information in dictionary format
41
The following informations are delivered (if available):
42
ret['location']['lightcoroot']: Light checkout root
43
ret['location']['sharedrepo']: Shared repository
44
ret['location']['repobranch']: Repository branch
45
ret['location']['cobranch']: Checkout of branch
46
ret['location']['repoco']: Repository checkout
47
ret['location']['coroot']: Checkout root
48
ret['location']['branchroot']: Branch root
49
ret['related']['parentbranch']: Parent branch
50
ret['related']['publishbranch']: Publish to branch
51
ret['format']['control']: Control format
52
ret['format']['workingtree']: Working tree format
53
ret['format']['branch']: Branch format
54
ret['format']['repository']: Repository format
55
ret['locking']['workingtree']: Working tree lock status
56
ret['locking']['branch']: Branch lock status
57
ret['locking']['repository']: Repository lock status
58
ret['missing']['branch']: Missing revisions in branch
59
ret['missing']['workingtree']: Missing revisions in working tree
60
ret['wtstats']['unchanged']: Unchanged files
61
ret['wtstats']['modified']: Modified files
62
ret['wtstats']['added']: Added files
63
ret['wtstats']['removed']: Removed files
64
ret['wtstats']['renamed']: Renamed files
65
ret['wtstats']['unknown']: Unknown files
66
ret['wtstats']['ignored']: Ingnored files
67
ret['wtstats']['subdirs']: Versioned subdirectories
68
ret['brstats']['revno']: Revisions in branch
69
ret['brstats']['commiters']: Number of commiters
70
ret['brstats']['age']: Age of branch in days
71
ret['brstats']['firstrev']: Time of first revision
72
ret['brstats']['lastrev']: Time of last revision
73
ret['repstats']['revisions']: Revisions in repository
74
ret['repstats']['size']: Size of repository in bytes
76
import bzrlib.bzrdir as bzrdir
82
a_bzrdir = bzrdir.BzrDir.open_containing(location)[0]
83
except errors.NotBranchError:
84
raise NotBranchError(location)
87
working = a_bzrdir.open_workingtree()
90
branch = working.branch
91
repository = branch.repository
92
control = working.bzrdir
94
ret['location'] = info_helper.get_location_info(repository, branch, working)
95
ret['related'] = info_helper.get_related_info(branch)
96
ret['format'] = info_helper.get_format_info(control, repository, branch, working)
97
ret['locking'] = info_helper.get_locking_info(repository, branch, working)
99
ret['missing']['branch'] = info_helper.get_missing_revisions_branch(branch)
100
ret['missing']['workingtree'] = info_helper.get_missing_revisions_working(working)
101
ret['wtstats'] = info_helper.get_working_stats(working)
102
ret['brstats'] = info_helper.get_branch_stats(branch)
103
ret['repstats'] = info_helper.get_repository_stats(repository)
108
except (errors.NoWorkingTree, errors.NotLocalUrl):
112
branch = a_bzrdir.open_branch()
115
ret['location'] = info_helper.get_location_info(repository, branch)
116
ret['related'] = info_helper.get_related_info(branch)
117
ret['format'] = info_helper.get_format_info(control, repository, branch)
118
ret['locking'] = info_helper.get_locking_info(repository, branch)
119
ret['missing']['branch'] = info_helper.get_missing_revisions_branch(branch)
120
ret['brstats'] = info_helper.get_branch_stats(branch)
121
ret['repstats'] = info_helper.get_repository_stats(repository)
126
except errors.NotBranchError:
130
repository = a_bzrdir.open_repository()
131
repository.lock_read()
133
ret['location'] = info_helper.get_location_info(repository)
134
ret['format'] = info_helper.get_format_info(control, repository)
135
ret['locking'] = info_helper.get_locking_info(repository)
136
ret['repstats'] = info_helper.get_repository_stats(repository)
141
except errors.NoRepositoryPresent:
146
""" Display Informations window and perform the needed actions. """
147
def __init__(self, gladefile, comm):
148
""" Initialize the Informations window. """
149
self.gladefile = gladefile
150
self.glade = gtk.glade.XML(self.gladefile, 'window_info', 'olive-gtk')
152
# Communication object
155
# Get the Informations window widget
156
self.window = self.glade.get_widget('window_info')
158
# Check if current location is a branch
159
self.notbranch = False
161
self.ret = info(self.comm.get_path())
162
except errors.NotBranchError:
163
self.notbranch = True
166
# Dictionary for signal_autoconnect
167
dic = { "on_button_info_close_clicked": self.close,
168
"on_expander_info_location_activate": self.activate,
169
"on_expander_info_related_activate": self.activate,
170
"on_expander_info_format_activate": self.activate,
171
"on_expander_info_locking_activate": self.activate,
172
"on_expander_info_missing_activate": self.activate,
173
"on_expander_info_wtstats_activate": self.activate,
174
"on_expander_info_brstats_activate": self.activate,
175
"on_expander_info_repstats_activate": self.activate }
177
# Connect the signals to the handlers
178
self.glade.signal_autoconnect(dic)
180
# Generate status output
181
self._generate_info()
183
def _generate_info(self):
184
""" Generate 'bzr info' output. """
186
if self.ret.has_key('location'):
188
e = self.glade.get_widget('expander_info_location')
189
if self.ret['location'].has_key('lightcoroot'):
190
ll = self.glade.get_widget('label_info_location_lightcoroot_label')
191
l = self.glade.get_widget('label_info_location_lightcoroot')
192
l.set_text(self.ret['location']['lightcoroot'])
199
if self.ret['location'].has_key('sharedrepo'):
200
ll = self.glade.get_widget('label_info_location_sharedrepo_label')
201
l = self.glade.get_widget('label_info_location_sharedrepo')
202
l.set_text(self.ret['location']['sharedrepo'])
209
if self.ret['location'].has_key('repobranch'):
210
ll = self.glade.get_widget('label_info_location_repobranch_label')
211
l = self.glade.get_widget('label_info_location_repobranch')
212
l.set_text(self.ret['location']['repobranch'])
219
if self.ret['location'].has_key('cobranch'):
220
ll = self.glade.get_widget('label_info_location_cobranch_label')
221
l = self.glade.get_widget('label_info_location_cobranch')
222
l.set_text(self.ret['location']['cobranch'])
229
if self.ret['location'].has_key('repoco'):
230
ll = self.glade.get_widget('label_info_location_repoco_label')
231
l = self.glade.get_widget('label_info_location_repoco')
232
l.set_text(self.ret['location']['repoco'])
239
if self.ret['location'].has_key('coroot'):
240
ll = self.glade.get_widget('label_info_location_coroot_label')
241
l = self.glade.get_widget('label_info_location_coroot')
242
l.set_text(self.ret['location']['coroot'])
249
if self.ret['location'].has_key('branchroot'):
250
ll = self.glade.get_widget('label_info_location_branchroot_label')
251
l = self.glade.get_widget('label_info_location_branchroot')
252
l.set_text(self.ret['location']['branchroot'])
260
if self.ret.has_key('related'):
262
e = self.glade.get_widget('expander_info_related')
263
if self.ret['related'].has_key('parentbranch'):
264
ll = self.glade.get_widget('label_info_related_parentbranch_label')
265
l = self.glade.get_widget('label_info_related_parentbranch')
266
l.set_text(self.ret['related']['parentbranch'])
273
if self.ret['related'].has_key('publishbranch'):
274
ll = self.glade.get_widget('label_info_related_publishbranch_label')
275
l = self.glade.get_widget('label_info_related_publishbranch')
276
l.set_text(self.ret['related']['publishbranch'])
284
if self.ret.has_key('format'):
286
e = self.glade.get_widget('expander_info_format')
287
if self.ret['format'].has_key('control'):
288
ll = self.glade.get_widget('label_info_format_control_label')
289
l = self.glade.get_widget('label_info_format_control')
290
l.set_text(self.ret['format']['control'])
297
if self.ret['format'].has_key('workingtree'):
298
ll = self.glade.get_widget('label_info_format_workingtree_label')
299
l = self.glade.get_widget('label_info_format_workingtree')
300
l.set_text(self.ret['format']['workingtree'])
307
if self.ret['format'].has_key('branch'):
308
ll = self.glade.get_widget('label_info_format_branch_label')
309
l = self.glade.get_widget('label_info_format_branch')
310
l.set_text(self.ret['format']['branch'])
317
if self.ret['format'].has_key('repository'):
318
ll = self.glade.get_widget('label_info_format_repository_label')
319
l = self.glade.get_widget('label_info_format_repository')
320
l.set_text(self.ret['format']['repository'])
328
if self.ret.has_key('locking'):
330
e = self.glade.get_widget('expander_info_locking')
331
if self.ret['locking'].has_key('workingtree'):
332
ll = self.glade.get_widget('label_info_locking_workingtree_label')
333
l = self.glade.get_widget('label_info_locking_workingtree')
334
l.set_text(self.ret['locking']['workingtree'])
341
if self.ret['locking'].has_key('branch'):
342
ll = self.glade.get_widget('label_info_locking_branch_label')
343
l = self.glade.get_widget('label_info_locking_branch')
344
l.set_text(self.ret['locking']['branch'])
351
if self.ret['locking'].has_key('repository'):
352
ll = self.glade.get_widget('label_info_locking_repository_label')
353
l = self.glade.get_widget('label_info_locking_repository')
354
l.set_text(self.ret['locking']['repository'])
361
# missing - temporary disabled
363
if self.ret.has_key('missing'):
365
e = self.glade.get_widget('expander_info_missing')
366
if self.ret['missing'].has_key('branch'):
367
ll = self.glade.get_widget('label_info_missing_branch_label')
368
l = self.glade.get_widget('label_info_missing_branch')
369
l.set_text(self.ret['missing']['branch'])
370
ll.set_markup('<b>' + ll.get_text() + '</b>')
377
if self.ret['missing'].has_key('workingtree'):
378
ll = self.glade.get_widget('label_info_missing_workingtree_label')
379
l = self.glade.get_widget('label_info_missing_workingtree')
380
l.set_text(self.ret['missing']['branch'])
381
ll.set_markup('<b>' + ll.get_text() + '</b>')
390
if self.ret.has_key('wtstats'):
392
e = self.glade.get_widget('expander_info_wtstats')
393
if self.ret['wtstats'].has_key('unchanged'):
394
ll = self.glade.get_widget('label_info_wtstats_unchanged_label')
395
l = self.glade.get_widget('label_info_wtstats_unchanged')
396
l.set_text(str(self.ret['wtstats']['unchanged']))
403
if self.ret['wtstats'].has_key('modified'):
404
ll = self.glade.get_widget('label_info_wtstats_modified_label')
405
l = self.glade.get_widget('label_info_wtstats_modified')
406
l.set_text(str(self.ret['wtstats']['modified']))
413
if self.ret['wtstats'].has_key('added'):
414
ll = self.glade.get_widget('label_info_wtstats_added_label')
415
l = self.glade.get_widget('label_info_wtstats_added')
416
l.set_text(str(self.ret['wtstats']['added']))
423
if self.ret['wtstats'].has_key('removed'):
424
ll = self.glade.get_widget('label_info_wtstats_removed_label')
425
l = self.glade.get_widget('label_info_wtstats_removed')
426
l.set_text(str(self.ret['wtstats']['removed']))
433
if self.ret['wtstats'].has_key('renamed'):
434
ll = self.glade.get_widget('label_info_wtstats_renamed_label')
435
l = self.glade.get_widget('label_info_wtstats_renamed')
436
l.set_text(str(self.ret['wtstats']['renamed']))
443
if self.ret['wtstats'].has_key('unknown'):
444
ll = self.glade.get_widget('label_info_wtstats_unknown_label')
445
l = self.glade.get_widget('label_info_wtstats_unknown')
446
l.set_text(str(self.ret['wtstats']['unknown']))
453
if self.ret['wtstats'].has_key('ignored'):
454
ll = self.glade.get_widget('label_info_wtstats_ignored_label')
455
l = self.glade.get_widget('label_info_wtstats_ignored')
456
l.set_text(str(self.ret['wtstats']['ignored']))
463
if self.ret['wtstats'].has_key('subdirs'):
464
ll = self.glade.get_widget('label_info_wtstats_subdirs_label')
465
l = self.glade.get_widget('label_info_wtstats_subdirs')
466
l.set_text(str(self.ret['wtstats']['subdirs']))
474
if self.ret.has_key('brstats'):
476
e = self.glade.get_widget('expander_info_brstats')
477
if self.ret['brstats'].has_key('revno'):
478
ll = self.glade.get_widget('label_info_brstats_revno_label')
479
l = self.glade.get_widget('label_info_brstats_revno')
480
l.set_text(str(self.ret['brstats']['revno']))
487
if self.ret['brstats'].has_key('commiters'):
488
ll = self.glade.get_widget('label_info_brstats_commiters_label')
489
l = self.glade.get_widget('label_info_brstats_commiters')
490
l.set_text(str(self.ret['brstats']['commiters']))
497
if self.ret['brstats'].has_key('age'):
498
ll = self.glade.get_widget('label_info_brstats_age_label')
499
l = self.glade.get_widget('label_info_brstats_age')
500
l.set_text('%d days' % self.ret['brstats']['age'])
507
if self.ret['brstats'].has_key('firstrev'):
508
ll = self.glade.get_widget('label_info_brstats_firstrev_label')
509
l = self.glade.get_widget('label_info_brstats_firstrev')
510
l.set_text(self.ret['brstats']['firstrev'])
517
if self.ret['brstats'].has_key('lastrev'):
518
ll = self.glade.get_widget('label_info_brstats_lastrev_label')
519
l = self.glade.get_widget('label_info_brstats_lastrev')
520
l.set_text(self.ret['brstats']['lastrev'])
528
if self.ret.has_key('repstats'):
530
e = self.glade.get_widget('expander_info_repstats')
531
if self.ret['repstats'].has_key('revisions'):
532
ll = self.glade.get_widget('label_info_repstats_revisions_label')
533
l = self.glade.get_widget('label_info_repstats_revisions')
534
l.set_text(str(self.ret['repstats']['revisions']))
541
if self.ret['repstats'].has_key('size'):
542
ll = self.glade.get_widget('label_info_repstats_size_label')
543
l = self.glade.get_widget('label_info_repstats_size')
544
l.set_text('%d KiB' % (self.ret['repstats']['size'] / 1024))
552
def activate(self, expander):
553
""" Redraw the window. """
554
self.window.resize(50, 50)
555
self.window.queue_resize()
558
""" Display the Informations window. """
560
error_dialog(_('Directory is not a branch'),
561
_('You can perform this action only in a branch.'))
566
def close(self, widget=None):
567
self.window.destroy()