/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-06 00:23:46 UTC
  • mto: (0.8.83 merge)
  • mto: This revision was merged to the branch mainline in revision 83.
  • Revision ID: jelmer@samba.org-20060906002346-73aa11b52d4d7b96
Load plugins on startup.

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
except:
29
29
    sys.exit(1)
30
30
 
31
 
import olive.backend.commit as commit
32
 
import olive.backend.errors as errors
33
 
import olive.backend.info as info
 
31
import bzrlib.errors as errors
34
32
 
35
33
class OlivePush:
36
34
    """ Display Push dialog and perform the needed actions. """
67
65
        self.label_test = self.glade.get_widget('label_push_test')
68
66
        self.image_test = self.glade.get_widget('image_push_test')
69
67
        
70
 
        # Set initial state
71
 
        self.entry_location.set_sensitive(0)
72
 
        self.check_remember.set_sensitive(0)
73
 
        self.check_create.set_sensitive(0)
74
 
                
75
68
        # Get stored location
76
69
        self.notbranch = False
77
70
        try:
78
 
            loc = info.get_push_location(self.comm.get_path())
 
71
            from bzrlib.branch import Branch
 
72
    
 
73
            branch = Branch.open_containing(self.comm.get_path())[0]
 
74
    
 
75
            self.entry_stored.set_text(branch.get_push_location())
79
76
        except errors.NotBranchError:
80
77
            self.notbranch = True
81
78
            return
82
 
 
83
 
        if loc is not None:
84
 
            self.entry_stored.set_text(loc)
85
79
    
86
80
    def display(self):
87
81
        """ Display the Push dialog. """
95
89
    
96
90
    def stored_toggled(self, widget):
97
91
        if widget.get_active():
98
 
            self.entry_stored.set_sensitive(1)
99
 
            self.entry_location.set_sensitive(0)
100
 
            self.check_remember.set_sensitive(0)
101
 
            self.check_create.set_sensitive(0)
 
92
            self.entry_stored.show()
 
93
            self.entry_location.hide()
 
94
            self.check_remember.hide()
 
95
            self.check_create.hide()
 
96
            self.window.resize(self.width, self.height)
102
97
        else:
103
 
            self.entry_stored.set_sensitive(0)
104
 
            self.entry_location.set_sensitive(1)
105
 
            self.check_remember.set_sensitive(1)
106
 
            self.check_create.set_sensitive(1)
 
98
            self.entry_stored.hide()
 
99
            self.entry_location.show()
 
100
            self.check_remember.show()
 
101
            self.check_create.show()
107
102
    
108
103
    def specific_toggled(self, widget):
109
104
        if widget.get_active():
110
 
            self.entry_stored.set_sensitive(0)
111
 
            self.entry_location.set_sensitive(1)
112
 
            self.check_remember.set_sensitive(1)
113
 
            self.check_create.set_sensitive(1)
 
105
            self.entry_stored.hide()
 
106
            self.entry_location.show()
 
107
            self.check_remember.show()
 
108
            self.check_create.show()
114
109
        else:
115
 
            self.entry_stored.set_sensitive(1)
116
 
            self.entry_location.set_sensitive(0)
117
 
            self.check_remember.set_sensitive(0)
118
 
            self.check_create.set_sensitive(0)
 
110
            self.entry_stored.show()
 
111
            self.entry_location.hide()
 
112
            self.check_remember.hide()
 
113
            self.check_create.hide()
119
114
    
120
115
    def push(self, widget):
121
116
        revs = 0
122
117
        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(),
 
120
                revs = do_push(self.comm.get_path(),
126
121
                                   overwrite=self.check_overwrite.get_active())
127
122
            except errors.NotBranchError:
128
123
                self.dialog.error_dialog(_('Directory is not a branch'),
150
145
                return
151
146
            
152
147
            try:
153
 
                revs = commit.push(self.comm.get_path(), location,
 
148
                revs = do_push(self.comm.get_path(), location,
154
149
                                   self.check_remember.get_active(),
155
150
                                   self.check_overwrite.get_active(),
156
151
                                   self.check_create.get_active())
200
195
            if (proto == 'sftp') or (proto == 'file') or (proto == 'ftp'):
201
196
                # have write acces (most probably)
202
197
                self.image_test.set_from_stock(gtk.STOCK_YES, 4)
203
 
                self.label_test.set_markup(_('<b>Write access is probably available</b>'))
 
198
                self.label_test.set_markup(_('<b>Write access is available most probably</b>'))
204
199
            else:
205
200
                # no write access
206
201
                self.image_test.set_from_stock(gtk.STOCK_NO, 4)
212
207
    
213
208
    def close(self, widget=None):
214
209
        self.window.destroy()
 
210
 
 
211
def do_push(branch, location=None, remember=False, overwrite=False,
 
212
         create_prefix=False):
 
213
    """ Update a mirror of a branch.
 
214
    
 
215
    :param branch: the source branch
 
216
    
 
217
    :param location: the location of the branch that you'd like to update
 
218
    
 
219
    :param remember: if set, the location will be stored
 
220
    
 
221
    :param overwrite: overwrite target location if it diverged
 
222
    
 
223
    :param create_prefix: create the path leading up to the branch if it doesn't exist
 
224
    
 
225
    :return: number of revisions pushed
 
226
    """
 
227
    from bzrlib.branch import Branch
 
228
    from bzrlib.transport import get_transport
 
229
        
 
230
    br_from = Branch.open_containing(branch)[0]
 
231
    
 
232
    stored_loc = br_from.get_push_location()
 
233
    if location is None:
 
234
        if stored_loc is None:
 
235
            raise NoLocationKnown
 
236
        else:
 
237
            location = stored_loc
 
238
 
 
239
    transport = get_transport(location)
 
240
    location_url = transport.base
 
241
 
 
242
    if br_from.get_push_location() is None or remember:
 
243
        br_from.set_push_location(location_url)
 
244
 
 
245
    old_rh = []
 
246
 
 
247
    try:
 
248
        dir_to = bzrlib.bzrdir.BzrDir.open(location_url)
 
249
        br_to = dir_to.open_branch()
 
250
    except NotBranchError:
 
251
        # create a branch.
 
252
        transport = transport.clone('..')
 
253
        if not create_prefix:
 
254
            try:
 
255
                relurl = transport.relpath(location_url)
 
256
                transport.mkdir(relurl)
 
257
            except NoSuchFile:
 
258
                raise NonExistingParent(location)
 
259
        else:
 
260
            current = transport.base
 
261
            needed = [(transport, transport.relpath(location_url))]
 
262
            while needed:
 
263
                try:
 
264
                    transport, relpath = needed[-1]
 
265
                    transport.mkdir(relpath)
 
266
                    needed.pop()
 
267
                except NoSuchFile:
 
268
                    new_transport = transport.clone('..')
 
269
                    needed.append((new_transport,
 
270
                                   new_transport.relpath(transport.base)))
 
271
                    if new_transport.base == transport.base:
 
272
                        raise PathPrefixNotCreated
 
273
        dir_to = br_from.bzrdir.clone(location_url,
 
274
            revision_id=br_from.last_revision())
 
275
        br_to = dir_to.open_branch()
 
276
        count = len(br_to.revision_history())
 
277
    else:
 
278
        old_rh = br_to.revision_history()
 
279
        try:
 
280
            try:
 
281
                tree_to = dir_to.open_workingtree()
 
282
            except NotLocalUrl:
 
283
                # FIXME - what to do here? how should we warn the user?
 
284
                #warning('This transport does not update the working '
 
285
                #        'tree of: %s' % (br_to.base,))
 
286
                count = br_to.pull(br_from, overwrite)
 
287
            except NoWorkingTree:
 
288
                count = br_to.pull(br_from, overwrite)
 
289
            else:
 
290
                count = tree_to.pull(br_from, overwrite)
 
291
        except DivergedBranches:
 
292
            raise DivergedBranchesError
 
293
    
 
294
    return count