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 dialog import error_dialog
29
from guifiles import GLADEFILENAME
33
""" Get info about branch, working tree, and repository
35
:param location: the location of the branch/working tree/repository
37
:return: the information in dictionary format
39
The following informations are delivered (if available):
40
ret['location']['lightcoroot']: Light checkout root
41
ret['location']['sharedrepo']: Shared repository
42
ret['location']['repobranch']: Repository branch
43
ret['location']['cobranch']: Checkout of branch
44
ret['location']['repoco']: Repository checkout
45
ret['location']['coroot']: Checkout root
46
ret['location']['branchroot']: Branch root
47
ret['related']['parentbranch']: Parent branch
48
ret['related']['publishbranch']: Publish to branch
49
ret['format']['control']: Control format
50
ret['format']['workingtree']: Working tree format
51
ret['format']['branch']: Branch format
52
ret['format']['repository']: Repository format
53
ret['locking']['workingtree']: Working tree lock status
54
ret['locking']['branch']: Branch lock status
55
ret['locking']['repository']: Repository lock status
56
ret['missing']['branch']: Missing revisions in branch
57
ret['missing']['workingtree']: Missing revisions in working tree
58
ret['wtstats']['unchanged']: Unchanged files
59
ret['wtstats']['modified']: Modified files
60
ret['wtstats']['added']: Added files
61
ret['wtstats']['removed']: Removed files
62
ret['wtstats']['renamed']: Renamed files
63
ret['wtstats']['unknown']: Unknown files
64
ret['wtstats']['ignored']: Ingnored files
65
ret['wtstats']['subdirs']: Versioned subdirectories
66
ret['brstats']['revno']: Revisions in branch
67
ret['brstats']['commiters']: Number of commiters
68
ret['brstats']['age']: Age of branch in days
69
ret['brstats']['firstrev']: Time of first revision
70
ret['brstats']['lastrev']: Time of last revision
71
ret['repstats']['revisions']: Revisions in repository
72
ret['repstats']['size']: Size of repository in bytes
74
import bzrlib.bzrdir as bzrdir
80
a_bzrdir = bzrdir.BzrDir.open_containing(location)[0]
81
except errors.NotBranchError:
82
raise errors.NotBranchError(location)
85
working = a_bzrdir.open_workingtree()
88
branch = working.branch
89
repository = branch.repository
90
control = working.bzrdir
92
ret['location'] = info_helper.get_location_info(repository, branch, working)
93
ret['related'] = info_helper.get_related_info(branch)
94
ret['format'] = info_helper.get_format_info(control, repository, branch, working)
95
ret['locking'] = info_helper.get_locking_info(repository, branch, working)
97
ret['missing']['branch'] = info_helper.get_missing_revisions_branch(branch)
98
ret['missing']['workingtree'] = info_helper.get_missing_revisions_working(working)
99
ret['wtstats'] = info_helper.get_working_stats(working)
100
ret['brstats'] = info_helper.get_branch_stats(branch)
101
ret['repstats'] = info_helper.get_repository_stats(repository)
106
except (errors.NoWorkingTree, errors.NotLocalUrl):
110
branch = a_bzrdir.open_branch()
113
ret['location'] = info_helper.get_location_info(repository, branch)
114
ret['related'] = info_helper.get_related_info(branch)
115
ret['format'] = info_helper.get_format_info(control, repository, branch)
116
ret['locking'] = info_helper.get_locking_info(repository, branch)
117
ret['missing']['branch'] = info_helper.get_missing_revisions_branch(branch)
118
ret['brstats'] = info_helper.get_branch_stats(branch)
119
ret['repstats'] = info_helper.get_repository_stats(repository)
124
except errors.NotBranchError:
128
repository = a_bzrdir.open_repository()
129
repository.lock_read()
131
ret['location'] = info_helper.get_location_info(repository)
132
ret['format'] = info_helper.get_format_info(control, repository)
133
ret['locking'] = info_helper.get_locking_info(repository)
134
ret['repstats'] = info_helper.get_repository_stats(repository)
139
except errors.NoRepositoryPresent:
144
""" Display Informations window and perform the needed actions. """
145
def __init__(self, wt):
146
""" Initialize the Informations window. """
147
self.glade = gtk.glade.XML(GLADEFILENAME, 'window_info', 'olive-gtk')
149
# Get the Informations window widget
150
self.window = self.glade.get_widget('window_info')
152
# Check if current location is a branch
153
self.notbranch = False
155
self.ret = info(wt.basedir)
156
except errors.NotBranchError:
157
self.notbranch = True
160
# Dictionary for signal_autoconnect
161
dic = { "on_button_info_close_clicked": self.close,
162
"on_expander_info_location_activate": self.activate,
163
"on_expander_info_related_activate": self.activate,
164
"on_expander_info_format_activate": self.activate,
165
"on_expander_info_locking_activate": self.activate,
166
"on_expander_info_missing_activate": self.activate,
167
"on_expander_info_wtstats_activate": self.activate,
168
"on_expander_info_brstats_activate": self.activate,
169
"on_expander_info_repstats_activate": self.activate }
171
# Connect the signals to the handlers
172
self.glade.signal_autoconnect(dic)
174
# Generate status output
175
self._generate_info()
177
def _generate_info(self):
178
""" Generate 'bzr info' output. """
180
if self.ret.has_key('location'):
182
e = self.glade.get_widget('expander_info_location')
183
if self.ret['location'].has_key('lightcoroot'):
184
ll = self.glade.get_widget('label_info_location_lightcoroot_label')
185
l = self.glade.get_widget('label_info_location_lightcoroot')
186
l.set_text(self.ret['location']['lightcoroot'])
193
if self.ret['location'].has_key('sharedrepo'):
194
ll = self.glade.get_widget('label_info_location_sharedrepo_label')
195
l = self.glade.get_widget('label_info_location_sharedrepo')
196
l.set_text(self.ret['location']['sharedrepo'])
203
if self.ret['location'].has_key('repobranch'):
204
ll = self.glade.get_widget('label_info_location_repobranch_label')
205
l = self.glade.get_widget('label_info_location_repobranch')
206
l.set_text(self.ret['location']['repobranch'])
213
if self.ret['location'].has_key('cobranch'):
214
ll = self.glade.get_widget('label_info_location_cobranch_label')
215
l = self.glade.get_widget('label_info_location_cobranch')
216
l.set_text(self.ret['location']['cobranch'])
223
if self.ret['location'].has_key('repoco'):
224
ll = self.glade.get_widget('label_info_location_repoco_label')
225
l = self.glade.get_widget('label_info_location_repoco')
226
l.set_text(self.ret['location']['repoco'])
233
if self.ret['location'].has_key('coroot'):
234
ll = self.glade.get_widget('label_info_location_coroot_label')
235
l = self.glade.get_widget('label_info_location_coroot')
236
l.set_text(self.ret['location']['coroot'])
243
if self.ret['location'].has_key('branchroot'):
244
ll = self.glade.get_widget('label_info_location_branchroot_label')
245
l = self.glade.get_widget('label_info_location_branchroot')
246
l.set_text(self.ret['location']['branchroot'])
254
if self.ret.has_key('related'):
256
e = self.glade.get_widget('expander_info_related')
257
if self.ret['related'].has_key('parentbranch'):
258
ll = self.glade.get_widget('label_info_related_parentbranch_label')
259
l = self.glade.get_widget('label_info_related_parentbranch')
260
l.set_text(self.ret['related']['parentbranch'])
267
if self.ret['related'].has_key('publishbranch'):
268
ll = self.glade.get_widget('label_info_related_publishbranch_label')
269
l = self.glade.get_widget('label_info_related_publishbranch')
270
l.set_text(self.ret['related']['publishbranch'])
278
if self.ret.has_key('format'):
280
e = self.glade.get_widget('expander_info_format')
281
if self.ret['format'].has_key('control'):
282
ll = self.glade.get_widget('label_info_format_control_label')
283
l = self.glade.get_widget('label_info_format_control')
284
l.set_text(self.ret['format']['control'])
291
if self.ret['format'].has_key('workingtree'):
292
ll = self.glade.get_widget('label_info_format_workingtree_label')
293
l = self.glade.get_widget('label_info_format_workingtree')
294
l.set_text(self.ret['format']['workingtree'])
301
if self.ret['format'].has_key('branch'):
302
ll = self.glade.get_widget('label_info_format_branch_label')
303
l = self.glade.get_widget('label_info_format_branch')
304
l.set_text(self.ret['format']['branch'])
311
if self.ret['format'].has_key('repository'):
312
ll = self.glade.get_widget('label_info_format_repository_label')
313
l = self.glade.get_widget('label_info_format_repository')
314
l.set_text(self.ret['format']['repository'])
322
if self.ret.has_key('locking'):
324
e = self.glade.get_widget('expander_info_locking')
325
if self.ret['locking'].has_key('workingtree'):
326
ll = self.glade.get_widget('label_info_locking_workingtree_label')
327
l = self.glade.get_widget('label_info_locking_workingtree')
328
l.set_text(self.ret['locking']['workingtree'])
335
if self.ret['locking'].has_key('branch'):
336
ll = self.glade.get_widget('label_info_locking_branch_label')
337
l = self.glade.get_widget('label_info_locking_branch')
338
l.set_text(self.ret['locking']['branch'])
345
if self.ret['locking'].has_key('repository'):
346
ll = self.glade.get_widget('label_info_locking_repository_label')
347
l = self.glade.get_widget('label_info_locking_repository')
348
l.set_text(self.ret['locking']['repository'])
355
# missing - temporary disabled
357
if self.ret.has_key('missing'):
359
e = self.glade.get_widget('expander_info_missing')
360
if self.ret['missing'].has_key('branch'):
361
ll = self.glade.get_widget('label_info_missing_branch_label')
362
l = self.glade.get_widget('label_info_missing_branch')
363
l.set_text(self.ret['missing']['branch'])
364
ll.set_markup('<b>' + ll.get_text() + '</b>')
371
if self.ret['missing'].has_key('workingtree'):
372
ll = self.glade.get_widget('label_info_missing_workingtree_label')
373
l = self.glade.get_widget('label_info_missing_workingtree')
374
l.set_text(self.ret['missing']['branch'])
375
ll.set_markup('<b>' + ll.get_text() + '</b>')
384
if self.ret.has_key('wtstats'):
386
e = self.glade.get_widget('expander_info_wtstats')
387
if self.ret['wtstats'].has_key('unchanged'):
388
ll = self.glade.get_widget('label_info_wtstats_unchanged_label')
389
l = self.glade.get_widget('label_info_wtstats_unchanged')
390
l.set_text(str(self.ret['wtstats']['unchanged']))
397
if self.ret['wtstats'].has_key('modified'):
398
ll = self.glade.get_widget('label_info_wtstats_modified_label')
399
l = self.glade.get_widget('label_info_wtstats_modified')
400
l.set_text(str(self.ret['wtstats']['modified']))
407
if self.ret['wtstats'].has_key('added'):
408
ll = self.glade.get_widget('label_info_wtstats_added_label')
409
l = self.glade.get_widget('label_info_wtstats_added')
410
l.set_text(str(self.ret['wtstats']['added']))
417
if self.ret['wtstats'].has_key('removed'):
418
ll = self.glade.get_widget('label_info_wtstats_removed_label')
419
l = self.glade.get_widget('label_info_wtstats_removed')
420
l.set_text(str(self.ret['wtstats']['removed']))
427
if self.ret['wtstats'].has_key('renamed'):
428
ll = self.glade.get_widget('label_info_wtstats_renamed_label')
429
l = self.glade.get_widget('label_info_wtstats_renamed')
430
l.set_text(str(self.ret['wtstats']['renamed']))
437
if self.ret['wtstats'].has_key('unknown'):
438
ll = self.glade.get_widget('label_info_wtstats_unknown_label')
439
l = self.glade.get_widget('label_info_wtstats_unknown')
440
l.set_text(str(self.ret['wtstats']['unknown']))
447
if self.ret['wtstats'].has_key('ignored'):
448
ll = self.glade.get_widget('label_info_wtstats_ignored_label')
449
l = self.glade.get_widget('label_info_wtstats_ignored')
450
l.set_text(str(self.ret['wtstats']['ignored']))
457
if self.ret['wtstats'].has_key('subdirs'):
458
ll = self.glade.get_widget('label_info_wtstats_subdirs_label')
459
l = self.glade.get_widget('label_info_wtstats_subdirs')
460
l.set_text(str(self.ret['wtstats']['subdirs']))
468
if self.ret.has_key('brstats'):
470
e = self.glade.get_widget('expander_info_brstats')
471
if self.ret['brstats'].has_key('revno'):
472
ll = self.glade.get_widget('label_info_brstats_revno_label')
473
l = self.glade.get_widget('label_info_brstats_revno')
474
l.set_text(str(self.ret['brstats']['revno']))
481
if self.ret['brstats'].has_key('commiters'):
482
ll = self.glade.get_widget('label_info_brstats_commiters_label')
483
l = self.glade.get_widget('label_info_brstats_commiters')
484
l.set_text(str(self.ret['brstats']['commiters']))
491
if self.ret['brstats'].has_key('age'):
492
ll = self.glade.get_widget('label_info_brstats_age_label')
493
l = self.glade.get_widget('label_info_brstats_age')
494
l.set_text('%d days' % self.ret['brstats']['age'])
501
if self.ret['brstats'].has_key('firstrev'):
502
ll = self.glade.get_widget('label_info_brstats_firstrev_label')
503
l = self.glade.get_widget('label_info_brstats_firstrev')
504
l.set_text(self.ret['brstats']['firstrev'])
511
if self.ret['brstats'].has_key('lastrev'):
512
ll = self.glade.get_widget('label_info_brstats_lastrev_label')
513
l = self.glade.get_widget('label_info_brstats_lastrev')
514
l.set_text(self.ret['brstats']['lastrev'])
522
if self.ret.has_key('repstats'):
524
e = self.glade.get_widget('expander_info_repstats')
525
if self.ret['repstats'].has_key('revisions'):
526
ll = self.glade.get_widget('label_info_repstats_revisions_label')
527
l = self.glade.get_widget('label_info_repstats_revisions')
528
l.set_text(str(self.ret['repstats']['revisions']))
535
if self.ret['repstats'].has_key('size'):
536
ll = self.glade.get_widget('label_info_repstats_size_label')
537
l = self.glade.get_widget('label_info_repstats_size')
538
l.set_text('%d KiB' % (self.ret['repstats']['size'] / 1024))
546
def activate(self, expander):
547
""" Redraw the window. """
548
self.window.resize(50, 50)
549
self.window.queue_resize()
552
""" Display the Informations window. """
554
error_dialog(_('Directory is not a branch'),
555
_('You can perform this action only in a branch.'))
560
def close(self, widget=None):
561
self.window.destroy()