/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-13 20:19:31 UTC
  • mfrom: (0.8.79 main)
  • mto: (0.8.83 merge)
  • mto: This revision was merged to the branch mainline in revision 83.
  • Revision ID: jelmer@samba.org-20060913201931-23adba246d4d6529
Merge main branch.

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
 
    
25
 
import gtk
26
 
import gtk.gdk
27
 
import gtk.glade
 
24
try:
 
25
    import gtk
 
26
    import gtk.gdk
 
27
    import gtk.glade
 
28
except:
 
29
    sys.exit(1)
28
30
 
29
31
import bzrlib.errors as errors
30
32
 
31
 
from olive import gladefile
32
 
 
33
33
class OlivePush:
34
34
    """ Display Push dialog and perform the needed actions. """
35
 
    def __init__(self, branch):
 
35
    def __init__(self, gladefile, comm, dialog):
36
36
        """ Initialize the Push dialog. """
37
 
        self.glade = gtk.glade.XML(gladefile, 'window_push')
 
37
        self.gladefile = gladefile
 
38
        self.glade = gtk.glade.XML(self.gladefile, 'window_push')
 
39
        
 
40
        # Communication object
 
41
        self.comm = comm
 
42
        # Dialog object
 
43
        self.dialog = dialog
38
44
        
39
45
        self.window = self.glade.get_widget('window_push')
40
 
 
41
 
        self.branch = branch
42
46
        
43
47
        # Dictionary for signal_autoconnect
44
48
        dic = { "on_button_push_push_clicked": self.push,
65
69
        self.entry_location.set_sensitive(0)
66
70
        self.check_remember.set_sensitive(0)
67
71
        self.check_create.set_sensitive(0)
68
 
        
69
 
        self.entry_stored.set_text(branch.get_push_location())
 
72
                
 
73
        # Get stored location
 
74
        self.notbranch = False
 
75
        try:
 
76
            from bzrlib.branch import Branch
 
77
    
 
78
            branch = Branch.open_containing(self.comm.get_path())[0]
 
79
    
 
80
            self.entry_stored.set_text(branch.get_push_location())
 
81
        except errors.NotBranchError:
 
82
            self.notbranch = True
 
83
            return
70
84
    
71
85
    def display(self):
72
86
        """ Display the Push dialog. """
73
 
        self.window.show()
74
 
        self.width, self.height = self.window.get_size()
 
87
        if self.notbranch:
 
88
            self.dialog.error_dialog(_('Directory is not a branch'),
 
89
                                     _('You can perform this action only in a branch.'))
 
90
            self.close()
 
91
        else:
 
92
            self.window.show()
 
93
            self.width, self.height = self.window.get_size()
75
94
    
76
95
    def stored_toggled(self, widget):
77
96
        if widget.get_active():
99
118
    
100
119
    def push(self, widget):
101
120
        revs = 0
 
121
        self.comm.set_busy(self.window)
102
122
        if self.radio_stored.get_active():
103
123
            try:
104
 
                revs = do_push(self.branch,
105
 
                               overwrite=self.check_overwrite.get_active())
 
124
                revs = do_push(self.comm.get_path(),
 
125
                                   overwrite=self.check_overwrite.get_active())
106
126
            except errors.NotBranchError:
107
 
                error_dialog(_('Directory is not a branch'),
 
127
                self.dialog.error_dialog(_('Directory is not a branch'),
108
128
                                         _('You can perform this action only in a branch.'))
109
129
                return
110
 
            except errors.DivergedBranches:
111
 
                error_dialog(_('Branches have been diverged'),
 
130
            except errors.NoLocationKnown:
 
131
                self.dialog.error_dialog(_('Push location is unknown'),
 
132
                                         _('Please specify a location manually.'))
 
133
                return
 
134
            except errors.NonExistingParent, errmsg:
 
135
                self.dialog.error_dialog(_('Non existing parent directory'),
 
136
                                         _("The parent directory (%s)\ndoesn't exist.") % errmsg)
 
137
                return
 
138
            except errors.DivergedBranchesError:
 
139
                self.dialog.error_dialog(_('Branches have been diverged'),
112
140
                                         _('You cannot push if branches have diverged. Use the\noverwrite option if you want to push anyway.'))
113
141
                return
 
142
            except:
 
143
                raise
114
144
        elif self.radio_specific.get_active():
115
145
            location = self.entry_location.get_text()
116
146
            if location == '':
117
 
                error_dialog(_('No location specified'),
 
147
                self.dialog.error_dialog(_('No location specified'),
118
148
                                         _('Please specify a location or use the default.'))
119
149
                return
120
150
            
121
151
            try:
122
 
                revs = do_push(self.branch, location,
123
 
                               self.check_remember.get_active(),
124
 
                               self.check_overwrite.get_active(),
125
 
                               self.check_create.get_active())
 
152
                revs = do_push(self.comm.get_path(), location,
 
153
                                   self.check_remember.get_active(),
 
154
                                   self.check_overwrite.get_active(),
 
155
                                   self.check_create.get_active())
126
156
            except errors.NotBranchError:
127
 
                error_dialog(_('Directory is not a branch'),
 
157
                self.dialog.error_dialog(_('Directory is not a branch'),
128
158
                                         _('You can perform this action only in a branch.'))
129
 
                return
130
 
            except errors.DivergedBranches:
131
 
                error_dialog(_('Branches have been diverged'),
 
159
                self.comm.set_busy(self.window, False)
 
160
                return
 
161
            except errors.NonExistingParent, errmsg:
 
162
                self.dialog.error_dialog(_('Non existing parent directory'),
 
163
                                         _("The parent directory (%s)\ndoesn't exist.") % errmsg)
 
164
                self.comm.set_busy(self.window, False)
 
165
                return
 
166
            except errors.DivergedBranchesError:
 
167
                self.dialog.error_dialog(_('Branches have been diverged'),
132
168
                                         _('You cannot push if branches have diverged. Use the\noverwrite option if you want to push anyway.'))
133
 
                return
 
169
                self.comm.set_busy(self.window, False)
 
170
                return
 
171
            except errors.PathPrefixNotCreated:
 
172
                self.dialog.error_dialog(_('Path prefix not created'),
 
173
                                         _("The path leading up to the specified location couldn't\nbe created."))
 
174
                self.comm.set_busy(self.window, False)
 
175
                return
 
176
            except:
 
177
                raise
 
178
        else:
 
179
            # This should really never happen
 
180
            pass
134
181
        
135
182
        self.close()
136
 
        info_dialog(_('Push successful'),
 
183
        self.dialog.info_dialog(_('Push successful'),
137
184
                                _('%d revision(s) pushed.') % revs)
138
185
    
139
186
    def test(self, widget):
182
229
    :return: number of revisions pushed
183
230
    """
184
231
    from bzrlib.branch import Branch
185
 
    from bzrlib.bzrdir import BzrDir
186
232
    from bzrlib.transport import get_transport
187
233
        
188
234
    br_from = Branch.open_containing(branch)[0]
190
236
    stored_loc = br_from.get_push_location()
191
237
    if location is None:
192
238
        if stored_loc is None:
193
 
            error_dialog(_('Push location is unknown'),
194
 
                                     _('Please specify a location manually.'))
195
 
            return
 
239
            raise NoLocationKnown
196
240
        else:
197
241
            location = stored_loc
198
242
 
205
249
    old_rh = []
206
250
 
207
251
    try:
208
 
        dir_to = BzrDir.open(location_url)
 
252
        dir_to = bzrlib.bzrdir.BzrDir.open(location_url)
209
253
        br_to = dir_to.open_branch()
210
 
    except errors.NotBranchError:
 
254
    except NotBranchError:
211
255
        # create a branch.
212
256
        transport = transport.clone('..')
213
257
        if not create_prefix:
214
258
            try:
215
259
                relurl = transport.relpath(location_url)
216
260
                transport.mkdir(relurl)
217
 
            except errors.NoSuchFile:
218
 
                error_dialog(_('Non existing parent directory'),
219
 
                                         _("The parent directory (%s)\ndoesn't exist.") % location)
220
 
                return
 
261
            except NoSuchFile:
 
262
                raise NonExistingParent(location)
221
263
        else:
222
264
            current = transport.base
223
265
            needed = [(transport, transport.relpath(location_url))]
226
268
                    transport, relpath = needed[-1]
227
269
                    transport.mkdir(relpath)
228
270
                    needed.pop()
229
 
                except errors.NoSuchFile:
 
271
                except NoSuchFile:
230
272
                    new_transport = transport.clone('..')
231
273
                    needed.append((new_transport,
232
274
                                   new_transport.relpath(transport.base)))
233
275
                    if new_transport.base == transport.base:
234
 
                        error_dialog(_('Path prefix not created'),
235
 
                                                 _("The path leading up to the specified location couldn't\nbe created."))
236
 
                        return
 
276
                        raise PathPrefixNotCreated
237
277
        dir_to = br_from.bzrdir.clone(location_url,
238
278
            revision_id=br_from.last_revision())
239
279
        br_to = dir_to.open_branch()
241
281
    else:
242
282
        old_rh = br_to.revision_history()
243
283
        try:
244
 
            tree_to = dir_to.open_workingtree()
245
 
        except errors.NotLocalUrl:
246
 
            # FIXME - what to do here? how should we warn the user?
247
 
            #warning('This transport does not update the working '
248
 
            #        'tree of: %s' % (br_to.base,))
249
 
            count = br_to.pull(br_from, overwrite)
250
 
        except errors.NoWorkingTree:
251
 
            count = br_to.pull(br_from, overwrite)
252
 
        else:
253
 
            count = tree_to.pull(br_from, overwrite)
254
 
 
 
284
            try:
 
285
                tree_to = dir_to.open_workingtree()
 
286
            except NotLocalUrl:
 
287
                # FIXME - what to do here? how should we warn the user?
 
288
                #warning('This transport does not update the working '
 
289
                #        'tree of: %s' % (br_to.base,))
 
290
                count = br_to.pull(br_from, overwrite)
 
291
            except NoWorkingTree:
 
292
                count = br_to.pull(br_from, overwrite)
 
293
            else:
 
294
                count = tree_to.pull(br_from, overwrite)
 
295
        except DivergedBranches:
 
296
            raise DivergedBranchesError
 
297
    
255
298
    return count