/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz

« back to all changes in this revision

Viewing changes to olive/info.py

  • Committer: Jelmer Vernooij
  • Date: 2010-05-25 17:09:02 UTC
  • mto: This revision was merged to the branch mainline in revision 691.
  • Revision ID: jelmer@samba.org-20100525170902-3to8g5iw7ovw79kh
Split out olive into a separate directory.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic) <szilveszter.farkas@gmail.com>
 
2
#
 
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.
 
7
#
 
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.
 
12
#
 
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
 
16
 
 
17
import os
 
18
 
 
19
try:
 
20
    import pygtk
 
21
    pygtk.require("2.0")
 
22
except:
 
23
    pass
 
24
 
 
25
import gtk
 
26
 
 
27
import bzrlib.errors as errors
 
28
 
 
29
from bzrlib.plugins.gtk import _i18n, icon_path
 
30
from bzrlib.plugins.gtk.dialog import error_dialog
 
31
 
 
32
 
 
33
def info(location):
 
34
    """ Get info about branch, working tree, and repository
 
35
    
 
36
    :param location: the location of the branch/working tree/repository
 
37
    
 
38
    :return: the information in dictionary format
 
39
    
 
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
 
74
    """
 
75
    import bzrlib.bzrdir as bzrdir
 
76
    
 
77
    import info_helper
 
78
    
 
79
    ret = {}
 
80
    try:
 
81
        a_bzrdir = bzrdir.BzrDir.open_containing(location)[0]
 
82
    except errors.NotBranchError:
 
83
        raise errors.NotBranchError(location)
 
84
 
 
85
    try:
 
86
        working = a_bzrdir.open_workingtree()
 
87
        working.lock_read()
 
88
        try:
 
89
            branch = working.branch
 
90
            repository = branch.repository
 
91
            control = working.bzrdir
 
92
            
 
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)
 
97
            ret['missing'] = {}
 
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)
 
103
        finally:
 
104
            working.unlock()
 
105
            return ret
 
106
        return
 
107
    except (errors.NoWorkingTree, errors.NotLocalUrl):
 
108
        pass
 
109
 
 
110
    try:
 
111
        branch = a_bzrdir.open_branch()
 
112
        repository = branch.repository
 
113
        control = a_bzrdir
 
114
        branch.lock_read()
 
115
        try:
 
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)
 
123
        finally:
 
124
            branch.unlock()
 
125
            return ret
 
126
        return
 
127
    except errors.NotBranchError:
 
128
        pass
 
129
 
 
130
    try:
 
131
        repository = a_bzrdir.open_repository()
 
132
        repository.lock_read()
 
133
        try:
 
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)
 
138
        finally:
 
139
            repository.unlock()
 
140
        return ret
 
141
    except errors.NoRepositoryPresent:
 
142
        pass
 
143
 
 
144
 
 
145
class InfoDialog(object):
 
146
    """ Display Informations window and perform the needed actions. """
 
147
    
 
148
    def __init__(self, branch):
 
149
        """ Initialize the Informations window. """
 
150
        # Check if current location is a branch
 
151
        self.notbranch = False
 
152
        try:
 
153
            self.ret = info(branch.base)
 
154
        except errors.NotBranchError:
 
155
            self.notbranch = True
 
156
            return
 
157
        
 
158
        # Create the window
 
159
        self.window = gtk.Dialog(title="Branch Information",
 
160
                                  parent = None,
 
161
                                  flags=0,
 
162
                                  buttons=None)
 
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)
 
167
        
 
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")),
 
176
                            )),
 
177
                        ('related', _i18n("Related branches"), (
 
178
                            ('parentbranch', _i18n("Parent branch")),
 
179
                            ('publishbranch', _i18n("Publish to branch")),
 
180
                            )),
 
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")),
 
186
                            )),
 
187
                        ('locking', _i18n("Lock status"), (
 
188
                            ('workingtree', _i18n("Working tree lock status")),
 
189
                            ('branch', _i18n("Branch lock status")),
 
190
                            ('repository', _i18n("Repository lock status")),
 
191
                            )),
 
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")),
 
205
                            )),
 
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")),
 
212
                            )),
 
213
                        ('repstats', _i18n("Revision store"), (
 
214
                            ('revisions', _i18n("Revisions in repository")),
 
215
                            ('size', _i18n("Size of repository in bytes")),
 
216
                            )),
 
217
                        )
 
218
               
 
219
        # Generate status output
 
220
        self._generate_info(infokeylist)
 
221
        
 
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)
 
226
    
 
227
    def _generate_info(self, infokeylist):
 
228
        """ Generate 'bzr info' output. """
 
229
        expander={}
 
230
        alignment={}
 
231
        table={}
 
232
        label = {}
 
233
        description = {}
 
234
        for key, keystring, subkeylist in infokeylist:
 
235
            if self.ret.has_key(key):
 
236
                tablelength = 0
 
237
                for subkey, subkeystring in subkeylist:
 
238
                    if self.ret[key].has_key(subkey):
 
239
                        tablelength += 1
 
240
                if tablelength == 0:
 
241
                    pass
 
242
                else:
 
243
                    expander[key] = gtk.Expander(keystring)
 
244
                    expander[key].set_use_markup(True)
 
245
                    expander[key].connect('activate', self.activate)
 
246
                    
 
247
                    alignment[key]= gtk.Alignment()
 
248
                    alignment[key].set_padding(0, 0, 24, 0)
 
249
                    expander[key].add(alignment[key])
 
250
                    
 
251
                    table[key] = gtk.Table(tablelength, 2)
 
252
                    table[key].set_col_spacings(12)
 
253
                    alignment[key].add(table[key])
 
254
                    
 
255
                    label[key] = {}
 
256
                    description[key] = {}
 
257
                    
 
258
                    tablepos = 0
 
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)
 
264
                            
 
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)
 
268
                            tablepos += 1
 
269
                    expander[key].set_expanded(True)
 
270
                    self.window.vbox.pack_start(expander[key], False, True, 0)
 
271
    
 
272
    def activate(self, expander):
 
273
        """ Redraw the window. """
 
274
        self.window.resize(50, 50)
 
275
        self.window.queue_resize()
 
276
    
 
277
    def display(self):
 
278
        """ Display the Informations window. """
 
279
        if self.notbranch:
 
280
            error_dialog(_i18n('Directory is not a branch'),
 
281
                         _i18n('You can perform this action only in a branch.'))
 
282
            self.close()
 
283
        else:
 
284
            self.window.show_all()
 
285
    
 
286
    def close(self, widget=None):
 
287
        self.window.destroy()