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
26
import bzrlib.errors as errors
28
from bzrlib.plugins.gtk import _i18n
29
from bzrlib.plugins.gtk.dialog import error_dialog
30
from guifiles import GLADEFILENAME
34
""" Get info about branch, working tree, and repository
36
:param location: the location of the branch/working tree/repository
38
:return: the information in dictionary format
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
75
import bzrlib.bzrdir as bzrdir
81
a_bzrdir = bzrdir.BzrDir.open_containing(location)[0]
82
except errors.NotBranchError:
83
raise errors.NotBranchError(location)
86
working = a_bzrdir.open_workingtree()
89
branch = working.branch
90
repository = branch.repository
91
control = working.bzrdir
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)
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)
107
except (errors.NoWorkingTree, errors.NotLocalUrl):
111
branch = a_bzrdir.open_branch()
112
repository = branch.repository
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)
127
except errors.NotBranchError:
131
repository = a_bzrdir.open_repository()
132
repository.lock_read()
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)
142
except errors.NoRepositoryPresent:
147
""" Display Informations window and perform the needed actions. """
148
def __init__(self, branch):
149
""" Initialize the Informations window. """
150
self.glade = gtk.glade.XML(GLADEFILENAME, 'window_info', 'olive-gtk')
152
# Get the Informations window widget
153
self.window = self.glade.get_widget('window_info')
155
# Check if current location is a branch
156
self.notbranch = False
158
self.ret = info(branch.base)
159
except errors.NotBranchError:
160
self.notbranch = True
163
# Dictionary for signal_autoconnect
164
dic = { "on_button_info_close_clicked": self.close,
165
"on_expander_info_location_activate": self.activate,
166
"on_expander_info_related_activate": self.activate,
167
"on_expander_info_format_activate": self.activate,
168
"on_expander_info_locking_activate": self.activate,
169
"on_expander_info_missing_activate": self.activate,
170
"on_expander_info_wtstats_activate": self.activate,
171
"on_expander_info_brstats_activate": self.activate,
172
"on_expander_info_repstats_activate": self.activate }
174
# Connect the signals to the handlers
175
self.glade.signal_autoconnect(dic)
177
# Generate status output
178
self._generate_info()
180
def _generate_info(self):
181
""" Generate 'bzr info' output. """
183
if self.ret.has_key('location'):
185
e = self.glade.get_widget('expander_info_location')
186
if self.ret['location'].has_key('lightcoroot'):
187
ll = self.glade.get_widget('label_info_location_lightcoroot_label')
188
l = self.glade.get_widget('label_info_location_lightcoroot')
189
l.set_text(self.ret['location']['lightcoroot'])
196
if self.ret['location'].has_key('sharedrepo'):
197
ll = self.glade.get_widget('label_info_location_sharedrepo_label')
198
l = self.glade.get_widget('label_info_location_sharedrepo')
199
l.set_text(self.ret['location']['sharedrepo'])
206
if self.ret['location'].has_key('repobranch'):
207
ll = self.glade.get_widget('label_info_location_repobranch_label')
208
l = self.glade.get_widget('label_info_location_repobranch')
209
l.set_text(self.ret['location']['repobranch'])
216
if self.ret['location'].has_key('cobranch'):
217
ll = self.glade.get_widget('label_info_location_cobranch_label')
218
l = self.glade.get_widget('label_info_location_cobranch')
219
l.set_text(self.ret['location']['cobranch'])
226
if self.ret['location'].has_key('repoco'):
227
ll = self.glade.get_widget('label_info_location_repoco_label')
228
l = self.glade.get_widget('label_info_location_repoco')
229
l.set_text(self.ret['location']['repoco'])
236
if self.ret['location'].has_key('coroot'):
237
ll = self.glade.get_widget('label_info_location_coroot_label')
238
l = self.glade.get_widget('label_info_location_coroot')
239
l.set_text(self.ret['location']['coroot'])
246
if self.ret['location'].has_key('branchroot'):
247
ll = self.glade.get_widget('label_info_location_branchroot_label')
248
l = self.glade.get_widget('label_info_location_branchroot')
249
l.set_text(self.ret['location']['branchroot'])
257
if self.ret.has_key('related'):
259
e = self.glade.get_widget('expander_info_related')
260
if self.ret['related'].has_key('parentbranch'):
261
ll = self.glade.get_widget('label_info_related_parentbranch_label')
262
l = self.glade.get_widget('label_info_related_parentbranch')
263
l.set_text(self.ret['related']['parentbranch'])
270
if self.ret['related'].has_key('publishbranch'):
271
ll = self.glade.get_widget('label_info_related_publishbranch_label')
272
l = self.glade.get_widget('label_info_related_publishbranch')
273
l.set_text(self.ret['related']['publishbranch'])
281
if self.ret.has_key('format'):
283
e = self.glade.get_widget('expander_info_format')
284
if self.ret['format'].has_key('control'):
285
ll = self.glade.get_widget('label_info_format_control_label')
286
l = self.glade.get_widget('label_info_format_control')
287
l.set_text(self.ret['format']['control'])
294
if self.ret['format'].has_key('workingtree'):
295
ll = self.glade.get_widget('label_info_format_workingtree_label')
296
l = self.glade.get_widget('label_info_format_workingtree')
297
l.set_text(self.ret['format']['workingtree'])
304
if self.ret['format'].has_key('branch'):
305
ll = self.glade.get_widget('label_info_format_branch_label')
306
l = self.glade.get_widget('label_info_format_branch')
307
l.set_text(self.ret['format']['branch'])
314
if self.ret['format'].has_key('repository'):
315
ll = self.glade.get_widget('label_info_format_repository_label')
316
l = self.glade.get_widget('label_info_format_repository')
317
l.set_text(self.ret['format']['repository'])
325
if self.ret.has_key('locking'):
327
e = self.glade.get_widget('expander_info_locking')
328
if self.ret['locking'].has_key('workingtree'):
329
ll = self.glade.get_widget('label_info_locking_workingtree_label')
330
l = self.glade.get_widget('label_info_locking_workingtree')
331
l.set_text(self.ret['locking']['workingtree'])
338
if self.ret['locking'].has_key('branch'):
339
ll = self.glade.get_widget('label_info_locking_branch_label')
340
l = self.glade.get_widget('label_info_locking_branch')
341
l.set_text(self.ret['locking']['branch'])
348
if self.ret['locking'].has_key('repository'):
349
ll = self.glade.get_widget('label_info_locking_repository_label')
350
l = self.glade.get_widget('label_info_locking_repository')
351
l.set_text(self.ret['locking']['repository'])
358
# missing - temporary disabled
360
if self.ret.has_key('missing'):
362
e = self.glade.get_widget('expander_info_missing')
363
if self.ret['missing'].has_key('branch'):
364
ll = self.glade.get_widget('label_info_missing_branch_label')
365
l = self.glade.get_widget('label_info_missing_branch')
366
l.set_text(self.ret['missing']['branch'])
367
ll.set_markup('<b>' + ll.get_text() + '</b>')
374
if self.ret['missing'].has_key('workingtree'):
375
ll = self.glade.get_widget('label_info_missing_workingtree_label')
376
l = self.glade.get_widget('label_info_missing_workingtree')
377
l.set_text(self.ret['missing']['branch'])
378
ll.set_markup('<b>' + ll.get_text() + '</b>')
387
if self.ret.has_key('wtstats'):
389
e = self.glade.get_widget('expander_info_wtstats')
390
if self.ret['wtstats'].has_key('unchanged'):
391
ll = self.glade.get_widget('label_info_wtstats_unchanged_label')
392
l = self.glade.get_widget('label_info_wtstats_unchanged')
393
l.set_text(str(self.ret['wtstats']['unchanged']))
400
if self.ret['wtstats'].has_key('modified'):
401
ll = self.glade.get_widget('label_info_wtstats_modified_label')
402
l = self.glade.get_widget('label_info_wtstats_modified')
403
l.set_text(str(self.ret['wtstats']['modified']))
410
if self.ret['wtstats'].has_key('added'):
411
ll = self.glade.get_widget('label_info_wtstats_added_label')
412
l = self.glade.get_widget('label_info_wtstats_added')
413
l.set_text(str(self.ret['wtstats']['added']))
420
if self.ret['wtstats'].has_key('removed'):
421
ll = self.glade.get_widget('label_info_wtstats_removed_label')
422
l = self.glade.get_widget('label_info_wtstats_removed')
423
l.set_text(str(self.ret['wtstats']['removed']))
430
if self.ret['wtstats'].has_key('renamed'):
431
ll = self.glade.get_widget('label_info_wtstats_renamed_label')
432
l = self.glade.get_widget('label_info_wtstats_renamed')
433
l.set_text(str(self.ret['wtstats']['renamed']))
440
if self.ret['wtstats'].has_key('unknown'):
441
ll = self.glade.get_widget('label_info_wtstats_unknown_label')
442
l = self.glade.get_widget('label_info_wtstats_unknown')
443
l.set_text(str(self.ret['wtstats']['unknown']))
450
if self.ret['wtstats'].has_key('ignored'):
451
ll = self.glade.get_widget('label_info_wtstats_ignored_label')
452
l = self.glade.get_widget('label_info_wtstats_ignored')
453
l.set_text(str(self.ret['wtstats']['ignored']))
460
if self.ret['wtstats'].has_key('subdirs'):
461
ll = self.glade.get_widget('label_info_wtstats_subdirs_label')
462
l = self.glade.get_widget('label_info_wtstats_subdirs')
463
l.set_text(str(self.ret['wtstats']['subdirs']))
471
if self.ret.has_key('brstats'):
473
e = self.glade.get_widget('expander_info_brstats')
474
if self.ret['brstats'].has_key('revno'):
475
ll = self.glade.get_widget('label_info_brstats_revno_label')
476
l = self.glade.get_widget('label_info_brstats_revno')
477
l.set_text(str(self.ret['brstats']['revno']))
484
if self.ret['brstats'].has_key('commiters'):
485
ll = self.glade.get_widget('label_info_brstats_commiters_label')
486
l = self.glade.get_widget('label_info_brstats_commiters')
487
l.set_text(str(self.ret['brstats']['commiters']))
494
if self.ret['brstats'].has_key('age'):
495
ll = self.glade.get_widget('label_info_brstats_age_label')
496
l = self.glade.get_widget('label_info_brstats_age')
497
l.set_text('%d days' % self.ret['brstats']['age'])
504
if self.ret['brstats'].has_key('firstrev'):
505
ll = self.glade.get_widget('label_info_brstats_firstrev_label')
506
l = self.glade.get_widget('label_info_brstats_firstrev')
507
l.set_text(self.ret['brstats']['firstrev'])
514
if self.ret['brstats'].has_key('lastrev'):
515
ll = self.glade.get_widget('label_info_brstats_lastrev_label')
516
l = self.glade.get_widget('label_info_brstats_lastrev')
517
l.set_text(self.ret['brstats']['lastrev'])
525
if self.ret.has_key('repstats'):
527
e = self.glade.get_widget('expander_info_repstats')
528
if self.ret['repstats'].has_key('revisions'):
529
ll = self.glade.get_widget('label_info_repstats_revisions_label')
530
l = self.glade.get_widget('label_info_repstats_revisions')
531
l.set_text(str(self.ret['repstats']['revisions']))
538
if self.ret['repstats'].has_key('size'):
539
ll = self.glade.get_widget('label_info_repstats_size_label')
540
l = self.glade.get_widget('label_info_repstats_size')
541
l.set_text('%d KiB' % (self.ret['repstats']['size'] / 1024))
549
def activate(self, expander):
550
""" Redraw the window. """
551
self.window.resize(50, 50)
552
self.window.queue_resize()
555
""" Display the Informations window. """
557
error_dialog(_i18n('Directory is not a branch'),
558
_i18n('You can perform this action only in a branch.'))
563
def close(self, widget=None):
564
self.window.destroy()