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
27
import bzrlib.errors as errors
29
from bzrlib.plugins.gtk import _i18n, icon_path
30
from bzrlib.plugins.gtk.dialog import error_dialog
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)
141
except errors.NoRepositoryPresent:
145
class InfoDialog(object):
146
""" Display Informations window and perform the needed actions. """
148
def __init__(self, branch):
149
""" Initialize the Informations window. """
150
# Check if current location is a branch
151
self.notbranch = False
153
self.ret = info(branch.base)
154
except errors.NotBranchError:
155
self.notbranch = True
159
self.window = gtk.Dialog(title="Branch Information",
163
self.window.set_icon_list(gtk.gdk.pixbuf_new_from_file(icon_path("oliveicon2.png")),
164
gtk.gdk.pixbuf_new_from_file(icon_path("olive-gtk.png")))
165
self.window.vbox.set_spacing(3)
166
self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_NORMAL)
168
infokeylist = ( ('location', _i18n("Location"), (
169
('lightcoroot', _i18n("Light checkout root")),
170
('sharedrepo', _i18n("Shared repository")),
171
('repobranch', _i18n("Repository branch")),
172
('cobranch', _i18n("Checkout of branch")),
173
('repoco', _i18n("Repository checkout")),
174
('coroot', _i18n("Checkout root")),
175
('branchroot', _i18n("Branch root")),
177
('related', _i18n("Related branches"), (
178
('parentbranch', _i18n("Parent branch")),
179
('publishbranch', _i18n("Publish to branch")),
181
('format', _i18n("Format"), (
182
('control', _i18n("Control format")),
183
('workingtree', _i18n("Working tree format")),
184
('branch', _i18n("Branch format")),
185
('repository', _i18n("Repository format")),
187
('locking', _i18n("Lock status"), (
188
('workingtree', _i18n("Working tree lock status")),
189
('branch', _i18n("Branch lock status")),
190
('repository', _i18n("Repository lock status")),
192
#('missing', _i18n("Missing revisions"), (
193
# ('branch', _i18n("Missing revisions in branch")),
194
# ('workingtree', _i18n("Missing revisions in working tree")),
195
# )), # Missing is 'temporary' disabled
196
('wtstats', _i18n("In the working tree"), (
197
('unchanged', _i18n("Unchanged files")),
198
('modified', _i18n("Modified files")),
199
('added', _i18n("Added files")),
200
('removed', _i18n("Removed files")),
201
('renamed', _i18n("Renamed files")),
202
('unknown', _i18n("Unknown files")),
203
('ignored', _i18n("Ignored files")),
204
('subdirs', _i18n("Versioned subdirectories")),
206
('brstats', _i18n("Branch history"), (
207
('revno', _i18n("Revisions in branch")),
208
('commiters', _i18n("Number of commiters")),
209
('age', _i18n("Age of branch in days")),
210
('firstrev', _i18n("Time of first revision")),
211
('lastrev', _i18n("Time of last revision")),
213
('repstats', _i18n("Revision store"), (
214
('revisions', _i18n("Revisions in repository")),
215
('size', _i18n("Size of repository in bytes")),
219
# Generate status output
220
self._generate_info(infokeylist)
222
button_close = gtk.Button(stock=gtk.STOCK_CLOSE)
223
button_close.connect('clicked', self.close)
224
self.window.action_area.pack_end(button_close)
225
self.window.set_focus(button_close)
227
def _generate_info(self, infokeylist):
228
""" Generate 'bzr info' output. """
234
for key, keystring, subkeylist in infokeylist:
235
if self.ret.has_key(key):
237
for subkey, subkeystring in subkeylist:
238
if self.ret[key].has_key(subkey):
243
expander[key] = gtk.Expander(keystring)
244
expander[key].set_use_markup(True)
245
expander[key].connect('activate', self.activate)
247
alignment[key]= gtk.Alignment()
248
alignment[key].set_padding(0, 0, 24, 0)
249
expander[key].add(alignment[key])
251
table[key] = gtk.Table(tablelength, 2)
252
table[key].set_col_spacings(12)
253
alignment[key].add(table[key])
256
description[key] = {}
259
for subkey, subkeystring in subkeylist:
260
if self.ret[key].has_key(subkey):
261
label[key][subkey] = gtk.Label(subkeystring)
262
table[key].attach(label[key][subkey], 0, 1, tablepos, tablepos + 1, gtk.FILL)
263
label[key][subkey].set_alignment(0, 0.5)
265
description[key][subkey] = gtk.Label(str(self.ret[key][subkey]))
266
table[key].attach(description[key][subkey], 1, 2, tablepos, tablepos + 1, gtk.FILL)
267
description[key][subkey].set_alignment(0, 0.5)
269
expander[key].set_expanded(True)
270
self.window.vbox.pack_start(expander[key], False, True, 0)
272
def activate(self, expander):
273
""" Redraw the window. """
274
self.window.resize(50, 50)
275
self.window.queue_resize()
278
""" Display the Informations window. """
280
error_dialog(_i18n('Directory is not a branch'),
281
_i18n('You can perform this action only in a branch.'))
284
self.window.show_all()
286
def close(self, widget=None):
287
self.window.destroy()