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

  • Committer: Curtis Hovey
  • Date: 2011-08-12 20:25:28 UTC
  • mto: This revision was merged to the branch mainline in revision 741.
  • Revision ID: sinzui.is@verizon.net-20110812202528-4xf4a2t23urx50d2
Updated gst to gtk3.

Show diffs side-by-side

added added

removed removed

Lines of Context:
15
15
# along with this program; if not, write to the Free Software
16
16
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17
17
 
18
 
try:
19
 
    import pygtk
20
 
    pygtk.require("2.0")
21
 
except:
22
 
    pass
23
 
    
24
 
import gtk
 
18
from gi.repository import GObject
 
19
from gi.repository import Gtk
25
20
 
26
21
from errors import show_bzr_error
27
22
 
28
 
# FIXME: This needs to be public JRV 20070714
29
 
from bzrlib.builtins import _create_prefix
30
 
from bzrlib.config import LocationConfig
31
23
import bzrlib.errors as errors
32
24
 
33
 
from bzrlib.plugins.gtk import _i18n
34
 
from dialog import error_dialog, info_dialog, question_dialog
35
 
 
36
 
from history import UrlHistory
37
 
 
38
 
class PushDialog(gtk.Dialog):
39
 
    """ New implementation of the Push dialog. """
 
25
from bzrlib.plugins.gtk.dialog import (
 
26
    info_dialog,
 
27
    question_dialog,
 
28
    )
 
29
 
 
30
from bzrlib.plugins.gtk.history import UrlHistory
 
31
from bzrlib.plugins.gtk.i18n import _i18n
 
32
 
 
33
 
 
34
class PushDialog(Gtk.Dialog):
 
35
    """New implementation of the Push dialog."""
 
36
 
40
37
    def __init__(self, repository, revid, branch=None, parent=None):
41
 
        """ Initialize the Push dialog. """
42
 
        gtk.Dialog.__init__(self, title="Push - Olive",
 
38
        """Initialize the Push dialog. """
 
39
        GObject.GObject.__init__(self, title="Push",
43
40
                                  parent=parent,
44
41
                                  flags=0,
45
 
                                  buttons=(gtk.STOCK_CANCEL, gtk.RESPONSE_CANCEL))
46
 
        
 
42
                                  buttons=(Gtk.STOCK_CANCEL, Gtk.ResponseType.CANCEL))
 
43
 
47
44
        # Get arguments
48
45
        self.repository = repository
49
46
        self.revid = revid
50
47
        self.branch = branch
51
 
        
 
48
 
52
49
        # Create the widgets
53
 
        self._label_location = gtk.Label(_i18n("Location:"))
54
 
        self._combo = gtk.ComboBoxEntry()
55
 
        self._button_push = gtk.Button(_i18n("_Push"), use_underline=True)
56
 
        self._hbox_location = gtk.HBox()
57
 
        
 
50
        self._label_location = Gtk.Label(label=_i18n("Location:"))
 
51
        self._combo = Gtk.ComboBoxEntry()
 
52
        self._button_push = Gtk.Button(_i18n("_Push"), use_underline=True)
 
53
        self._hbox_location = Gtk.HBox()
 
54
 
58
55
        # Set callbacks
59
56
        self._button_push.connect('clicked', self._on_push_clicked)
60
 
        
 
57
 
61
58
        # Set properties
62
59
        self._label_location.set_alignment(0, 0.5)
63
60
        self._hbox_location.set_spacing(3)
64
61
        self.vbox.set_spacing(3)
65
 
        
 
62
 
66
63
        # Pack widgets
67
64
        self._hbox_location.pack_start(self._label_location, False, False)
68
65
        self._hbox_location.pack_start(self._combo, True, True)
69
 
        self.vbox.pack_start(self._hbox_location)
 
66
        self.vbox.pack_start(self._hbox_location, True, True, 0)
70
67
        self.action_area.pack_end(self._button_push)
71
 
        
 
68
 
72
69
        # Show the dialog
73
70
        self.vbox.show_all()
74
 
        
 
71
 
75
72
        # Build location history
76
73
        self._history = UrlHistory(self.branch.get_config(), 'push_history')
77
74
        self._build_history()
78
 
        
 
75
 
79
76
    def _build_history(self):
80
 
        """ Build up the location history. """
81
 
        self._combo_model = gtk.ListStore(str)
 
77
        """Build up the location history. """
 
78
        self._combo_model = Gtk.ListStore(str)
82
79
        for item in self._history.get_entries():
83
80
            self._combo_model.append([ item ])
84
81
        self._combo.set_model(self._combo_model)
85
82
        self._combo.set_text_column(0)
86
 
        
 
83
 
87
84
        if self.branch is not None:
88
85
            location = self.branch.get_push_location()
89
86
            if location is not None:
90
87
                self._combo.get_child().set_text(location)
91
 
    
 
88
 
92
89
    @show_bzr_error
93
90
    def _on_push_clicked(self, widget):
94
 
        """ Push button clicked handler. """
 
91
        """Push button clicked handler. """
95
92
        location = self._combo.get_child().get_text()
96
93
        revs = 0
97
 
        if self.branch is not None and self.branch.get_push_location() is None:
98
 
            response = question_dialog(_i18n('Set default push location'),
99
 
                                       _i18n('There is no default push location set.\nSet %r as default now?') % location)
100
 
            if response == gtk.RESPONSE_OK:
101
 
                self.branch.set_push_location(location)
102
94
 
103
95
        try:
104
96
            revs = do_push(self.branch, location=location, overwrite=False)
105
97
        except errors.DivergedBranches:
106
98
            response = question_dialog(_i18n('Branches have been diverged'),
107
99
                                       _i18n('You cannot push if branches have diverged.\nOverwrite?'))
108
 
            if response == gtk.RESPONSE_YES:
 
100
            if response == Gtk.ResponseType.YES:
109
101
                revs = do_push(self.branch, location=location, overwrite=True)
110
 
        
 
102
 
 
103
        if self.branch is not None and self.branch.get_push_location() is None:
 
104
            self.branch.set_push_location(location)
 
105
 
111
106
        self._history.add_entry(location)
112
107
        info_dialog(_i18n('Push successful'),
113
108
                    _i18n("%d revision(s) pushed.") % revs)
114
 
        
115
 
        self.response(gtk.RESPONSE_OK)
 
109
 
 
110
        self.response(Gtk.ResponseType.OK)
 
111
 
116
112
 
117
113
def do_push(br_from, location, overwrite):
118
 
    """ Update a mirror of a branch.
119
 
    
 
114
    """Update a mirror of a branch.
 
115
 
120
116
    :param br_from: the source branch
121
 
    
122
117
    :param location: the location of the branch that you'd like to update
123
 
    
124
118
    :param overwrite: overwrite target location if it diverged
125
 
    
126
119
    :return: number of revisions pushed
127
120
    """
128
121
    from bzrlib.bzrdir import BzrDir
129
122
    from bzrlib.transport import get_transport
130
 
        
 
123
 
131
124
    transport = get_transport(location)
132
125
    location_url = transport.base
133
126
 
145
138
        except errors.NoSuchFile:
146
139
            response = question_dialog(_i18n('Non existing parent directory'),
147
140
                         _i18n("The parent directory (%s)\ndoesn't exist. Create?") % location)
148
 
            if response == gtk.RESPONSE_OK:
149
 
                _create_prefix(transport)
 
141
            if response == Gtk.ResponseType.OK:
 
142
                transport.create_prefix()
150
143
            else:
151
144
                return
152
145
        dir_to = br_from.bzrdir.clone(location_url,