/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 push.py

  • Committer: Jelmer Vernooij
  • Date: 2007-07-15 18:12:57 UTC
  • Revision ID: jelmer@samba.org-20070715181257-g264qus2zyi3v39z
Add RevisionSelectionBox widget, use in TagDialog.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic) <szilveszter.farkas@gmail.com>
 
2
# Copyright (C) 2007 by Jelmer Vernooij <jelmer@samba.org>
2
3
#
3
4
# This program is free software; you can redistribute it and/or modify
4
5
# it under the terms of the GNU General Public License as published by
22
23
    
23
24
import gtk
24
25
 
25
 
from olive import delimiter
26
26
from errors import show_bzr_error
27
27
 
 
28
# FIXME: This needs to be public JRV 20070714
 
29
from bzrlib.builtins import _create_prefix
28
30
from bzrlib.config import LocationConfig
29
31
import bzrlib.errors as errors
30
32
 
31
 
from olive.dialog import error_dialog, info_dialog, question_dialog
 
33
from dialog import error_dialog, info_dialog, question_dialog
32
34
 
 
35
from history import UrlHistory
33
36
 
34
37
class PushDialog(gtk.Dialog):
35
38
    """ New implementation of the Push dialog. """
36
 
    def __init__(self, branch, parent=None):
 
39
    def __init__(self, repository, revid, branch=None, parent=None):
37
40
        """ Initialize the Push dialog. """
38
41
        gtk.Dialog.__init__(self, title="Push - Olive",
39
42
                                  parent=parent,
41
44
                                  buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
42
45
        
43
46
        # Get arguments
 
47
        self.repository = repository
 
48
        self.revid = revid
44
49
        self.branch = branch
45
50
        
46
51
        # Create the widgets
47
52
        self._label_location = gtk.Label(_("Location:"))
48
53
        self._label_test = gtk.Label(_("(click the Test button to check write access)"))
49
 
        self._check_remember = gtk.CheckButton(_("_Remember as default location"),
50
 
                                               use_underline=True)
51
 
        self._check_prefix = gtk.CheckButton(_("Create the path _leading up to the location"),
52
 
                                             use_underline=True)
53
 
        self._check_overwrite = gtk.CheckButton(_("_Overwrite target if diverged"),
54
 
                                                use_underline=True)
55
54
        self._combo = gtk.ComboBoxEntry()
56
55
        self._button_test = gtk.Button(_("_Test"), use_underline=True)
57
56
        self._button_push = gtk.Button(_("_Push"), use_underline=True)
77
76
        self._hbox_test.pack_start(self._image_test, False, False)
78
77
        self._hbox_test.pack_start(self._label_test, True, True)
79
78
        self.vbox.pack_start(self._hbox_location)
80
 
        self.vbox.pack_start(self._check_remember)
81
 
        self.vbox.pack_start(self._check_prefix)
82
 
        self.vbox.pack_start(self._check_overwrite)
83
79
        self.vbox.pack_start(self._hbox_test)
84
80
        self.action_area.pack_start(self._button_test)
85
81
        self.action_area.pack_end(self._button_push)
88
84
        self.vbox.show_all()
89
85
        
90
86
        # Build location history
 
87
        self._history = UrlHistory(self.branch.get_config(), 'push_history')
91
88
        self._build_history()
92
89
        
93
90
    def _build_history(self):
94
91
        """ Build up the location history. """
95
 
        config = LocationConfig(self.branch.base)
96
 
        history = config.get_user_option('gpush_history')
97
 
        if history is not None:
98
 
            self._combo_model = gtk.ListStore(str)
99
 
            for item in history.split(delimiter):
100
 
                self._combo_model.append([ item ])
101
 
            self._combo.set_model(self._combo_model)
102
 
            self._combo.set_text_column(0)
 
92
        self._combo_model = gtk.ListStore(str)
 
93
        for item in self._history.get_entries():
 
94
            self._combo_model.append([ item ])
 
95
        self._combo.set_model(self._combo_model)
 
96
        self._combo.set_text_column(0)
103
97
        
104
 
        location = self.branch.get_push_location()
105
 
        if location:
106
 
            self._combo.get_child().set_text(location)
107
 
    
108
 
    def _add_to_history(self, location):
109
 
        """ Add specified location to the history (if not yet added). """
110
 
        config = LocationConfig(self.branch.base)
111
 
        history = config.get_user_option('gpush_history')
112
 
        if history is None:
113
 
            config.set_user_option('gpush_history', location)
114
 
        else:
115
 
            h = history.split(delimiter)
116
 
            if location not in h:
117
 
                h.append(location)
118
 
            config.set_user_option('gpush_history', delimiter.join(h))
 
98
        if self.branch is not None:
 
99
            location = self.branch.get_push_location()
 
100
            if location is not None:
 
101
                self._combo.get_child().set_text(location)
119
102
    
120
103
    def _on_test_clicked(self, widget):
121
104
        """ Test button clicked handler. """
127
110
        m = _urlRE.match(url)
128
111
        if m:
129
112
            proto = m.groupdict()['proto']
130
 
            if (proto == 'sftp') or (proto == 'file') or (proto == 'ftp'):
131
 
                # have write acces (most probably)
 
113
            # FIXME: This should ask the transport or branch rather than 
 
114
            # guessing using regular expressions. JRV 20070714
 
115
            if proto in ('sftp', 'file', 'ftp'):
 
116
                # have write access (most probably)
132
117
                self._image_test.set_from_stock(gtk.STOCK_YES, 4)
133
118
                self._label_test.set_markup(_('<b>Write access is probably available</b>'))
134
119
            else:
145
130
        """ Push button clicked handler. """
146
131
        location = self._combo.get_child().get_text()
147
132
        revs = 0
 
133
        if self.branch is not None and self.branch.get_push_location() is None:
 
134
            response = question_dialog(_('Set default push location'),
 
135
                                       _('There is no default push location set.\nSet %r as default now?') % location)
 
136
            if response == gtk.REPONSE_OK:
 
137
                self.branch.set_push_location(location)
 
138
 
148
139
        try:
149
 
            revs = do_push(self.branch,
150
 
                           location=location,
151
 
                           overwrite=self._check_overwrite.get_active(),
152
 
                           remember=self._check_remember.get_active(),
153
 
                           create_prefix=self._check_prefix.get_active())
 
140
            revs = do_push(self.branch, location=location, overwrite=False)
154
141
        except errors.DivergedBranches:
155
142
            response = question_dialog(_('Branches have been diverged'),
156
143
                                       _('You cannot push if branches have diverged.\nOverwrite?'))
157
144
            if response == gtk.RESPONSE_OK:
158
 
                revs = do_push(self.branch, overwrite=True)
 
145
                revs = do_push(self.branch, location=location, overwrite=True)
159
146
            return
160
147
        
161
 
        self._add_to_history(location)
 
148
        self._history.add_entry(location)
162
149
        info_dialog(_('Push successful'),
163
150
                    _("%d revision(s) pushed.") % revs)
164
151
        
165
152
        self.response(gtk.RESPONSE_OK)
166
153
 
167
 
def do_push(branch, location=None, remember=False, overwrite=False,
168
 
         create_prefix=False):
 
154
def do_push(br_from, location, overwrite):
169
155
    """ Update a mirror of a branch.
170
156
    
171
 
    :param branch: the source branch
 
157
    :param br_from: the source branch
172
158
    
173
159
    :param location: the location of the branch that you'd like to update
174
160
    
175
 
    :param remember: if set, the location will be stored
176
 
    
177
161
    :param overwrite: overwrite target location if it diverged
178
162
    
179
 
    :param create_prefix: create the path leading up to the branch if it doesn't exist
180
 
    
181
163
    :return: number of revisions pushed
182
164
    """
183
165
    from bzrlib.bzrdir import BzrDir
184
166
    from bzrlib.transport import get_transport
185
167
        
186
 
    br_from = branch
187
 
    
188
 
    stored_loc = br_from.get_push_location()
189
 
    if location is None:
190
 
        if stored_loc is None:
191
 
            error_dialog(_('Push location is unknown'),
192
 
                         _('Please specify a location manually.'))
193
 
            return
194
 
        else:
195
 
            location = stored_loc
196
 
 
197
168
    transport = get_transport(location)
198
169
    location_url = transport.base
199
170
 
200
 
    if br_from.get_push_location() is None or remember:
201
 
        br_from.set_push_location(location_url)
202
 
 
203
171
    old_rh = []
204
172
 
205
173
    try:
208
176
    except errors.NotBranchError:
209
177
        # create a branch.
210
178
        transport = transport.clone('..')
211
 
        if not create_prefix:
212
 
            try:
213
 
                relurl = transport.relpath(location_url)
214
 
                transport.mkdir(relurl)
215
 
            except errors.NoSuchFile:
216
 
                error_dialog(_('Non existing parent directory'),
217
 
                             _("The parent directory (%s)\ndoesn't exist.") % location)
 
179
        try:
 
180
            relurl = transport.relpath(location_url)
 
181
            transport.mkdir(relurl)
 
182
        except errors.NoSuchFile:
 
183
            response = question_dialog(_('Non existing parent directory'),
 
184
                         _("The parent directory (%s)\ndoesn't exist. Create?") % location)
 
185
            if response == gtk.RESPONSE_OK:
 
186
                _create_prefix(transport)
 
187
            else:
218
188
                return
219
 
        else:
220
 
            current = transport.base
221
 
            needed = [(transport, transport.relpath(location_url))]
222
 
            while needed:
223
 
                try:
224
 
                    transport, relpath = needed[-1]
225
 
                    transport.mkdir(relpath)
226
 
                    needed.pop()
227
 
                except errors.NoSuchFile:
228
 
                    new_transport = transport.clone('..')
229
 
                    needed.append((new_transport,
230
 
                                   new_transport.relpath(transport.base)))
231
 
                    if new_transport.base == transport.base:
232
 
                        error_dialog(_('Path prefix not created'),
233
 
                                     _("The path leading up to the specified location couldn't\nbe created."))
234
 
                        return
235
189
        dir_to = br_from.bzrdir.clone(location_url,
236
190
            revision_id=br_from.last_revision())
237
191
        br_to = dir_to.open_branch()
242
196
            tree_to = dir_to.open_workingtree()
243
197
        except errors.NotLocalUrl:
244
198
            # FIXME - what to do here? how should we warn the user?
245
 
            #warning('This transport does not update the working '
246
 
            #        'tree of: %s' % (br_to.base,))
247
199
            count = br_to.pull(br_from, overwrite)
248
200
        except errors.NoWorkingTree:
249
201
            count = br_to.pull(br_from, overwrite)