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 olive import gladefile
29
from dialog import error_dialog
32
""" Get info about branch, working tree, and repository
34
:param location: the location of the branch/working tree/repository
36
:return: the information in dictionary format
38
The following informations are delivered (if available):
39
ret['location']['lightcoroot']: Light checkout root
40
ret['location']['sharedrepo']: Shared repository
41
ret['location']['repobranch']: Repository branch
42
ret['location']['cobranch']: Checkout of branch
43
ret['location']['repoco']: Repository checkout
44
ret['location']['coroot']: Checkout root
45
ret['location']['branchroot']: Branch root
46
ret['related']['parentbranch']: Parent branch
47
ret['related']['publishbranch']: Publish to branch
48
ret['format']['control']: Control format
49
ret['format']['workingtree']: Working tree format
50
ret['format']['branch']: Branch format
51
ret['format']['repository']: Repository format
52
ret['locking']['workingtree']: Working tree lock status
53
ret['locking']['branch']: Branch lock status
54
ret['locking']['repository']: Repository lock status
55
ret['missing']['branch']: Missing revisions in branch
56
ret['missing']['workingtree']: Missing revisions in working tree
57
ret['wtstats']['unchanged']: Unchanged files
58
ret['wtstats']['modified']: Modified files
59
ret['wtstats']['added']: Added files
60
ret['wtstats']['removed']: Removed files
61
ret['wtstats']['renamed']: Renamed files
62
ret['wtstats']['unknown']: Unknown files
63
ret['wtstats']['ignored']: Ingnored files
64
ret['wtstats']['subdirs']: Versioned subdirectories
65
ret['brstats']['revno']: Revisions in branch
66
ret['brstats']['commiters']: Number of commiters
67
ret['brstats']['age']: Age of branch in days
68
ret['brstats']['firstrev']: Time of first revision
69
ret['brstats']['lastrev']: Time of last revision
70
ret['repstats']['revisions']: Revisions in repository
71
ret['repstats']['size']: Size of repository in bytes
73
import bzrlib.bzrdir as bzrdir
79
a_bzrdir = bzrdir.BzrDir.open_containing(location)[0]
80
except errors.NotBranchError:
81
raise errors.NotBranchError(location)
84
working = a_bzrdir.open_workingtree()
87
branch = working.branch
88
repository = branch.repository
89
control = working.bzrdir
91
ret['location'] = info_helper.get_location_info(repository, branch, working)
92
ret['related'] = info_helper.get_related_info(branch)
93
ret['format'] = info_helper.get_format_info(control, repository, branch, working)
94
ret['locking'] = info_helper.get_locking_info(repository, branch, working)
96
ret['missing']['branch'] = info_helper.get_missing_revisions_branch(branch)
97
ret['missing']['workingtree'] = info_helper.get_missing_revisions_working(working)
98
ret['wtstats'] = info_helper.get_working_stats(working)
99
ret['brstats'] = info_helper.get_branch_stats(branch)
100
ret['repstats'] = info_helper.get_repository_stats(repository)
105
except (errors.NoWorkingTree, errors.NotLocalUrl):
109
branch = a_bzrdir.open_branch()
112
ret['location'] = info_helper.get_location_info(repository, branch)
113
ret['related'] = info_helper.get_related_info(branch)
114
ret['format'] = info_helper.get_format_info(control, repository, branch)
115
ret['locking'] = info_helper.get_locking_info(repository, branch)
116
ret['missing']['branch'] = info_helper.get_missing_revisions_branch(branch)
117
ret['brstats'] = info_helper.get_branch_stats(branch)
118
ret['repstats'] = info_helper.get_repository_stats(repository)
123
except errors.NotBranchError:
127
repository = a_bzrdir.open_repository()
128
repository.lock_read()
130
ret['location'] = info_helper.get_location_info(repository)
131
ret['format'] = info_helper.get_format_info(control, repository)
132
ret['locking'] = info_helper.get_locking_info(repository)
133
ret['repstats'] = info_helper.get_repository_stats(repository)
138
except errors.NoRepositoryPresent:
143
""" Display Informations window and perform the needed actions. """
144
def __init__(self, wt):
145
""" Initialize the Informations window. """
146
self.glade = gtk.glade.XML(gladefile, 'window_info', 'olive-gtk')
148
# Get the Informations window widget
149
self.window = self.glade.get_widget('window_info')
151
# Check if current location is a branch
152
self.notbranch = False
154
self.ret = info(wt.basedir)
155
except errors.NotBranchError:
156
self.notbranch = True
159
# Dictionary for signal_autoconnect
160
dic = { "on_button_info_close_clicked": self.close,
161
"on_expander_info_location_activate": self.activate,
162
"on_expander_info_related_activate": self.activate,
163
"on_expander_info_format_activate": self.activate,
164
"on_expander_info_locking_activate": self.activate,
165
"on_expander_info_missing_activate": self.activate,
166
"on_expander_info_wtstats_activate": self.activate,
167
"on_expander_info_brstats_activate": self.activate,
168
"on_expander_info_repstats_activate": self.activate }
170
# Connect the signals to the handlers
171
self.glade.signal_autoconnect(dic)
173
# Generate status output
174
self._generate_info()
176
def _generate_info(self):
177
""" Generate 'bzr info' output. """
179
if self.ret.has_key('location'):
181
e = self.glade.get_widget('expander_info_location')
182
if self.ret['location'].has_key('lightcoroot'):
183
ll = self.glade.get_widget('label_info_location_lightcoroot_label')
184
l = self.glade.get_widget('label_info_location_lightcoroot')
185
l.set_text(self.ret['location']['lightcoroot'])
192
if self.ret['location'].has_key('sharedrepo'):
193
ll = self.glade.get_widget('label_info_location_sharedrepo_label')
194
l = self.glade.get_widget('label_info_location_sharedrepo')
195
l.set_text(self.ret['location']['sharedrepo'])
202
if self.ret['location'].has_key('repobranch'):
203
ll = self.glade.get_widget('label_info_location_repobranch_label')
204
l = self.glade.get_widget('label_info_location_repobranch')
205
l.set_text(self.ret['location']['repobranch'])
212
if self.ret['location'].has_key('cobranch'):
213
ll = self.glade.get_widget('label_info_location_cobranch_label')
214
l = self.glade.get_widget('label_info_location_cobranch')
215
l.set_text(self.ret['location']['cobranch'])
222
if self.ret['location'].has_key('repoco'):
223
ll = self.glade.get_widget('label_info_location_repoco_label')
224
l = self.glade.get_widget('label_info_location_repoco')
225
l.set_text(self.ret['location']['repoco'])
232
if self.ret['location'].has_key('coroot'):
233
ll = self.glade.get_widget('label_info_location_coroot_label')
234
l = self.glade.get_widget('label_info_location_coroot')
235
l.set_text(self.ret['location']['coroot'])
242
if self.ret['location'].has_key('branchroot'):
243
ll = self.glade.get_widget('label_info_location_branchroot_label')
244
l = self.glade.get_widget('label_info_location_branchroot')
245
l.set_text(self.ret['location']['branchroot'])
253
if self.ret.has_key('related'):
255
e = self.glade.get_widget('expander_info_related')
256
if self.ret['related'].has_key('parentbranch'):
257
ll = self.glade.get_widget('label_info_related_parentbranch_label')
258
l = self.glade.get_widget('label_info_related_parentbranch')
259
l.set_text(self.ret['related']['parentbranch'])
266
if self.ret['related'].has_key('publishbranch'):
267
ll = self.glade.get_widget('label_info_related_publishbranch_label')
268
l = self.glade.get_widget('label_info_related_publishbranch')
269
l.set_text(self.ret['related']['publishbranch'])
277
if self.ret.has_key('format'):
279
e = self.glade.get_widget('expander_info_format')
280
if self.ret['format'].has_key('control'):
281
ll = self.glade.get_widget('label_info_format_control_label')
282
l = self.glade.get_widget('label_info_format_control')
283
l.set_text(self.ret['format']['control'])
290
if self.ret['format'].has_key('workingtree'):
291
ll = self.glade.get_widget('label_info_format_workingtree_label')
292
l = self.glade.get_widget('label_info_format_workingtree')
293
l.set_text(self.ret['format']['workingtree'])
300
if self.ret['format'].has_key('branch'):
301
ll = self.glade.get_widget('label_info_format_branch_label')
302
l = self.glade.get_widget('label_info_format_branch')
303
l.set_text(self.ret['format']['branch'])
310
if self.ret['format'].has_key('repository'):
311
ll = self.glade.get_widget('label_info_format_repository_label')
312
l = self.glade.get_widget('label_info_format_repository')
313
l.set_text(self.ret['format']['repository'])
321
if self.ret.has_key('locking'):
323
e = self.glade.get_widget('expander_info_locking')
324
if self.ret['locking'].has_key('workingtree'):
325
ll = self.glade.get_widget('label_info_locking_workingtree_label')
326
l = self.glade.get_widget('label_info_locking_workingtree')
327
l.set_text(self.ret['locking']['workingtree'])
334
if self.ret['locking'].has_key('branch'):
335
ll = self.glade.get_widget('label_info_locking_branch_label')
336
l = self.glade.get_widget('label_info_locking_branch')
337
l.set_text(self.ret['locking']['branch'])
344
if self.ret['locking'].has_key('repository'):
345
ll = self.glade.get_widget('label_info_locking_repository_label')
346
l = self.glade.get_widget('label_info_locking_repository')
347
l.set_text(self.ret['locking']['repository'])
354
# missing - temporary disabled
356
if self.ret.has_key('missing'):
358
e = self.glade.get_widget('expander_info_missing')
359
if self.ret['missing'].has_key('branch'):
360
ll = self.glade.get_widget('label_info_missing_branch_label')
361
l = self.glade.get_widget('label_info_missing_branch')
362
l.set_text(self.ret['missing']['branch'])
363
ll.set_markup('<b>' + ll.get_text() + '</b>')
370
if self.ret['missing'].has_key('workingtree'):
371
ll = self.glade.get_widget('label_info_missing_workingtree_label')
372
l = self.glade.get_widget('label_info_missing_workingtree')
373
l.set_text(self.ret['missing']['branch'])
374
ll.set_markup('<b>' + ll.get_text() + '</b>')
383
if self.ret.has_key('wtstats'):
385
e = self.glade.get_widget('expander_info_wtstats')
386
if self.ret['wtstats'].has_key('unchanged'):
387
ll = self.glade.get_widget('label_info_wtstats_unchanged_label')
388
l = self.glade.get_widget('label_info_wtstats_unchanged')
389
l.set_text(str(self.ret['wtstats']['unchanged']))
396
if self.ret['wtstats'].has_key('modified'):
397
ll = self.glade.get_widget('label_info_wtstats_modified_label')
398
l = self.glade.get_widget('label_info_wtstats_modified')
399
l.set_text(str(self.ret['wtstats']['modified']))
406
if self.ret['wtstats'].has_key('added'):
407
ll = self.glade.get_widget('label_info_wtstats_added_label')
408
l = self.glade.get_widget('label_info_wtstats_added')
409
l.set_text(str(self.ret['wtstats']['added']))
416
if self.ret['wtstats'].has_key('removed'):
417
ll = self.glade.get_widget('label_info_wtstats_removed_label')
418
l = self.glade.get_widget('label_info_wtstats_removed')
419
l.set_text(str(self.ret['wtstats']['removed']))
426
if self.ret['wtstats'].has_key('renamed'):
427
ll = self.glade.get_widget('label_info_wtstats_renamed_label')
428
l = self.glade.get_widget('label_info_wtstats_renamed')
429
l.set_text(str(self.ret['wtstats']['renamed']))
436
if self.ret['wtstats'].has_key('unknown'):
437
ll = self.glade.get_widget('label_info_wtstats_unknown_label')
438
l = self.glade.get_widget('label_info_wtstats_unknown')
439
l.set_text(str(self.ret['wtstats']['unknown']))
446
if self.ret['wtstats'].has_key('ignored'):
447
ll = self.glade.get_widget('label_info_wtstats_ignored_label')
448
l = self.glade.get_widget('label_info_wtstats_ignored')
449
l.set_text(str(self.ret['wtstats']['ignored']))
456
if self.ret['wtstats'].has_key('subdirs'):
457
ll = self.glade.get_widget('label_info_wtstats_subdirs_label')
458
l = self.glade.get_widget('label_info_wtstats_subdirs')
459
l.set_text(str(self.ret['wtstats']['subdirs']))
467
if self.ret.has_key('brstats'):
469
e = self.glade.get_widget('expander_info_brstats')
470
if self.ret['brstats'].has_key('revno'):
471
ll = self.glade.get_widget('label_info_brstats_revno_label')
472
l = self.glade.get_widget('label_info_brstats_revno')
473
l.set_text(str(self.ret['brstats']['revno']))
480
if self.ret['brstats'].has_key('commiters'):
481
ll = self.glade.get_widget('label_info_brstats_commiters_label')
482
l = self.glade.get_widget('label_info_brstats_commiters')
483
l.set_text(str(self.ret['brstats']['commiters']))
490
if self.ret['brstats'].has_key('age'):
491
ll = self.glade.get_widget('label_info_brstats_age_label')
492
l = self.glade.get_widget('label_info_brstats_age')
493
l.set_text('%d days' % self.ret['brstats']['age'])
500
if self.ret['brstats'].has_key('firstrev'):
501
ll = self.glade.get_widget('label_info_brstats_firstrev_label')
502
l = self.glade.get_widget('label_info_brstats_firstrev')
503
l.set_text(self.ret['brstats']['firstrev'])
510
if self.ret['brstats'].has_key('lastrev'):
511
ll = self.glade.get_widget('label_info_brstats_lastrev_label')
512
l = self.glade.get_widget('label_info_brstats_lastrev')
513
l.set_text(self.ret['brstats']['lastrev'])
521
if self.ret.has_key('repstats'):
523
e = self.glade.get_widget('expander_info_repstats')
524
if self.ret['repstats'].has_key('revisions'):
525
ll = self.glade.get_widget('label_info_repstats_revisions_label')
526
l = self.glade.get_widget('label_info_repstats_revisions')
527
l.set_text(str(self.ret['repstats']['revisions']))
534
if self.ret['repstats'].has_key('size'):
535
ll = self.glade.get_widget('label_info_repstats_size_label')
536
l = self.glade.get_widget('label_info_repstats_size')
537
l.set_text('%d KiB' % (self.ret['repstats']['size'] / 1024))
545
def activate(self, expander):
546
""" Redraw the window. """
547
self.window.resize(50, 50)
548
self.window.queue_resize()
551
""" Display the Informations window. """
553
error_dialog(_('Directory is not a branch'),
554
_('You can perform this action only in a branch.'))
559
def close(self, widget=None):
560
self.window.destroy()