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, dialog):
148
""" Initialize the Informations window. """
149
self.gladefile = gladefile
150
self.glade = gtk.glade.XML(self.gladefile, 'window_info', 'olive-gtk')
152
# Communication object
157
# Get the Informations window widget
158
self.window = self.glade.get_widget('window_info')
160
# Check if current location is a branch
161
self.notbranch = False
163
self.ret = info(self.comm.get_path())
164
except errors.NotBranchError:
165
self.notbranch = True
168
# Dictionary for signal_autoconnect
169
dic = { "on_button_info_close_clicked": self.close,
170
"on_expander_info_location_activate": self.activate,
171
"on_expander_info_related_activate": self.activate,
172
"on_expander_info_format_activate": self.activate,
173
"on_expander_info_locking_activate": self.activate,
174
"on_expander_info_missing_activate": self.activate,
175
"on_expander_info_wtstats_activate": self.activate,
176
"on_expander_info_brstats_activate": self.activate,
177
"on_expander_info_repstats_activate": self.activate }
179
# Connect the signals to the handlers
180
self.glade.signal_autoconnect(dic)
182
# Generate status output
183
self._generate_info()
185
def _generate_info(self):
186
""" Generate 'bzr info' output. """
188
if self.ret.has_key('location'):
190
e = self.glade.get_widget('expander_info_location')
191
if self.ret['location'].has_key('lightcoroot'):
192
ll = self.glade.get_widget('label_info_location_lightcoroot_label')
193
l = self.glade.get_widget('label_info_location_lightcoroot')
194
l.set_text(self.ret['location']['lightcoroot'])
201
if self.ret['location'].has_key('sharedrepo'):
202
ll = self.glade.get_widget('label_info_location_sharedrepo_label')
203
l = self.glade.get_widget('label_info_location_sharedrepo')
204
l.set_text(self.ret['location']['sharedrepo'])
211
if self.ret['location'].has_key('repobranch'):
212
ll = self.glade.get_widget('label_info_location_repobranch_label')
213
l = self.glade.get_widget('label_info_location_repobranch')
214
l.set_text(self.ret['location']['repobranch'])
221
if self.ret['location'].has_key('cobranch'):
222
ll = self.glade.get_widget('label_info_location_cobranch_label')
223
l = self.glade.get_widget('label_info_location_cobranch')
224
l.set_text(self.ret['location']['cobranch'])
231
if self.ret['location'].has_key('repoco'):
232
ll = self.glade.get_widget('label_info_location_repoco_label')
233
l = self.glade.get_widget('label_info_location_repoco')
234
l.set_text(self.ret['location']['repoco'])
241
if self.ret['location'].has_key('coroot'):
242
ll = self.glade.get_widget('label_info_location_coroot_label')
243
l = self.glade.get_widget('label_info_location_coroot')
244
l.set_text(self.ret['location']['coroot'])
251
if self.ret['location'].has_key('branchroot'):
252
ll = self.glade.get_widget('label_info_location_branchroot_label')
253
l = self.glade.get_widget('label_info_location_branchroot')
254
l.set_text(self.ret['location']['branchroot'])
262
if self.ret.has_key('related'):
264
e = self.glade.get_widget('expander_info_related')
265
if self.ret['related'].has_key('parentbranch'):
266
ll = self.glade.get_widget('label_info_related_parentbranch_label')
267
l = self.glade.get_widget('label_info_related_parentbranch')
268
l.set_text(self.ret['related']['parentbranch'])
275
if self.ret['related'].has_key('publishbranch'):
276
ll = self.glade.get_widget('label_info_related_publishbranch_label')
277
l = self.glade.get_widget('label_info_related_publishbranch')
278
l.set_text(self.ret['related']['publishbranch'])
286
if self.ret.has_key('format'):
288
e = self.glade.get_widget('expander_info_format')
289
if self.ret['format'].has_key('control'):
290
ll = self.glade.get_widget('label_info_format_control_label')
291
l = self.glade.get_widget('label_info_format_control')
292
l.set_text(self.ret['format']['control'])
299
if self.ret['format'].has_key('workingtree'):
300
ll = self.glade.get_widget('label_info_format_workingtree_label')
301
l = self.glade.get_widget('label_info_format_workingtree')
302
l.set_text(self.ret['format']['workingtree'])
309
if self.ret['format'].has_key('branch'):
310
ll = self.glade.get_widget('label_info_format_branch_label')
311
l = self.glade.get_widget('label_info_format_branch')
312
l.set_text(self.ret['format']['branch'])
319
if self.ret['format'].has_key('repository'):
320
ll = self.glade.get_widget('label_info_format_repository_label')
321
l = self.glade.get_widget('label_info_format_repository')
322
l.set_text(self.ret['format']['repository'])
330
if self.ret.has_key('locking'):
332
e = self.glade.get_widget('expander_info_locking')
333
if self.ret['locking'].has_key('workingtree'):
334
ll = self.glade.get_widget('label_info_locking_workingtree_label')
335
l = self.glade.get_widget('label_info_locking_workingtree')
336
l.set_text(self.ret['locking']['workingtree'])
343
if self.ret['locking'].has_key('branch'):
344
ll = self.glade.get_widget('label_info_locking_branch_label')
345
l = self.glade.get_widget('label_info_locking_branch')
346
l.set_text(self.ret['locking']['branch'])
353
if self.ret['locking'].has_key('repository'):
354
ll = self.glade.get_widget('label_info_locking_repository_label')
355
l = self.glade.get_widget('label_info_locking_repository')
356
l.set_text(self.ret['locking']['repository'])
363
# missing - temporary disabled
365
if self.ret.has_key('missing'):
367
e = self.glade.get_widget('expander_info_missing')
368
if self.ret['missing'].has_key('branch'):
369
ll = self.glade.get_widget('label_info_missing_branch_label')
370
l = self.glade.get_widget('label_info_missing_branch')
371
l.set_text(self.ret['missing']['branch'])
372
ll.set_markup('<b>' + ll.get_text() + '</b>')
379
if self.ret['missing'].has_key('workingtree'):
380
ll = self.glade.get_widget('label_info_missing_workingtree_label')
381
l = self.glade.get_widget('label_info_missing_workingtree')
382
l.set_text(self.ret['missing']['branch'])
383
ll.set_markup('<b>' + ll.get_text() + '</b>')
392
if self.ret.has_key('wtstats'):
394
e = self.glade.get_widget('expander_info_wtstats')
395
if self.ret['wtstats'].has_key('unchanged'):
396
ll = self.glade.get_widget('label_info_wtstats_unchanged_label')
397
l = self.glade.get_widget('label_info_wtstats_unchanged')
398
l.set_text(str(self.ret['wtstats']['unchanged']))
405
if self.ret['wtstats'].has_key('modified'):
406
ll = self.glade.get_widget('label_info_wtstats_modified_label')
407
l = self.glade.get_widget('label_info_wtstats_modified')
408
l.set_text(str(self.ret['wtstats']['modified']))
415
if self.ret['wtstats'].has_key('added'):
416
ll = self.glade.get_widget('label_info_wtstats_added_label')
417
l = self.glade.get_widget('label_info_wtstats_added')
418
l.set_text(str(self.ret['wtstats']['added']))
425
if self.ret['wtstats'].has_key('removed'):
426
ll = self.glade.get_widget('label_info_wtstats_removed_label')
427
l = self.glade.get_widget('label_info_wtstats_removed')
428
l.set_text(str(self.ret['wtstats']['removed']))
435
if self.ret['wtstats'].has_key('renamed'):
436
ll = self.glade.get_widget('label_info_wtstats_renamed_label')
437
l = self.glade.get_widget('label_info_wtstats_renamed')
438
l.set_text(str(self.ret['wtstats']['renamed']))
445
if self.ret['wtstats'].has_key('unknown'):
446
ll = self.glade.get_widget('label_info_wtstats_unknown_label')
447
l = self.glade.get_widget('label_info_wtstats_unknown')
448
l.set_text(str(self.ret['wtstats']['unknown']))
455
if self.ret['wtstats'].has_key('ignored'):
456
ll = self.glade.get_widget('label_info_wtstats_ignored_label')
457
l = self.glade.get_widget('label_info_wtstats_ignored')
458
l.set_text(str(self.ret['wtstats']['ignored']))
465
if self.ret['wtstats'].has_key('subdirs'):
466
ll = self.glade.get_widget('label_info_wtstats_subdirs_label')
467
l = self.glade.get_widget('label_info_wtstats_subdirs')
468
l.set_text(str(self.ret['wtstats']['subdirs']))
476
if self.ret.has_key('brstats'):
478
e = self.glade.get_widget('expander_info_brstats')
479
if self.ret['brstats'].has_key('revno'):
480
ll = self.glade.get_widget('label_info_brstats_revno_label')
481
l = self.glade.get_widget('label_info_brstats_revno')
482
l.set_text(str(self.ret['brstats']['revno']))
489
if self.ret['brstats'].has_key('commiters'):
490
ll = self.glade.get_widget('label_info_brstats_commiters_label')
491
l = self.glade.get_widget('label_info_brstats_commiters')
492
l.set_text(str(self.ret['brstats']['commiters']))
499
if self.ret['brstats'].has_key('age'):
500
ll = self.glade.get_widget('label_info_brstats_age_label')
501
l = self.glade.get_widget('label_info_brstats_age')
502
l.set_text('%d days' % self.ret['brstats']['age'])
509
if self.ret['brstats'].has_key('firstrev'):
510
ll = self.glade.get_widget('label_info_brstats_firstrev_label')
511
l = self.glade.get_widget('label_info_brstats_firstrev')
512
l.set_text(self.ret['brstats']['firstrev'])
519
if self.ret['brstats'].has_key('lastrev'):
520
ll = self.glade.get_widget('label_info_brstats_lastrev_label')
521
l = self.glade.get_widget('label_info_brstats_lastrev')
522
l.set_text(self.ret['brstats']['lastrev'])
530
if self.ret.has_key('repstats'):
532
e = self.glade.get_widget('expander_info_repstats')
533
if self.ret['repstats'].has_key('revisions'):
534
ll = self.glade.get_widget('label_info_repstats_revisions_label')
535
l = self.glade.get_widget('label_info_repstats_revisions')
536
l.set_text(str(self.ret['repstats']['revisions']))
543
if self.ret['repstats'].has_key('size'):
544
ll = self.glade.get_widget('label_info_repstats_size_label')
545
l = self.glade.get_widget('label_info_repstats_size')
546
l.set_text('%d KiB' % (self.ret['repstats']['size'] / 1024))
554
def activate(self, expander):
555
""" Redraw the window. """
556
self.window.resize(50, 50)
557
self.window.queue_resize()
560
""" Display the Informations window. """
562
self.dialog.error_dialog(_('Directory is not a branch'),
563
_('You can perform this action only in a branch.'))
568
def close(self, widget=None):
569
self.window.destroy()