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, wt):
148
""" Initialize the Informations window. """
149
self.glade = gtk.glade.XML(gladefile, 'window_info', 'olive-gtk')
151
# Get the Informations window widget
152
self.window = self.glade.get_widget('window_info')
154
# Check if current location is a branch
155
self.notbranch = False
157
self.ret = info(wt.basedir)
158
except errors.NotBranchError:
159
self.notbranch = True
162
# Dictionary for signal_autoconnect
163
dic = { "on_button_info_close_clicked": self.close,
164
"on_expander_info_location_activate": self.activate,
165
"on_expander_info_related_activate": self.activate,
166
"on_expander_info_format_activate": self.activate,
167
"on_expander_info_locking_activate": self.activate,
168
"on_expander_info_missing_activate": self.activate,
169
"on_expander_info_wtstats_activate": self.activate,
170
"on_expander_info_brstats_activate": self.activate,
171
"on_expander_info_repstats_activate": self.activate }
173
# Connect the signals to the handlers
174
self.glade.signal_autoconnect(dic)
176
# Generate status output
177
self._generate_info()
179
def _generate_info(self):
180
""" Generate 'bzr info' output. """
182
if self.ret.has_key('location'):
184
e = self.glade.get_widget('expander_info_location')
185
if self.ret['location'].has_key('lightcoroot'):
186
ll = self.glade.get_widget('label_info_location_lightcoroot_label')
187
l = self.glade.get_widget('label_info_location_lightcoroot')
188
l.set_text(self.ret['location']['lightcoroot'])
195
if self.ret['location'].has_key('sharedrepo'):
196
ll = self.glade.get_widget('label_info_location_sharedrepo_label')
197
l = self.glade.get_widget('label_info_location_sharedrepo')
198
l.set_text(self.ret['location']['sharedrepo'])
205
if self.ret['location'].has_key('repobranch'):
206
ll = self.glade.get_widget('label_info_location_repobranch_label')
207
l = self.glade.get_widget('label_info_location_repobranch')
208
l.set_text(self.ret['location']['repobranch'])
215
if self.ret['location'].has_key('cobranch'):
216
ll = self.glade.get_widget('label_info_location_cobranch_label')
217
l = self.glade.get_widget('label_info_location_cobranch')
218
l.set_text(self.ret['location']['cobranch'])
225
if self.ret['location'].has_key('repoco'):
226
ll = self.glade.get_widget('label_info_location_repoco_label')
227
l = self.glade.get_widget('label_info_location_repoco')
228
l.set_text(self.ret['location']['repoco'])
235
if self.ret['location'].has_key('coroot'):
236
ll = self.glade.get_widget('label_info_location_coroot_label')
237
l = self.glade.get_widget('label_info_location_coroot')
238
l.set_text(self.ret['location']['coroot'])
245
if self.ret['location'].has_key('branchroot'):
246
ll = self.glade.get_widget('label_info_location_branchroot_label')
247
l = self.glade.get_widget('label_info_location_branchroot')
248
l.set_text(self.ret['location']['branchroot'])
256
if self.ret.has_key('related'):
258
e = self.glade.get_widget('expander_info_related')
259
if self.ret['related'].has_key('parentbranch'):
260
ll = self.glade.get_widget('label_info_related_parentbranch_label')
261
l = self.glade.get_widget('label_info_related_parentbranch')
262
l.set_text(self.ret['related']['parentbranch'])
269
if self.ret['related'].has_key('publishbranch'):
270
ll = self.glade.get_widget('label_info_related_publishbranch_label')
271
l = self.glade.get_widget('label_info_related_publishbranch')
272
l.set_text(self.ret['related']['publishbranch'])
280
if self.ret.has_key('format'):
282
e = self.glade.get_widget('expander_info_format')
283
if self.ret['format'].has_key('control'):
284
ll = self.glade.get_widget('label_info_format_control_label')
285
l = self.glade.get_widget('label_info_format_control')
286
l.set_text(self.ret['format']['control'])
293
if self.ret['format'].has_key('workingtree'):
294
ll = self.glade.get_widget('label_info_format_workingtree_label')
295
l = self.glade.get_widget('label_info_format_workingtree')
296
l.set_text(self.ret['format']['workingtree'])
303
if self.ret['format'].has_key('branch'):
304
ll = self.glade.get_widget('label_info_format_branch_label')
305
l = self.glade.get_widget('label_info_format_branch')
306
l.set_text(self.ret['format']['branch'])
313
if self.ret['format'].has_key('repository'):
314
ll = self.glade.get_widget('label_info_format_repository_label')
315
l = self.glade.get_widget('label_info_format_repository')
316
l.set_text(self.ret['format']['repository'])
324
if self.ret.has_key('locking'):
326
e = self.glade.get_widget('expander_info_locking')
327
if self.ret['locking'].has_key('workingtree'):
328
ll = self.glade.get_widget('label_info_locking_workingtree_label')
329
l = self.glade.get_widget('label_info_locking_workingtree')
330
l.set_text(self.ret['locking']['workingtree'])
337
if self.ret['locking'].has_key('branch'):
338
ll = self.glade.get_widget('label_info_locking_branch_label')
339
l = self.glade.get_widget('label_info_locking_branch')
340
l.set_text(self.ret['locking']['branch'])
347
if self.ret['locking'].has_key('repository'):
348
ll = self.glade.get_widget('label_info_locking_repository_label')
349
l = self.glade.get_widget('label_info_locking_repository')
350
l.set_text(self.ret['locking']['repository'])
357
# missing - temporary disabled
359
if self.ret.has_key('missing'):
361
e = self.glade.get_widget('expander_info_missing')
362
if self.ret['missing'].has_key('branch'):
363
ll = self.glade.get_widget('label_info_missing_branch_label')
364
l = self.glade.get_widget('label_info_missing_branch')
365
l.set_text(self.ret['missing']['branch'])
366
ll.set_markup('<b>' + ll.get_text() + '</b>')
373
if self.ret['missing'].has_key('workingtree'):
374
ll = self.glade.get_widget('label_info_missing_workingtree_label')
375
l = self.glade.get_widget('label_info_missing_workingtree')
376
l.set_text(self.ret['missing']['branch'])
377
ll.set_markup('<b>' + ll.get_text() + '</b>')
386
if self.ret.has_key('wtstats'):
388
e = self.glade.get_widget('expander_info_wtstats')
389
if self.ret['wtstats'].has_key('unchanged'):
390
ll = self.glade.get_widget('label_info_wtstats_unchanged_label')
391
l = self.glade.get_widget('label_info_wtstats_unchanged')
392
l.set_text(str(self.ret['wtstats']['unchanged']))
399
if self.ret['wtstats'].has_key('modified'):
400
ll = self.glade.get_widget('label_info_wtstats_modified_label')
401
l = self.glade.get_widget('label_info_wtstats_modified')
402
l.set_text(str(self.ret['wtstats']['modified']))
409
if self.ret['wtstats'].has_key('added'):
410
ll = self.glade.get_widget('label_info_wtstats_added_label')
411
l = self.glade.get_widget('label_info_wtstats_added')
412
l.set_text(str(self.ret['wtstats']['added']))
419
if self.ret['wtstats'].has_key('removed'):
420
ll = self.glade.get_widget('label_info_wtstats_removed_label')
421
l = self.glade.get_widget('label_info_wtstats_removed')
422
l.set_text(str(self.ret['wtstats']['removed']))
429
if self.ret['wtstats'].has_key('renamed'):
430
ll = self.glade.get_widget('label_info_wtstats_renamed_label')
431
l = self.glade.get_widget('label_info_wtstats_renamed')
432
l.set_text(str(self.ret['wtstats']['renamed']))
439
if self.ret['wtstats'].has_key('unknown'):
440
ll = self.glade.get_widget('label_info_wtstats_unknown_label')
441
l = self.glade.get_widget('label_info_wtstats_unknown')
442
l.set_text(str(self.ret['wtstats']['unknown']))
449
if self.ret['wtstats'].has_key('ignored'):
450
ll = self.glade.get_widget('label_info_wtstats_ignored_label')
451
l = self.glade.get_widget('label_info_wtstats_ignored')
452
l.set_text(str(self.ret['wtstats']['ignored']))
459
if self.ret['wtstats'].has_key('subdirs'):
460
ll = self.glade.get_widget('label_info_wtstats_subdirs_label')
461
l = self.glade.get_widget('label_info_wtstats_subdirs')
462
l.set_text(str(self.ret['wtstats']['subdirs']))
470
if self.ret.has_key('brstats'):
472
e = self.glade.get_widget('expander_info_brstats')
473
if self.ret['brstats'].has_key('revno'):
474
ll = self.glade.get_widget('label_info_brstats_revno_label')
475
l = self.glade.get_widget('label_info_brstats_revno')
476
l.set_text(str(self.ret['brstats']['revno']))
483
if self.ret['brstats'].has_key('commiters'):
484
ll = self.glade.get_widget('label_info_brstats_commiters_label')
485
l = self.glade.get_widget('label_info_brstats_commiters')
486
l.set_text(str(self.ret['brstats']['commiters']))
493
if self.ret['brstats'].has_key('age'):
494
ll = self.glade.get_widget('label_info_brstats_age_label')
495
l = self.glade.get_widget('label_info_brstats_age')
496
l.set_text('%d days' % self.ret['brstats']['age'])
503
if self.ret['brstats'].has_key('firstrev'):
504
ll = self.glade.get_widget('label_info_brstats_firstrev_label')
505
l = self.glade.get_widget('label_info_brstats_firstrev')
506
l.set_text(self.ret['brstats']['firstrev'])
513
if self.ret['brstats'].has_key('lastrev'):
514
ll = self.glade.get_widget('label_info_brstats_lastrev_label')
515
l = self.glade.get_widget('label_info_brstats_lastrev')
516
l.set_text(self.ret['brstats']['lastrev'])
524
if self.ret.has_key('repstats'):
526
e = self.glade.get_widget('expander_info_repstats')
527
if self.ret['repstats'].has_key('revisions'):
528
ll = self.glade.get_widget('label_info_repstats_revisions_label')
529
l = self.glade.get_widget('label_info_repstats_revisions')
530
l.set_text(str(self.ret['repstats']['revisions']))
537
if self.ret['repstats'].has_key('size'):
538
ll = self.glade.get_widget('label_info_repstats_size_label')
539
l = self.glade.get_widget('label_info_repstats_size')
540
l.set_text('%d KiB' % (self.ret['repstats']['size'] / 1024))
548
def activate(self, expander):
549
""" Redraw the window. """
550
self.window.resize(50, 50)
551
self.window.queue_resize()
554
""" Display the Informations window. """
556
error_dialog(_('Directory is not a branch'),
557
_('You can perform this action only in a branch.'))
562
def close(self, widget=None):
563
self.window.destroy()