/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: Szilveszter Farkas (Phanatic)
  • Date: 2006-09-30 13:04:15 UTC
  • mto: (0.14.3 main)
  • mto: This revision was merged to the branch mainline in revision 86.
  • Revision ID: Szilveszter.Farkas@gmail.com-20060930130415-aba4100709e11f0a
Loads of fixes. Pyflakes cleanup.

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 olive import gladefile
 
30
from dialog import error_dialog, info_dialog
 
31
 
33
32
class OlivePush:
34
33
    """ Display Push dialog and perform the needed actions. """
35
 
    def __init__(self, gladefile, comm, dialog):
 
34
    def __init__(self, branch):
36
35
        """ 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
 
36
        self.glade = gtk.glade.XML(gladefile, 'window_push')
44
37
        
45
38
        self.window = self.glade.get_widget('window_push')
 
39
 
 
40
        self.branch = branch
46
41
        
47
42
        # Dictionary for signal_autoconnect
48
43
        dic = { "on_button_push_push_clicked": self.push,
69
64
        self.entry_location.set_sensitive(0)
70
65
        self.check_remember.set_sensitive(0)
71
66
        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
 
67
        
 
68
        self.entry_stored.set_text(branch.get_push_location())
84
69
    
85
70
    def display(self):
86
71
        """ 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()
 
72
        self.window.show()
 
73
        self.width, self.height = self.window.get_size()
94
74
    
95
75
    def stored_toggled(self, widget):
96
76
        if widget.get_active():
118
98
    
119
99
    def push(self, widget):
120
100
        revs = 0
121
 
        self.comm.set_busy(self.window)
122
101
        if self.radio_stored.get_active():
123
102
            try:
124
 
                revs = do_push(self.comm.get_path(),
 
103
                revs = do_push(self.branch,
125
104
                               overwrite=self.check_overwrite.get_active())
126
105
            except errors.NotBranchError:
127
 
                self.dialog.error_dialog(_('Directory is not a branch'),
128
 
                                         _('You can perform this action only in a branch.'))
 
106
                error_dialog(_('Directory is not a branch'),
 
107
                             _('You can perform this action only in a branch.'))
129
108
                return
130
109
            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.'))
 
110
                error_dialog(_('Branches have been diverged'),
 
111
                             _('You cannot push if branches have diverged. Use the\noverwrite option if you want to push anyway.'))
133
112
                return
134
 
            except:
135
 
                raise
136
113
        elif self.radio_specific.get_active():
137
114
            location = self.entry_location.get_text()
138
115
            if location == '':
139
 
                self.dialog.error_dialog(_('No location specified'),
140
 
                                         _('Please specify a location or use the default.'))
 
116
                error_dialog(_('No location specified'),
 
117
                             _('Please specify a location or use the default.'))
141
118
                return
142
119
            
143
120
            try:
144
 
                revs = do_push(self.comm.get_path(), location,
 
121
                revs = do_push(self.branch, location,
145
122
                               self.check_remember.get_active(),
146
123
                               self.check_overwrite.get_active(),
147
124
                               self.check_create.get_active())
148
125
            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)
 
126
                error_dialog(_('Directory is not a branch'),
 
127
                             _('You can perform this action only in a branch.'))
152
128
                return
153
129
            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)
 
130
                error_dialog(_('Branches have been diverged'),
 
131
                             _('You cannot push if branches have diverged. Use the\noverwrite option if you want to push anyway.'))
157
132
                return
158
 
            except:
159
 
                raise
160
 
        else:
161
 
            # This should really never happen
162
 
            pass
163
133
        
164
134
        self.close()
165
 
        self.dialog.info_dialog(_('Push successful'),
166
 
                                _('%d revision(s) pushed.') % revs)
 
135
        info_dialog(_('Push successful'),
 
136
                    _('%d revision(s) pushed.') % revs)
167
137
    
168
138
    def test(self, widget):
169
139
        """ Test if write access possible. """
219
189
    stored_loc = br_from.get_push_location()
220
190
    if location is None:
221
191
        if stored_loc is None:
222
 
            self.dialog.error_dialog(_('Push location is unknown'),
 
192
            error_dialog(_('Push location is unknown'),
223
193
                                     _('Please specify a location manually.'))
224
194
            return
225
195
        else:
244
214
                relurl = transport.relpath(location_url)
245
215
                transport.mkdir(relurl)
246
216
            except errors.NoSuchFile:
247
 
                self.dialog.error_dialog(_('Non existing parent directory'),
248
 
                                         _("The parent directory (%s)\ndoesn't exist.") % location)
 
217
                error_dialog(_('Non existing parent directory'),
 
218
                             _("The parent directory (%s)\ndoesn't exist.") % location)
249
219
                return
250
220
        else:
251
221
            current = transport.base
260
230
                    needed.append((new_transport,
261
231
                                   new_transport.relpath(transport.base)))
262
232
                    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."))
 
233
                        error_dialog(_('Path prefix not created'),
 
234
                                     _("The path leading up to the specified location couldn't\nbe created."))
265
235
                        return
266
236
        dir_to = br_from.bzrdir.clone(location_url,
267
237
            revision_id=br_from.last_revision())
270
240
    else:
271
241
        old_rh = br_to.revision_history()
272
242
        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
 
    
 
243
            tree_to = dir_to.open_workingtree()
 
244
        except errors.NotLocalUrl:
 
245
            # FIXME - what to do here? how should we warn the user?
 
246
            #warning('This transport does not update the working '
 
247
            #        'tree of: %s' % (br_to.base,))
 
248
            count = br_to.pull(br_from, overwrite)
 
249
        except errors.NoWorkingTree:
 
250
            count = br_to.pull(br_from, overwrite)
 
251
        else:
 
252
            count = tree_to.pull(br_from, overwrite)
 
253
 
287
254
    return count