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
30
import bzrlib.errors as errors
32
from olive import gladefile
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, comm):
148
""" Initialize the Informations window. """
149
self.glade = gtk.glade.XML(gladefile, 'window_info', 'olive-gtk')
151
# Communication object
154
# Get the Informations window widget
155
self.window = self.glade.get_widget('window_info')
157
# Check if current location is a branch
158
self.notbranch = False
160
self.ret = info(self.comm.get_path())
161
except errors.NotBranchError:
162
self.notbranch = True
165
# Dictionary for signal_autoconnect
166
dic = { "on_button_info_close_clicked": self.close,
167
"on_expander_info_location_activate": self.activate,
168
"on_expander_info_related_activate": self.activate,
169
"on_expander_info_format_activate": self.activate,
170
"on_expander_info_locking_activate": self.activate,
171
"on_expander_info_missing_activate": self.activate,
172
"on_expander_info_wtstats_activate": self.activate,
173
"on_expander_info_brstats_activate": self.activate,
174
"on_expander_info_repstats_activate": self.activate }
176
# Connect the signals to the handlers
177
self.glade.signal_autoconnect(dic)
179
# Generate status output
180
self._generate_info()
182
def _generate_info(self):
183
""" Generate 'bzr info' output. """
185
if self.ret.has_key('location'):
187
e = self.glade.get_widget('expander_info_location')
188
if self.ret['location'].has_key('lightcoroot'):
189
ll = self.glade.get_widget('label_info_location_lightcoroot_label')
190
l = self.glade.get_widget('label_info_location_lightcoroot')
191
l.set_text(self.ret['location']['lightcoroot'])
198
if self.ret['location'].has_key('sharedrepo'):
199
ll = self.glade.get_widget('label_info_location_sharedrepo_label')
200
l = self.glade.get_widget('label_info_location_sharedrepo')
201
l.set_text(self.ret['location']['sharedrepo'])
208
if self.ret['location'].has_key('repobranch'):
209
ll = self.glade.get_widget('label_info_location_repobranch_label')
210
l = self.glade.get_widget('label_info_location_repobranch')
211
l.set_text(self.ret['location']['repobranch'])
218
if self.ret['location'].has_key('cobranch'):
219
ll = self.glade.get_widget('label_info_location_cobranch_label')
220
l = self.glade.get_widget('label_info_location_cobranch')
221
l.set_text(self.ret['location']['cobranch'])
228
if self.ret['location'].has_key('repoco'):
229
ll = self.glade.get_widget('label_info_location_repoco_label')
230
l = self.glade.get_widget('label_info_location_repoco')
231
l.set_text(self.ret['location']['repoco'])
238
if self.ret['location'].has_key('coroot'):
239
ll = self.glade.get_widget('label_info_location_coroot_label')
240
l = self.glade.get_widget('label_info_location_coroot')
241
l.set_text(self.ret['location']['coroot'])
248
if self.ret['location'].has_key('branchroot'):
249
ll = self.glade.get_widget('label_info_location_branchroot_label')
250
l = self.glade.get_widget('label_info_location_branchroot')
251
l.set_text(self.ret['location']['branchroot'])
259
if self.ret.has_key('related'):
261
e = self.glade.get_widget('expander_info_related')
262
if self.ret['related'].has_key('parentbranch'):
263
ll = self.glade.get_widget('label_info_related_parentbranch_label')
264
l = self.glade.get_widget('label_info_related_parentbranch')
265
l.set_text(self.ret['related']['parentbranch'])
272
if self.ret['related'].has_key('publishbranch'):
273
ll = self.glade.get_widget('label_info_related_publishbranch_label')
274
l = self.glade.get_widget('label_info_related_publishbranch')
275
l.set_text(self.ret['related']['publishbranch'])
283
if self.ret.has_key('format'):
285
e = self.glade.get_widget('expander_info_format')
286
if self.ret['format'].has_key('control'):
287
ll = self.glade.get_widget('label_info_format_control_label')
288
l = self.glade.get_widget('label_info_format_control')
289
l.set_text(self.ret['format']['control'])
296
if self.ret['format'].has_key('workingtree'):
297
ll = self.glade.get_widget('label_info_format_workingtree_label')
298
l = self.glade.get_widget('label_info_format_workingtree')
299
l.set_text(self.ret['format']['workingtree'])
306
if self.ret['format'].has_key('branch'):
307
ll = self.glade.get_widget('label_info_format_branch_label')
308
l = self.glade.get_widget('label_info_format_branch')
309
l.set_text(self.ret['format']['branch'])
316
if self.ret['format'].has_key('repository'):
317
ll = self.glade.get_widget('label_info_format_repository_label')
318
l = self.glade.get_widget('label_info_format_repository')
319
l.set_text(self.ret['format']['repository'])
327
if self.ret.has_key('locking'):
329
e = self.glade.get_widget('expander_info_locking')
330
if self.ret['locking'].has_key('workingtree'):
331
ll = self.glade.get_widget('label_info_locking_workingtree_label')
332
l = self.glade.get_widget('label_info_locking_workingtree')
333
l.set_text(self.ret['locking']['workingtree'])
340
if self.ret['locking'].has_key('branch'):
341
ll = self.glade.get_widget('label_info_locking_branch_label')
342
l = self.glade.get_widget('label_info_locking_branch')
343
l.set_text(self.ret['locking']['branch'])
350
if self.ret['locking'].has_key('repository'):
351
ll = self.glade.get_widget('label_info_locking_repository_label')
352
l = self.glade.get_widget('label_info_locking_repository')
353
l.set_text(self.ret['locking']['repository'])
360
# missing - temporary disabled
362
if self.ret.has_key('missing'):
364
e = self.glade.get_widget('expander_info_missing')
365
if self.ret['missing'].has_key('branch'):
366
ll = self.glade.get_widget('label_info_missing_branch_label')
367
l = self.glade.get_widget('label_info_missing_branch')
368
l.set_text(self.ret['missing']['branch'])
369
ll.set_markup('<b>' + ll.get_text() + '</b>')
376
if self.ret['missing'].has_key('workingtree'):
377
ll = self.glade.get_widget('label_info_missing_workingtree_label')
378
l = self.glade.get_widget('label_info_missing_workingtree')
379
l.set_text(self.ret['missing']['branch'])
380
ll.set_markup('<b>' + ll.get_text() + '</b>')
389
if self.ret.has_key('wtstats'):
391
e = self.glade.get_widget('expander_info_wtstats')
392
if self.ret['wtstats'].has_key('unchanged'):
393
ll = self.glade.get_widget('label_info_wtstats_unchanged_label')
394
l = self.glade.get_widget('label_info_wtstats_unchanged')
395
l.set_text(str(self.ret['wtstats']['unchanged']))
402
if self.ret['wtstats'].has_key('modified'):
403
ll = self.glade.get_widget('label_info_wtstats_modified_label')
404
l = self.glade.get_widget('label_info_wtstats_modified')
405
l.set_text(str(self.ret['wtstats']['modified']))
412
if self.ret['wtstats'].has_key('added'):
413
ll = self.glade.get_widget('label_info_wtstats_added_label')
414
l = self.glade.get_widget('label_info_wtstats_added')
415
l.set_text(str(self.ret['wtstats']['added']))
422
if self.ret['wtstats'].has_key('removed'):
423
ll = self.glade.get_widget('label_info_wtstats_removed_label')
424
l = self.glade.get_widget('label_info_wtstats_removed')
425
l.set_text(str(self.ret['wtstats']['removed']))
432
if self.ret['wtstats'].has_key('renamed'):
433
ll = self.glade.get_widget('label_info_wtstats_renamed_label')
434
l = self.glade.get_widget('label_info_wtstats_renamed')
435
l.set_text(str(self.ret['wtstats']['renamed']))
442
if self.ret['wtstats'].has_key('unknown'):
443
ll = self.glade.get_widget('label_info_wtstats_unknown_label')
444
l = self.glade.get_widget('label_info_wtstats_unknown')
445
l.set_text(str(self.ret['wtstats']['unknown']))
452
if self.ret['wtstats'].has_key('ignored'):
453
ll = self.glade.get_widget('label_info_wtstats_ignored_label')
454
l = self.glade.get_widget('label_info_wtstats_ignored')
455
l.set_text(str(self.ret['wtstats']['ignored']))
462
if self.ret['wtstats'].has_key('subdirs'):
463
ll = self.glade.get_widget('label_info_wtstats_subdirs_label')
464
l = self.glade.get_widget('label_info_wtstats_subdirs')
465
l.set_text(str(self.ret['wtstats']['subdirs']))
473
if self.ret.has_key('brstats'):
475
e = self.glade.get_widget('expander_info_brstats')
476
if self.ret['brstats'].has_key('revno'):
477
ll = self.glade.get_widget('label_info_brstats_revno_label')
478
l = self.glade.get_widget('label_info_brstats_revno')
479
l.set_text(str(self.ret['brstats']['revno']))
486
if self.ret['brstats'].has_key('commiters'):
487
ll = self.glade.get_widget('label_info_brstats_commiters_label')
488
l = self.glade.get_widget('label_info_brstats_commiters')
489
l.set_text(str(self.ret['brstats']['commiters']))
496
if self.ret['brstats'].has_key('age'):
497
ll = self.glade.get_widget('label_info_brstats_age_label')
498
l = self.glade.get_widget('label_info_brstats_age')
499
l.set_text('%d days' % self.ret['brstats']['age'])
506
if self.ret['brstats'].has_key('firstrev'):
507
ll = self.glade.get_widget('label_info_brstats_firstrev_label')
508
l = self.glade.get_widget('label_info_brstats_firstrev')
509
l.set_text(self.ret['brstats']['firstrev'])
516
if self.ret['brstats'].has_key('lastrev'):
517
ll = self.glade.get_widget('label_info_brstats_lastrev_label')
518
l = self.glade.get_widget('label_info_brstats_lastrev')
519
l.set_text(self.ret['brstats']['lastrev'])
527
if self.ret.has_key('repstats'):
529
e = self.glade.get_widget('expander_info_repstats')
530
if self.ret['repstats'].has_key('revisions'):
531
ll = self.glade.get_widget('label_info_repstats_revisions_label')
532
l = self.glade.get_widget('label_info_repstats_revisions')
533
l.set_text(str(self.ret['repstats']['revisions']))
540
if self.ret['repstats'].has_key('size'):
541
ll = self.glade.get_widget('label_info_repstats_size_label')
542
l = self.glade.get_widget('label_info_repstats_size')
543
l.set_text('%d KiB' % (self.ret['repstats']['size'] / 1024))
551
def activate(self, expander):
552
""" Redraw the window. """
553
self.window.resize(50, 50)
554
self.window.queue_resize()
557
""" Display the Informations window. """
559
error_dialog(_('Directory is not a branch'),
560
_('You can perform this action only in a branch.'))
565
def close(self, widget=None):
566
self.window.destroy()