/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: David Allouche
  • Date: 2006-05-08 13:03:59 UTC
  • Revision ID: david.allouche@canonical.com-20060508130359-f9a471d0d0b1dcf2
remove --robust, pyflakes fixes, update README

Thanks to Robert Collins' new graphing logic, the --robust option is
no longer needed to prevent extreme graph width on broken branches.
That allows removing a bunch of flaky code.

Remove a few spurious imports (thanks to pyflakes).

Update README to request bzr>=0.8.

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="Olive - 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
 
        for key, keystring, subkeylist in infokeylist:
230
 
            if self.ret.has_key(key):
231
 
                tablelength = 0
232
 
                for subkey, subkeystring in subkeylist:
233
 
                    if self.ret[key].has_key(subkey):
234
 
                        tablelength += 1
235
 
                if tablelength == 0:
236
 
                    pass
237
 
                else:
238
 
                    exec "exp_%s = gtk.Expander('<b>%s</b>')"%(key, keystring)
239
 
                    eval("exp_%s.set_use_markup(True)"%key)
240
 
                    eval("exp_%s.connect('activate', self.activate)"%key)
241
 
                    
242
 
                    exec "alignment_%s = gtk.Alignment()"%key
243
 
                    eval("alignment_%s.set_padding(0, 0, 24, 0)"%key)
244
 
                    eval("exp_%s.add(alignment_%s)"%(key, key))
245
 
                    
246
 
                    exec "table_%s = gtk.Table(tablelength, 2)"%key
247
 
                    eval("table_%s.set_col_spacings(12)"%key)
248
 
                    eval("alignment_%s.add(table_%s)"%(key, key))
249
 
                    
250
 
                    tablepos = 0
251
 
                    for subkey, subkeystring in subkeylist:
252
 
                        if self.ret[key].has_key(subkey):
253
 
                            exec "%s_%s_label = gtk.Label('%s:')"%(key,subkey, subkeystring)
254
 
                            eval("table_%s.attach(%s_%s_label, 0, 1, %i, %i, gtk.FILL)"%(key, key, subkey, tablepos, tablepos + 1))
255
 
                            eval("%s_%s_label.set_alignment(0, 0.5)"%(key, subkey))
256
 
                            
257
 
                            exec "%s_%s = gtk.Label('%s')"%(key, subkey, str(self.ret[key][subkey]))
258
 
                            eval("table_%s.attach(%s_%s, 1, 2, %i, %i, gtk.FILL)"%(key, key, subkey, tablepos, tablepos + 1))
259
 
                            eval("%s_%s.set_alignment(0, 0.5)"%(key, subkey))
260
 
                            tablepos += 1
261
 
                    eval("exp_%s.set_expanded(True)"%key)
262
 
                    eval("self.window.vbox.pack_start(exp_%s, False, True, 0)"%key)
263
 
    
264
 
    def activate(self, expander):
265
 
        """ Redraw the window. """
266
 
        self.window.resize(50, 50)
267
 
        self.window.queue_resize()
268
 
    
269
 
    def display(self):
270
 
        """ Display the Informations window. """
271
 
        if self.notbranch:
272
 
            error_dialog(_i18n('Directory is not a branch'),
273
 
                         _i18n('You can perform this action only in a branch.'))
274
 
            self.close()
275
 
        else:
276
 
            self.window.show_all()
277
 
    
278
 
    def close(self, widget=None):
279
 
        self.window.destroy()