/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: 2007-02-01 15:50:40 UTC
  • Revision ID: jelmer@samba.org-20070201155040-3hq4mfbxs99kzazy
add framework for tests.

Show diffs side-by-side

added added

removed removed

Lines of Context:
14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
 
import sys
18
 
 
19
17
try:
20
18
    import pygtk
21
19
    pygtk.require("2.0")
22
20
except:
23
21
    pass
24
 
try:
25
 
    import gtk
26
 
    import gtk.gdk
27
 
    import gtk.glade
28
 
except:
29
 
    sys.exit(1)
 
22
    
 
23
import gtk
 
24
import gtk.gdk
 
25
import gtk.glade
30
26
 
31
27
import bzrlib.errors as errors
32
28
 
 
29
from dialog import error_dialog, info_dialog
 
30
from guifiles import GLADEFILENAME
 
31
 
 
32
 
33
33
class OlivePush:
34
34
    """ Display Push dialog and perform the needed actions. """
35
 
    def __init__(self, gladefile, comm, dialog):
 
35
    def __init__(self, branch):
36
36
        """ Initialize the Push dialog. """
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
 
37
        self.glade = gtk.glade.XML(GLADEFILENAME, 'window_push')
44
38
        
45
39
        self.window = self.glade.get_widget('window_push')
 
40
 
 
41
        self.branch = branch
46
42
        
47
43
        # Dictionary for signal_autoconnect
48
44
        dic = { "on_button_push_push_clicked": self.push,
69
65
        self.entry_location.set_sensitive(0)
70
66
        self.check_remember.set_sensitive(0)
71
67
        self.check_create.set_sensitive(0)
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
 
68
        
 
69
        self.entry_stored.set_text(branch.get_push_location() or '')
84
70
    
85
71
    def display(self):
86
72
        """ Display the Push dialog. """
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()
 
73
        self.window.show()
 
74
        self.width, self.height = self.window.get_size()
94
75
    
95
76
    def stored_toggled(self, widget):
96
77
        if widget.get_active():
118
99
    
119
100
    def push(self, widget):
120
101
        revs = 0
121
 
        self.comm.set_busy(self.window)
122
102
        if self.radio_stored.get_active():
123
103
            try:
124
 
                revs = do_push(self.comm.get_path(),
 
104
                revs = do_push(self.branch,
125
105
                               overwrite=self.check_overwrite.get_active())
126
 
            except errors.NotBranchError:
127
 
                self.dialog.error_dialog(_('Directory is not a branch'),
128
 
                                         _('You can perform this action only in a branch.'))
129
 
                return
130
106
            except errors.DivergedBranches:
131
 
                self.dialog.error_dialog(_('Branches have been diverged'),
132
 
                                         _('You cannot push if branches have diverged. Use the\noverwrite option if you want to push anyway.'))
 
107
                response = question_dialog(_('Branches have been diverged'),
 
108
                             _('You cannot push if branches have diverged. \nOverwrite?'))
 
109
                if response == gtk.RESPONSE_OK:
 
110
                    revs = do_push(self.branch, overwrite=True)
133
111
                return
134
 
            except:
135
 
                raise
136
112
        elif self.radio_specific.get_active():
137
113
            location = self.entry_location.get_text()
138
114
            if location == '':
139
 
                self.dialog.error_dialog(_('No location specified'),
140
 
                                         _('Please specify a location or use the default.'))
 
115
                error_dialog(_('No location specified'),
 
116
                             _('Please specify a location or use the default.'))
141
117
                return
142
118
            
143
119
            try:
144
 
                revs = do_push(self.comm.get_path(), location,
 
120
                revs = do_push(self.branch, location,
145
121
                               self.check_remember.get_active(),
146
 
                               self.check_overwrite.get_active(),
 
122
                               False,
147
123
                               self.check_create.get_active())
148
 
            except errors.NotBranchError:
149
 
                self.dialog.error_dialog(_('Directory is not a branch'),
150
 
                                         _('You can perform this action only in a branch.'))
151
 
                self.comm.set_busy(self.window, False)
152
 
                return
153
124
            except errors.DivergedBranches:
154
 
                self.dialog.error_dialog(_('Branches have been diverged'),
155
 
                                         _('You cannot push if branches have diverged. Use the\noverwrite option if you want to push anyway.'))
156
 
                self.comm.set_busy(self.window, False)
157
 
                return
158
 
            except:
159
 
                raise
160
 
        else:
161
 
            # This should really never happen
162
 
            pass
 
125
                response = question_dialog(_('Branches have been diverged'),
 
126
                             _('You cannot push if branches have diverged. \nOverwrite?'))
 
127
                if response == gtk.RESPONSE_OK:
 
128
                    revs = do_push(self.branch, location,
 
129
                        self.check_remember.get_active(),
 
130
                            True,
 
131
                            self.check_create.get_active())
 
132
                else:
 
133
                    return
163
134
        
164
135
        self.close()
165
 
        self.dialog.info_dialog(_('Push successful'),
166
 
                                _('%d revision(s) pushed.') % revs)
 
136
        info_dialog(_('Push successful'),
 
137
                    _('%d revision(s) pushed.') % revs)
167
138
    
168
139
    def test(self, widget):
169
140
        """ Test if write access possible. """
214
185
    from bzrlib.bzrdir import BzrDir
215
186
    from bzrlib.transport import get_transport
216
187
        
217
 
    br_from = Branch.open_containing(branch)[0]
 
188
    br_from = branch
218
189
    
219
190
    stored_loc = br_from.get_push_location()
220
191
    if location is None:
221
192
        if stored_loc is None:
222
 
            self.dialog.error_dialog(_('Push location is unknown'),
223
 
                                     _('Please specify a location manually.'))
 
193
            error_dialog(_('Push location is unknown'),
 
194
                         _('Please specify a location manually.'))
224
195
            return
225
196
        else:
226
197
            location = stored_loc
244
215
                relurl = transport.relpath(location_url)
245
216
                transport.mkdir(relurl)
246
217
            except errors.NoSuchFile:
247
 
                self.dialog.error_dialog(_('Non existing parent directory'),
248
 
                                         _("The parent directory (%s)\ndoesn't exist.") % location)
 
218
                error_dialog(_('Non existing parent directory'),
 
219
                             _("The parent directory (%s)\ndoesn't exist.") % location)
249
220
                return
250
221
        else:
251
222
            current = transport.base
260
231
                    needed.append((new_transport,
261
232
                                   new_transport.relpath(transport.base)))
262
233
                    if new_transport.base == transport.base:
263
 
                        self.dialog.error_dialog(_('Path prefix not created'),
264
 
                                                 _("The path leading up to the specified location couldn't\nbe created."))
 
234
                        error_dialog(_('Path prefix not created'),
 
235
                                     _("The path leading up to the specified location couldn't\nbe created."))
265
236
                        return
266
237
        dir_to = br_from.bzrdir.clone(location_url,
267
238
            revision_id=br_from.last_revision())
270
241
    else:
271
242
        old_rh = br_to.revision_history()
272
243
        try:
273
 
            try:
274
 
                tree_to = dir_to.open_workingtree()
275
 
            except errors.NotLocalUrl:
276
 
                # FIXME - what to do here? how should we warn the user?
277
 
                #warning('This transport does not update the working '
278
 
                #        'tree of: %s' % (br_to.base,))
279
 
                count = br_to.pull(br_from, overwrite)
280
 
            except errors.NoWorkingTree:
281
 
                count = br_to.pull(br_from, overwrite)
282
 
            else:
283
 
                count = tree_to.pull(br_from, overwrite)
284
 
        except errors.DivergedBranches:
285
 
            raise
286
 
    
 
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
 
287
255
    return count