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

  • Committer: Jelmer Vernooij
  • Date: 2006-09-27 21:05:19 UTC
  • mto: (0.12.2 olive)
  • mto: This revision was merged to the branch mainline in revision 83.
  • Revision ID: jelmer@samba.org-20060927210519-7bc2662211808af5
Bunch of other small updates, add more items to 
the TODO list.

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
    pygtk.require("2.0")
22
22
except:
23
23
    pass
24
 
try:
25
 
    import gtk
26
 
    import gtk.gdk
27
 
    import gtk.glade
28
 
except:
29
 
    sys.exit(1)
30
 
 
31
 
import olive.backend.commit as commit
32
 
import olive.backend.errors as errors
33
 
import olive.backend.info as info
 
24
        
 
25
import gtk
 
26
import gtk.gdk
 
27
import gtk.glade
 
28
 
 
29
import bzrlib.errors as errors
 
30
 
 
31
from olive import gladefile
34
32
 
35
33
class OlivePush:
36
34
    """ Display Push dialog and perform the needed actions. """
37
 
    def __init__(self, gladefile, comm, dialog):
 
35
    def __init__(self, comm):
38
36
        """ Initialize the Push dialog. """
39
 
        self.gladefile = gladefile
40
 
        self.glade = gtk.glade.XML(self.gladefile, 'window_push')
 
37
        self.glade = gtk.glade.XML(gladefile, 'window_push')
41
38
        
42
39
        # Communication object
43
40
        self.comm = comm
44
 
        # Dialog object
45
 
        self.dialog = dialog
46
41
        
47
42
        self.window = self.glade.get_widget('window_push')
48
43
        
71
66
        self.entry_location.set_sensitive(0)
72
67
        self.check_remember.set_sensitive(0)
73
68
        self.check_create.set_sensitive(0)
74
 
                
 
69
        
75
70
        # Get stored location
76
71
        self.notbranch = False
77
72
        try:
78
 
            loc = info.get_push_location(self.comm.get_path())
 
73
            from bzrlib.branch import Branch
 
74
    
 
75
            branch = Branch.open_containing(self.comm.get_path())[0]
 
76
    
 
77
            self.entry_stored.set_text(branch.get_push_location())
79
78
        except errors.NotBranchError:
80
79
            self.notbranch = True
81
80
            return
82
 
 
83
 
        if loc is not None:
84
 
            self.entry_stored.set_text(loc)
85
81
    
86
82
    def display(self):
87
83
        """ Display the Push dialog. """
88
84
        if self.notbranch:
89
 
            self.dialog.error_dialog(_('Directory is not a branch'),
 
85
            error_dialog(_('Directory is not a branch'),
90
86
                                     _('You can perform this action only in a branch.'))
91
87
            self.close()
92
88
        else:
119
115
    
120
116
    def push(self, widget):
121
117
        revs = 0
122
 
        self.comm.set_busy(self.window)
123
118
        if self.radio_stored.get_active():
124
119
            try:
125
 
                revs = commit.push(self.comm.get_path(),
126
 
                                   overwrite=self.check_overwrite.get_active())
 
120
                revs = do_push(self.comm.get_path(),
 
121
                               overwrite=self.check_overwrite.get_active())
127
122
            except errors.NotBranchError:
128
 
                self.dialog.error_dialog(_('Directory is not a branch'),
 
123
                error_dialog(_('Directory is not a branch'),
129
124
                                         _('You can perform this action only in a branch.'))
130
125
                return
131
 
            except errors.NoLocationKnown:
132
 
                self.dialog.error_dialog(_('Push location is unknown'),
133
 
                                         _('Please specify a location manually.'))
134
 
                return
135
 
            except errors.NonExistingParent, errmsg:
136
 
                self.dialog.error_dialog(_('Non existing parent directory'),
137
 
                                         _("The parent directory (%s)\ndoesn't exist.") % errmsg)
138
 
                return
139
 
            except errors.DivergedBranchesError:
140
 
                self.dialog.error_dialog(_('Branches have been diverged'),
 
126
            except errors.DivergedBranches:
 
127
                error_dialog(_('Branches have been diverged'),
141
128
                                         _('You cannot push if branches have diverged. Use the\noverwrite option if you want to push anyway.'))
142
129
                return
143
 
            except:
144
 
                raise
145
130
        elif self.radio_specific.get_active():
146
131
            location = self.entry_location.get_text()
147
132
            if location == '':
148
 
                self.dialog.error_dialog(_('No location specified'),
 
133
                error_dialog(_('No location specified'),
149
134
                                         _('Please specify a location or use the default.'))
150
135
                return
151
136
            
152
137
            try:
153
 
                revs = commit.push(self.comm.get_path(), location,
154
 
                                   self.check_remember.get_active(),
155
 
                                   self.check_overwrite.get_active(),
156
 
                                   self.check_create.get_active())
 
138
                revs = do_push(self.comm.get_path(), location,
 
139
                               self.check_remember.get_active(),
 
140
                               self.check_overwrite.get_active(),
 
141
                               self.check_create.get_active())
157
142
            except errors.NotBranchError:
158
 
                self.dialog.error_dialog(_('Directory is not a branch'),
 
143
                error_dialog(_('Directory is not a branch'),
159
144
                                         _('You can perform this action only in a branch.'))
160
 
                self.comm.set_busy(self.window, False)
161
 
                return
162
 
            except errors.NonExistingParent, errmsg:
163
 
                self.dialog.error_dialog(_('Non existing parent directory'),
164
 
                                         _("The parent directory (%s)\ndoesn't exist.") % errmsg)
165
 
                self.comm.set_busy(self.window, False)
166
 
                return
167
 
            except errors.DivergedBranchesError:
168
 
                self.dialog.error_dialog(_('Branches have been diverged'),
 
145
                return
 
146
            except errors.DivergedBranches:
 
147
                error_dialog(_('Branches have been diverged'),
169
148
                                         _('You cannot push if branches have diverged. Use the\noverwrite option if you want to push anyway.'))
170
 
                self.comm.set_busy(self.window, False)
171
 
                return
172
 
            except errors.PathPrefixNotCreated:
173
 
                self.dialog.error_dialog(_('Path prefix not created'),
174
 
                                         _("The path leading up to the specified location couldn't\nbe created."))
175
 
                self.comm.set_busy(self.window, False)
176
 
                return
177
 
            except:
178
 
                raise
179
 
        else:
180
 
            # This should really never happen
181
 
            pass
 
149
                return
182
150
        
183
151
        self.close()
184
 
        self.dialog.info_dialog(_('Push successful'),
 
152
        info_dialog(_('Push successful'),
185
153
                                _('%d revision(s) pushed.') % revs)
186
154
    
187
155
    def test(self, widget):
212
180
    
213
181
    def close(self, widget=None):
214
182
        self.window.destroy()
 
183
 
 
184
def do_push(branch, location=None, remember=False, overwrite=False,
 
185
         create_prefix=False):
 
186
    """ Update a mirror of a branch.
 
187
    
 
188
    :param branch: the source branch
 
189
    
 
190
    :param location: the location of the branch that you'd like to update
 
191
    
 
192
    :param remember: if set, the location will be stored
 
193
    
 
194
    :param overwrite: overwrite target location if it diverged
 
195
    
 
196
    :param create_prefix: create the path leading up to the branch if it doesn't exist
 
197
    
 
198
    :return: number of revisions pushed
 
199
    """
 
200
    from bzrlib.branch import Branch
 
201
    from bzrlib.bzrdir import BzrDir
 
202
    from bzrlib.transport import get_transport
 
203
        
 
204
    br_from = Branch.open_containing(branch)[0]
 
205
    
 
206
    stored_loc = br_from.get_push_location()
 
207
    if location is None:
 
208
        if stored_loc is None:
 
209
            error_dialog(_('Push location is unknown'),
 
210
                                     _('Please specify a location manually.'))
 
211
            return
 
212
        else:
 
213
            location = stored_loc
 
214
 
 
215
    transport = get_transport(location)
 
216
    location_url = transport.base
 
217
 
 
218
    if br_from.get_push_location() is None or remember:
 
219
        br_from.set_push_location(location_url)
 
220
 
 
221
    old_rh = []
 
222
 
 
223
    try:
 
224
        dir_to = BzrDir.open(location_url)
 
225
        br_to = dir_to.open_branch()
 
226
    except errors.NotBranchError:
 
227
        # create a branch.
 
228
        transport = transport.clone('..')
 
229
        if not create_prefix:
 
230
            try:
 
231
                relurl = transport.relpath(location_url)
 
232
                transport.mkdir(relurl)
 
233
            except errors.NoSuchFile:
 
234
                error_dialog(_('Non existing parent directory'),
 
235
                                         _("The parent directory (%s)\ndoesn't exist.") % location)
 
236
                return
 
237
        else:
 
238
            current = transport.base
 
239
            needed = [(transport, transport.relpath(location_url))]
 
240
            while needed:
 
241
                try:
 
242
                    transport, relpath = needed[-1]
 
243
                    transport.mkdir(relpath)
 
244
                    needed.pop()
 
245
                except errors.NoSuchFile:
 
246
                    new_transport = transport.clone('..')
 
247
                    needed.append((new_transport,
 
248
                                   new_transport.relpath(transport.base)))
 
249
                    if new_transport.base == transport.base:
 
250
                        error_dialog(_('Path prefix not created'),
 
251
                                                 _("The path leading up to the specified location couldn't\nbe created."))
 
252
                        return
 
253
        dir_to = br_from.bzrdir.clone(location_url,
 
254
            revision_id=br_from.last_revision())
 
255
        br_to = dir_to.open_branch()
 
256
        count = len(br_to.revision_history())
 
257
    else:
 
258
        old_rh = br_to.revision_history()
 
259
        try:
 
260
            try:
 
261
                tree_to = dir_to.open_workingtree()
 
262
            except errors.NotLocalUrl:
 
263
                # FIXME - what to do here? how should we warn the user?
 
264
                #warning('This transport does not update the working '
 
265
                #        'tree of: %s' % (br_to.base,))
 
266
                count = br_to.pull(br_from, overwrite)
 
267
            except errors.NoWorkingTree:
 
268
                count = br_to.pull(br_from, overwrite)
 
269
            else:
 
270
                count = tree_to.pull(br_from, overwrite)
 
271
    
 
272
    return count