/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
0.8.42 by Szilveszter Farkas (Phanatic)
Implemented Informations functionality; some bzrlib API changes handled.
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
554.1.1 by Jasper Groenewegen
Replace OliveInfo with gladeless InfoDialog
17
import os
18
0.8.42 by Szilveszter Farkas (Phanatic)
Implemented Informations functionality; some bzrlib API changes handled.
19
try:
20
    import pygtk
21
    pygtk.require("2.0")
22
except:
23
    pass
0.13.10 by Jelmer Vernooij
Don't pass around gladefile all the time.
24
25
import gtk
0.8.42 by Szilveszter Farkas (Phanatic)
Implemented Informations functionality; some bzrlib API changes handled.
26
0.11.1 by Jelmer Vernooij
Eliminate olive.backend.errors.
27
import bzrlib.errors as errors
0.11.9 by Jelmer Vernooij
Remove last few bits from backend and integrate them where necessary.
28
554.1.1 by Jasper Groenewegen
Replace OliveInfo with gladeless InfoDialog
29
from bzrlib.plugins.gtk import _i18n, icon_path
151 by Jelmer Vernooij
Move dialog to top-level directory.
30
from bzrlib.plugins.gtk.dialog import error_dialog
93.1.6 by Alexander Belchenko
detecting name of glade file doing in separate module (olive.gladefile)
31
0.13.10 by Jelmer Vernooij
Don't pass around gladefile all the time.
32
0.11.9 by Jelmer Vernooij
Remove last few bits from backend and integrate them where necessary.
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:
0.8.98 by Szilveszter Farkas (Phanatic)
Loads of fixes. Pyflakes cleanup.
83
        raise errors.NotBranchError(location)
0.11.9 by Jelmer Vernooij
Remove last few bits from backend and integrate them where necessary.
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()
195.1.21 by Szilveszter Farkas (Phanatic)
Some small modifications to Branch, Checkout and Info to support remote branches.
112
        repository = branch.repository
113
        control = a_bzrdir
0.11.9 by Jelmer Vernooij
Remove last few bits from backend and integrate them where necessary.
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()
554.1.1 by Jasper Groenewegen
Replace OliveInfo with gladeless InfoDialog
140
        return ret
0.11.9 by Jelmer Vernooij
Remove last few bits from backend and integrate them where necessary.
141
    except errors.NoRepositoryPresent:
142
        pass
143
0.8.42 by Szilveszter Farkas (Phanatic)
Implemented Informations functionality; some bzrlib API changes handled.
144
554.1.1 by Jasper Groenewegen
Replace OliveInfo with gladeless InfoDialog
145
class InfoDialog(object):
0.8.42 by Szilveszter Farkas (Phanatic)
Implemented Informations functionality; some bzrlib API changes handled.
146
    """ Display Informations window and perform the needed actions. """
554.1.1 by Jasper Groenewegen
Replace OliveInfo with gladeless InfoDialog
147
    
195.1.21 by Szilveszter Farkas (Phanatic)
Some small modifications to Branch, Checkout and Info to support remote branches.
148
    def __init__(self, branch):
0.8.42 by Szilveszter Farkas (Phanatic)
Implemented Informations functionality; some bzrlib API changes handled.
149
        """ Initialize the Informations window. """
150
        # Check if current location is a branch
151
        self.notbranch = False
152
        try:
195.1.21 by Szilveszter Farkas (Phanatic)
Some small modifications to Branch, Checkout and Info to support remote branches.
153
            self.ret = info(branch.base)
0.8.42 by Szilveszter Farkas (Phanatic)
Implemented Informations functionality; some bzrlib API changes handled.
154
        except errors.NotBranchError:
155
            self.notbranch = True
156
            return
157
        
554.1.1 by Jasper Groenewegen
Replace OliveInfo with gladeless InfoDialog
158
        iconpath = icon_path() + os.sep
159
        
160
        # Create the window
161
        self.window = gtk.Dialog(title="Olive - Information",
162
                                  parent = None,
163
                                  flags=0,
164
                                  buttons=None)
165
        self.window.set_icon_list(gtk.gdk.pixbuf_new_from_file(iconpath+"oliveicon2.png"),
166
                                  gtk.gdk.pixbuf_new_from_file(iconpath+"olive-gtk.png"))
167
        self.window.vbox.set_spacing(3)
168
        self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_NORMAL)
169
        
170
        infokeylist = ( ('location', _i18n("Location"), (
171
                            ('lightcoroot', _i18n("Light checkout root")),
172
                            ('sharedrepo', _i18n("Shared repository")),
173
                            ('repobranch', _i18n("Repository branch")),
174
                            ('cobranch', _i18n("Checkout of branch")),
175
                            ('repoco', _i18n("Repository checkout")),
176
                            ('coroot', _i18n("Checkout root")),
177
                            ('branchroot', _i18n("Branch root")),
178
                            )),
179
                        ('related', _i18n("Related branches"), (
180
                            ('parentbranch', _i18n("Parent branch")),
181
                            ('publishbranch', _i18n("Publish to branch")),
182
                            )),
183
                        ('format', _i18n("Format"), (
184
                            ('control', _i18n("Control format")),
185
                            ('workingtree', _i18n("Working tree format")),
186
                            ('branch', _i18n("Branch format")),
187
                            ('repository', _i18n("Repository format")),
188
                            )),
189
                        ('locking', _i18n("Lock status"), (
190
                            ('workingtree', _i18n("Working tree lock status")),
191
                            ('branch', _i18n("Branch lock status")),
192
                            ('repository', _i18n("Repository lock status")),
193
                            )),
194
                        #('missing', _i18n("Missing revisions"), (
195
                        #    ('branch', _i18n("Missing revisions in branch")),
196
                        #    ('workingtree', _i18n("Missing revisions in working tree")),
197
                        #    )), # Missing is 'temporary' disabled
198
                        ('wtstats', _i18n("In the working tree"), (
199
                            ('unchanged', _i18n("Unchanged files")),
200
                            ('modified', _i18n("Modified files")),
201
                            ('added', _i18n("Added files")),
202
                            ('removed', _i18n("Removed files")),
203
                            ('renamed', _i18n("Renamed files")),
204
                            ('unknown', _i18n("Unknown files")),
205
                            ('ignored', _i18n("Ignored files")),
206
                            ('subdirs', _i18n("Versioned subdirectories")),
207
                            )),
208
                        ('brstats', _i18n("Branch history"), (
209
                            ('revno', _i18n("Revisions in branch")),
210
                            ('commiters', _i18n("Number of commiters")),
211
                            ('age', _i18n("Age of branch in days")),
212
                            ('firstrev', _i18n("Time of first revision")),
213
                            ('lastrev', _i18n("Time of last revision")),
214
                            )),
215
                        ('repstats', _i18n("Revision store"), (
216
                            ('revisions', _i18n("Revisions in repository")),
217
                            ('size', _i18n("Size of repository in bytes")),
218
                            )),
219
                        )
220
               
0.8.42 by Szilveszter Farkas (Phanatic)
Implemented Informations functionality; some bzrlib API changes handled.
221
        # Generate status output
554.1.1 by Jasper Groenewegen
Replace OliveInfo with gladeless InfoDialog
222
        self._generate_info(infokeylist)
223
        
224
        button_close = gtk.Button(stock=gtk.STOCK_CLOSE)        
225
        button_close.connect('clicked', self.close)
226
        self.window.action_area.pack_end(button_close)
227
        self.window.set_focus(button_close)
228
    
229
    def _generate_info(self, infokeylist):
0.8.42 by Szilveszter Farkas (Phanatic)
Implemented Informations functionality; some bzrlib API changes handled.
230
        """ Generate 'bzr info' output. """
554.1.1 by Jasper Groenewegen
Replace OliveInfo with gladeless InfoDialog
231
        for key, keystring, subkeylist in infokeylist:
232
            if self.ret.has_key(key):
233
                tablelength = 0
234
                for subkey, subkeystring in subkeylist:
235
                    if self.ret[key].has_key(subkey):
236
                        tablelength += 1
237
                if tablelength == 0:
238
                    pass
239
                else:
240
                    exec "exp_%s = gtk.Expander('<b>%s</b>')"%(key, keystring)
241
                    eval("exp_%s.set_use_markup(True)"%key)
242
                    eval("exp_%s.connect('activate', self.activate)"%key)
243
                    
244
                    exec "alignment_%s = gtk.Alignment()"%key
245
                    eval("alignment_%s.set_padding(0, 0, 24, 0)"%key)
246
                    eval("exp_%s.add(alignment_%s)"%(key, key))
247
                    
248
                    exec "table_%s = gtk.Table(tablelength, 2)"%key
249
                    eval("table_%s.set_col_spacings(12)"%key)
250
                    eval("alignment_%s.add(table_%s)"%(key, key))
251
                    
252
                    tablepos = 0
253
                    for subkey, subkeystring in subkeylist:
254
                        if self.ret[key].has_key(subkey):
255
                            exec "%s_%s_label = gtk.Label('%s:')"%(key,subkey, subkeystring)
256
                            eval("table_%s.attach(%s_%s_label, 0, 1, %i, %i, gtk.FILL)"%(key, key, subkey, tablepos, tablepos + 1))
257
                            eval("%s_%s_label.set_alignment(0, 0.5)"%(key, subkey))
258
                            
259
                            exec "%s_%s = gtk.Label('%s')"%(key, subkey, str(self.ret[key][subkey]))
260
                            eval("table_%s.attach(%s_%s, 1, 2, %i, %i, gtk.FILL)"%(key, key, subkey, tablepos, tablepos + 1))
261
                            eval("%s_%s.set_alignment(0, 0.5)"%(key, subkey))
262
                            tablepos += 1
263
                    eval("exp_%s.set_expanded(True)"%key)
264
                    eval("self.window.vbox.pack_start(exp_%s, False, True, 0)"%key)
0.8.42 by Szilveszter Farkas (Phanatic)
Implemented Informations functionality; some bzrlib API changes handled.
265
    
266
    def activate(self, expander):
267
        """ Redraw the window. """
268
        self.window.resize(50, 50)
269
        self.window.queue_resize()
270
    
271
    def display(self):
272
        """ Display the Informations window. """
273
        if self.notbranch:
475.1.2 by Vincent Ladeuil
Fix bug #187283 fix replacing _() by _i18n().
274
            error_dialog(_i18n('Directory is not a branch'),
275
                         _i18n('You can perform this action only in a branch.'))
0.8.42 by Szilveszter Farkas (Phanatic)
Implemented Informations functionality; some bzrlib API changes handled.
276
            self.close()
277
        else:
554.1.1 by Jasper Groenewegen
Replace OliveInfo with gladeless InfoDialog
278
            self.window.show_all()
279
    
0.8.42 by Szilveszter Farkas (Phanatic)
Implemented Informations functionality; some bzrlib API changes handled.
280
    def close(self, widget=None):
281
        self.window.destroy()