/b-gtk/fix-viz

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/b-gtk/fix-viz
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
1
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic) <szilveszter.farkas@gmail.com>
227 by Jelmer Vernooij
Add push item in revision menu, clean up push code.
2
# Copyright (C) 2007 by Jelmer Vernooij <jelmer@samba.org>
0.8.46 by Szilveszter Farkas (Phanatic)
Modified OliveDialog class interface; huge cleanups.
3
#
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
4
# This program is free software; you can redistribute it and/or modify
5
# it under the terms of the GNU General Public License as published by
6
# the Free Software Foundation; either version 2 of the License, or
7
# (at your option) any later version.
0.8.46 by Szilveszter Farkas (Phanatic)
Modified OliveDialog class interface; huge cleanups.
8
#
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
# GNU General Public License for more details.
0.8.46 by Szilveszter Farkas (Phanatic)
Modified OliveDialog class interface; huge cleanups.
13
#
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, write to the Free Software
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
18
try:
19
    import pygtk
20
    pygtk.require("2.0")
21
except:
22
    pass
0.13.13 by Jelmer Vernooij
Update TODO
23
    
0.13.10 by Jelmer Vernooij
Don't pass around gladefile all the time.
24
import gtk
126.1.19 by Szilveszter Farkas (Phanatic)
Refactored the Push dialog. Add 'gpush' command.
25
26
from errors import show_bzr_error
27
28
from bzrlib.config import LocationConfig
0.11.1 by Jelmer Vernooij
Eliminate olive.backend.errors.
29
import bzrlib.errors as errors
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
30
153 by Jelmer Vernooij
Fix references to dialog.
31
from dialog import error_dialog, info_dialog, question_dialog
126.1.19 by Szilveszter Farkas (Phanatic)
Refactored the Push dialog. Add 'gpush' command.
32
154 by Jelmer Vernooij
Add trivial generic class for storing URL history.
33
from history import UrlHistory
126.1.19 by Szilveszter Farkas (Phanatic)
Refactored the Push dialog. Add 'gpush' command.
34
35
class PushDialog(gtk.Dialog):
36
    """ New implementation of the Push dialog. """
227 by Jelmer Vernooij
Add push item in revision menu, clean up push code.
37
    def __init__(self, repository, revid, branch=None, parent=None):
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
38
        """ Initialize the Push dialog. """
126.1.19 by Szilveszter Farkas (Phanatic)
Refactored the Push dialog. Add 'gpush' command.
39
        gtk.Dialog.__init__(self, title="Push - Olive",
40
                                  parent=parent,
41
                                  flags=0,
42
                                  buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
43
        
126.1.19 by Szilveszter Farkas (Phanatic)
Refactored the Push dialog. Add 'gpush' command.
44
        # Get arguments
227 by Jelmer Vernooij
Add push item in revision menu, clean up push code.
45
        self.repository = repository
46
        self.revid = revid
0.13.13 by Jelmer Vernooij
Update TODO
47
        self.branch = branch
0.8.19 by Szilveszter Farkas (Phanatic)
2006-07-21 Szilveszter Farkas <Szilveszter.Farkas@gmail.com>
48
        
126.1.19 by Szilveszter Farkas (Phanatic)
Refactored the Push dialog. Add 'gpush' command.
49
        # Create the widgets
50
        self._label_location = gtk.Label(_("Location:"))
51
        self._label_test = gtk.Label(_("(click the Test button to check write access)"))
52
        self._check_prefix = gtk.CheckButton(_("Create the path _leading up to the location"),
53
                                             use_underline=True)
54
        self._combo = gtk.ComboBoxEntry()
55
        self._button_test = gtk.Button(_("_Test"), use_underline=True)
56
        self._button_push = gtk.Button(_("_Push"), use_underline=True)
57
        self._hbox_location = gtk.HBox()
58
        self._hbox_test = gtk.HBox()
59
        self._image_test = gtk.Image()
60
        
61
        # Set callbacks
62
        self._button_test.connect('clicked', self._on_test_clicked)
63
        self._button_push.connect('clicked', self._on_push_clicked)
64
        
65
        # Set properties
66
        self._image_test.set_from_stock(gtk.STOCK_DIALOG_INFO, gtk.ICON_SIZE_BUTTON)
67
        self._label_location.set_alignment(0, 0.5)
68
        self._label_test.set_alignment(0, 0.5)
69
        self._hbox_location.set_spacing(3)
70
        self._hbox_test.set_spacing(3)
71
        self.vbox.set_spacing(3)
72
        
73
        # Pack widgets
74
        self._hbox_location.pack_start(self._label_location, False, False)
75
        self._hbox_location.pack_start(self._combo, True, True)
76
        self._hbox_test.pack_start(self._image_test, False, False)
77
        self._hbox_test.pack_start(self._label_test, True, True)
78
        self.vbox.pack_start(self._hbox_location)
79
        self.vbox.pack_start(self._check_prefix)
80
        self.vbox.pack_start(self._hbox_test)
81
        self.action_area.pack_start(self._button_test)
82
        self.action_area.pack_end(self._button_push)
83
        
84
        # Show the dialog
85
        self.vbox.show_all()
86
        
87
        # Build location history
154 by Jelmer Vernooij
Add trivial generic class for storing URL history.
88
        self._history = UrlHistory(self.branch.get_config(), 'push_history')
126.1.19 by Szilveszter Farkas (Phanatic)
Refactored the Push dialog. Add 'gpush' command.
89
        self._build_history()
90
        
91
    def _build_history(self):
92
        """ Build up the location history. """
154 by Jelmer Vernooij
Add trivial generic class for storing URL history.
93
        self._combo_model = gtk.ListStore(str)
94
        for item in self._history.get_entries():
95
            self._combo_model.append([ item ])
96
        self._combo.set_model(self._combo_model)
97
        self._combo.set_text_column(0)
126.1.19 by Szilveszter Farkas (Phanatic)
Refactored the Push dialog. Add 'gpush' command.
98
        
227 by Jelmer Vernooij
Add push item in revision menu, clean up push code.
99
        if self.branch is not None:
100
            location = self.branch.get_push_location()
101
            if location is not None:
102
                self._combo.get_child().set_text(location)
126.1.19 by Szilveszter Farkas (Phanatic)
Refactored the Push dialog. Add 'gpush' command.
103
    
104
    def _on_test_clicked(self, widget):
105
        """ Test button clicked handler. """
0.8.58 by Szilveszter Farkas (Phanatic)
Added Test write access functionality to the Push dialog.
106
        import re
107
        _urlRE = re.compile(r'^(?P<proto>[^:/\\]+)://(?P<path>.*)$')
108
        
126.1.19 by Szilveszter Farkas (Phanatic)
Refactored the Push dialog. Add 'gpush' command.
109
        url = self._combo.get_child().get_text()
0.8.58 by Szilveszter Farkas (Phanatic)
Added Test write access functionality to the Push dialog.
110
        
111
        m = _urlRE.match(url)
112
        if m:
113
            proto = m.groupdict()['proto']
222 by Jelmer Vernooij
Fix whitespace, add comment.
114
            # FIXME: This should ask the transport or branch rather than 
115
            # guessing using regular expressions. JRV 20070714
116
            if proto in ('sftp', 'file', 'ftp'):
117
                # have write access (most probably)
126.1.19 by Szilveszter Farkas (Phanatic)
Refactored the Push dialog. Add 'gpush' command.
118
                self._image_test.set_from_stock(gtk.STOCK_YES, 4)
119
                self._label_test.set_markup(_('<b>Write access is probably available</b>'))
0.8.58 by Szilveszter Farkas (Phanatic)
Added Test write access functionality to the Push dialog.
120
            else:
121
                # no write access
126.1.19 by Szilveszter Farkas (Phanatic)
Refactored the Push dialog. Add 'gpush' command.
122
                self._image_test.set_from_stock(gtk.STOCK_NO, 4)
123
                self._label_test.set_markup(_('<b>No write access</b>'))
0.8.58 by Szilveszter Farkas (Phanatic)
Added Test write access functionality to the Push dialog.
124
        else:
125
            # couldn't determine
126.1.19 by Szilveszter Farkas (Phanatic)
Refactored the Push dialog. Add 'gpush' command.
126
            self._image_test.set_from_stock(gtk.STOCK_DIALOG_QUESTION, 4)
127
            self._label_test.set_markup(_('<b>Could not determine</b>'))
0.8.58 by Szilveszter Farkas (Phanatic)
Added Test write access functionality to the Push dialog.
128
    
126.1.19 by Szilveszter Farkas (Phanatic)
Refactored the Push dialog. Add 'gpush' command.
129
    @show_bzr_error
130
    def _on_push_clicked(self, widget):
131
        """ Push button clicked handler. """
132
        location = self._combo.get_child().get_text()
133
        revs = 0
227 by Jelmer Vernooij
Add push item in revision menu, clean up push code.
134
        if self.branch is not None and self.branch.get_push_location() is None:
135
            response = question_dialog(_('Set default push location'),
136
                                       _('There is no default push location set.\nSet %r as default now?') % location)
137
            if response == gtk.REPONSE_OK:
138
                self.branch.set_push_location(location)
139
126.1.19 by Szilveszter Farkas (Phanatic)
Refactored the Push dialog. Add 'gpush' command.
140
        try:
141
            revs = do_push(self.branch,
142
                           location=location,
227 by Jelmer Vernooij
Add push item in revision menu, clean up push code.
143
                           overwrite=False,
126.1.19 by Szilveszter Farkas (Phanatic)
Refactored the Push dialog. Add 'gpush' command.
144
                           create_prefix=self._check_prefix.get_active())
145
        except errors.DivergedBranches:
146
            response = question_dialog(_('Branches have been diverged'),
147
                                       _('You cannot push if branches have diverged.\nOverwrite?'))
148
            if response == gtk.RESPONSE_OK:
227 by Jelmer Vernooij
Add push item in revision menu, clean up push code.
149
                revs = do_push(self.branch, location=location,
150
                               overwrite=True,
151
                               create_prefix=self._check_prefix.get_active()
152
                               )
126.1.19 by Szilveszter Farkas (Phanatic)
Refactored the Push dialog. Add 'gpush' command.
153
            return
154
        
154 by Jelmer Vernooij
Add trivial generic class for storing URL history.
155
        self._history.add_entry(location)
126.1.19 by Szilveszter Farkas (Phanatic)
Refactored the Push dialog. Add 'gpush' command.
156
        info_dialog(_('Push successful'),
157
                    _("%d revision(s) pushed.") % revs)
158
        
159
        self.response(gtk.RESPONSE_OK)
0.11.9 by Jelmer Vernooij
Remove last few bits from backend and integrate them where necessary.
160
227 by Jelmer Vernooij
Add push item in revision menu, clean up push code.
161
def do_push(branch, location, overwrite, create_prefix):
0.11.9 by Jelmer Vernooij
Remove last few bits from backend and integrate them where necessary.
162
    """ Update a mirror of a branch.
163
    
164
    :param branch: the source branch
165
    
166
    :param location: the location of the branch that you'd like to update
167
    
168
    :param overwrite: overwrite target location if it diverged
169
    
170
    :param create_prefix: create the path leading up to the branch if it doesn't exist
171
    
172
    :return: number of revisions pushed
173
    """
0.8.85 by Szilveszter Farkas (Phanatic)
Fix Push functionality.
174
    from bzrlib.bzrdir import BzrDir
0.11.9 by Jelmer Vernooij
Remove last few bits from backend and integrate them where necessary.
175
    from bzrlib.transport import get_transport
176
        
177
    transport = get_transport(location)
178
    location_url = transport.base
179
180
    old_rh = []
181
182
    try:
0.8.85 by Szilveszter Farkas (Phanatic)
Fix Push functionality.
183
        dir_to = BzrDir.open(location_url)
0.11.9 by Jelmer Vernooij
Remove last few bits from backend and integrate them where necessary.
184
        br_to = dir_to.open_branch()
0.8.85 by Szilveszter Farkas (Phanatic)
Fix Push functionality.
185
    except errors.NotBranchError:
0.11.9 by Jelmer Vernooij
Remove last few bits from backend and integrate them where necessary.
186
        # create a branch.
187
        transport = transport.clone('..')
188
        if not create_prefix:
189
            try:
190
                relurl = transport.relpath(location_url)
191
                transport.mkdir(relurl)
0.8.85 by Szilveszter Farkas (Phanatic)
Fix Push functionality.
192
            except errors.NoSuchFile:
0.13.6 by Jelmer Vernooij
Don't pass along dialog context everywhere.
193
                error_dialog(_('Non existing parent directory'),
0.8.98 by Szilveszter Farkas (Phanatic)
Loads of fixes. Pyflakes cleanup.
194
                             _("The parent directory (%s)\ndoesn't exist.") % location)
0.8.85 by Szilveszter Farkas (Phanatic)
Fix Push functionality.
195
                return
0.11.9 by Jelmer Vernooij
Remove last few bits from backend and integrate them where necessary.
196
        else:
197
            current = transport.base
198
            needed = [(transport, transport.relpath(location_url))]
199
            while needed:
200
                try:
201
                    transport, relpath = needed[-1]
202
                    transport.mkdir(relpath)
203
                    needed.pop()
0.8.85 by Szilveszter Farkas (Phanatic)
Fix Push functionality.
204
                except errors.NoSuchFile:
0.11.9 by Jelmer Vernooij
Remove last few bits from backend and integrate them where necessary.
205
                    new_transport = transport.clone('..')
206
                    needed.append((new_transport,
207
                                   new_transport.relpath(transport.base)))
208
                    if new_transport.base == transport.base:
0.13.6 by Jelmer Vernooij
Don't pass along dialog context everywhere.
209
                        error_dialog(_('Path prefix not created'),
0.8.98 by Szilveszter Farkas (Phanatic)
Loads of fixes. Pyflakes cleanup.
210
                                     _("The path leading up to the specified location couldn't\nbe created."))
0.8.85 by Szilveszter Farkas (Phanatic)
Fix Push functionality.
211
                        return
0.11.9 by Jelmer Vernooij
Remove last few bits from backend and integrate them where necessary.
212
        dir_to = br_from.bzrdir.clone(location_url,
213
            revision_id=br_from.last_revision())
214
        br_to = dir_to.open_branch()
215
        count = len(br_to.revision_history())
216
    else:
217
        old_rh = br_to.revision_history()
218
        try:
0.13.13 by Jelmer Vernooij
Update TODO
219
            tree_to = dir_to.open_workingtree()
220
        except errors.NotLocalUrl:
221
            # FIXME - what to do here? how should we warn the user?
222
            count = br_to.pull(br_from, overwrite)
223
        except errors.NoWorkingTree:
224
            count = br_to.pull(br_from, overwrite)
225
        else:
226
            count = tree_to.pull(br_from, overwrite)
227
0.11.9 by Jelmer Vernooij
Remove last few bits from backend and integrate them where necessary.
228
    return count