1
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic) <szilveszter.farkas@gmail.com>
1
# Copyright (C) 2006 by Szilveszter Farkas (Phanatic)
2
# <szilveszter.farkas@gmail.com>
3
# Copyright (C) 2007 by Jelmer Vernooij <jelmer@samba.org>
3
5
# This program is free software; you can redistribute it and/or modify
4
6
# it under the terms of the GNU General Public License as published by
5
7
# the Free Software Foundation; either version 2 of the License, or
6
8
# (at your option) any later version.
8
10
# This program is distributed in the hope that it will be useful,
9
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
13
# GNU General Public License for more details.
13
15
# You should have received a copy of the GNU General Public License
14
16
# along with this program; if not, write to the Free Software
15
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
30
import olive.backend.commit as commit
31
import olive.backend.errors as errors
34
""" Display Push dialog and perform the needed actions. """
35
def __init__(self, gladefile, comm):
36
""" Initialize the Push dialog. """
37
self.gladefile = gladefile
38
self.glade = gtk.glade.XML(self.gladefile, 'window_push')
42
self.window = self.glade.get_widget('window_push')
44
# Dictionary for signal_autoconnect
45
dic = { "on_button_push_push_clicked": self.push,
46
"on_button_push_cancel_clicked": self.close,
47
"on_radiobutton_push_stored_toggled": self.stored_toggled,
48
"on_radiobutton_push_specific_toggled": self.specific_toggled, }
50
# Connect the signals to the handlers
51
self.glade.signal_autoconnect(dic)
53
# Get some useful widgets
54
self.entry_location = self.glade.get_widget('entry_push_location')
55
self.check_remember = self.glade.get_widget('checkbutton_push_remember')
56
self.check_overwrite = self.glade.get_widget('checkbutton_push_overwrite')
57
self.check_create = self.glade.get_widget('checkbutton_push_create')
60
""" Display the Push dialog. """
63
def stored_toggled(self, widget):
64
if widget.get_active():
65
self.entry_location.hide()
66
self.check_remember.hide()
67
self.check_overwrite.hide()
68
self.check_create.hide()
70
self.entry_location.show()
71
self.check_remember.show()
72
self.check_overwrite.show()
73
self.check_create.show()
75
def specific_toggled(self, widget):
76
if widget.get_active():
77
self.entry_location.show()
78
self.check_remember.show()
79
self.check_overwrite.show()
80
self.check_create.show()
82
self.entry_location.hide()
83
self.check_remember.hide()
84
self.check_overwrite.hide()
85
self.check_create.hide()
87
def push(self, widget):
88
from dialog import OliveDialog
89
dialog = OliveDialog(self.gladefile)
91
radio_stored = self.glade.get_widget('radiobutton_push_stored')
92
radio_specific = self.glade.get_widget('radiobutton_push_specific')
94
if radio_stored.get_active():
96
commit.push(self.comm.get_path())
97
except errors.NotBranchError:
98
dialog.error_dialog('Directory is not a branch.')
100
except errors.NoLocationKnown:
101
dialog.error_dialog('No location known.')
103
except errors.NonExistingParent, errmsg:
104
dialog.error_dialog('Parent directory doesn\'t exist: %s', errmsg)
106
except errors.DivergedBranchesError:
107
dialog.error_dialog('Branches have been diverged.')
111
elif radio_specific.get_active():
112
location = self.entry_location.get_text()
114
dialog.error_dialog('No location specified.')
118
commit.push(self.comm.get_path(), location,
119
self.check_remember.get_active(),
120
self.check_overwrite.get_active(),
121
self.check_create.get_active())
122
except errors.NotBranchError:
123
dialog.error_dialog('Directory is not a branch.')
125
except errors.NonExistingParent, errmsg:
126
dialog.error_dialog('Parent directory doesn\'t exist: %s', errmsg)
128
except errors.DivergedBranchesError:
129
dialog.error_dialog('Branches have been diverged.')
131
except errors.PathPrefixNotCreated:
132
dialog.error_dialog('Path prefix couldn\'t be created.')
137
# This should really never happen
142
def close(self, widget=None):
143
self.window.destroy()
19
from gi.repository import Gtk
21
from errors import show_bzr_error
27
from bzrlib.bzrdir import BzrDir
28
from bzrlib.transport import get_transport
30
from bzrlib.plugins.gtk.dialog import (
33
from bzrlib.plugins.gtk.history import UrlHistory
34
from bzrlib.plugins.gtk.i18n import _i18n
35
from bzrlib.plugins.gtk.ui import ProgressPanel
38
class PushDialog(Gtk.Dialog):
39
"""New implementation of the Push dialog."""
41
def __init__(self, repository, revid, branch=None, parent=None):
42
"""Initialize the Push dialog. """
43
super(PushDialog, self).__init__(
44
title="Push", parent=parent, flags=0, border_width=6,
45
buttons=(Gtk.STOCK_CLOSE, Gtk.ResponseType.CLOSE))
49
self.repository = repository
53
self._label_location = Gtk.Label(label=_i18n("Location:"))
54
self._combo = Gtk.ComboBox.new_with_entry()
55
self._button_push = Gtk.Button(_i18n("_Push"), use_underline=True)
56
self._hbox_location = Gtk.Box(Gtk.Orientation.HORIZONTAL, 6)
57
self._push_message = Gtk.Label(xalign=0)
58
self._progress_widget = ProgressPanel()
61
ui.ui_factory.set_progress_bar_widget(self._progress_widget)
62
self.connect('close', self._on_close_clicked)
63
self._button_push.connect('clicked', self._on_push_clicked)
66
content_area = self.get_content_area()
67
content_area.set_spacing(6)
70
self._hbox_location.pack_start(self._label_location, False, False, 0)
71
self._hbox_location.pack_start(self._combo, False, False, 0)
72
content_area.pack_start(self._hbox_location, True, True, 0)
73
content_area.pack_start(self._progress_widget, True, True, 0)
74
content_area.pack_start(self._push_message, True, True, 0)
75
self.get_action_area().pack_end(self._button_push, True, True, 0)
78
content_area.show_all()
79
self._progress_widget.hide()
80
self._push_message.hide()
82
# Build location history
83
self._history = UrlHistory(self.branch.get_config(), 'push_history')
86
def _build_history(self):
87
"""Build up the location history. """
88
self._combo_model = Gtk.ListStore(str)
89
for item in self._history.get_entries():
90
self._combo_model.append([item])
91
self._combo.set_model(self._combo_model)
92
self._combo.set_entry_text_column(0)
94
if self.branch is not None:
95
location = self.branch.get_push_location()
96
if location is not None:
97
self._combo.get_child().set_text(location)
99
def _on_close_clicked(self, widget):
100
"""Close dialog handler."""
101
ui.ui_factory.set_progress_bar_widget(None)
104
def _on_push_clicked(self, widget):
105
"""Push button clicked handler. """
106
self._push_message.hide()
107
self._progress_widget.tick()
108
location = self._combo.get_child().get_text()
111
message = do_push(self.branch, location, overwrite=False)
112
except errors.DivergedBranches:
113
response = question_dialog(
114
_i18n('Branches have been diverged'),
115
_i18n('You cannot push if branches have diverged.\n'
117
if response == Gtk.ResponseType.YES:
118
message = do_push(self.branch, location, overwrite=True)
121
self._history.add_entry(location)
122
if (self.branch is not None
123
and self.branch.get_push_location() is None):
124
self.branch.set_push_location(location)
126
self._progress_widget.finished()
127
self._push_message.props.label = message
128
self._push_message.show()
131
def do_push(br_from, location, overwrite):
132
"""Update a mirror of a branch.
134
:param br_from: the source branch
135
:param location: the location of the branch that you'd like to update
136
:param overwrite: overwrite target location if it diverged
137
:return: number of revisions pushed
139
transport = get_transport(location)
140
location_url = transport.base
143
dir_to = BzrDir.open(location_url)
144
br_to = dir_to.open_branch()
145
except errors.NotBranchError:
147
transport = transport.clone('..')
149
relurl = transport.relpath(location_url)
150
transport.mkdir(relurl)
151
except errors.NoSuchFile:
152
response = question_dialog(
153
_i18n('Non existing parent directory'),
154
_i18n("The parent directory (%s)\ndoesn't exist. Create?") %
156
if response == Gtk.ResponseType.OK:
157
transport.create_prefix()
160
dir_to = br_from.bzrdir.clone(location_url,
161
revision_id=br_from.last_revision())
162
br_to = dir_to.open_branch()
163
count = len(br_to.revision_history())
165
br_to.revision_history()
167
tree_to = dir_to.open_workingtree()
168
except errors.NotLocalUrl:
169
# FIXME - what to do here? how should we warn the user?
170
count = br_to.pull(br_from, overwrite)
171
except errors.NoWorkingTree:
172
count = br_to.pull(br_from, overwrite)
174
count = tree_to.pull(br_from, overwrite)
176
# The count var is either an int or a PushResult. PushResult is being
177
# coerced into an int, but the method is deprecated.
178
return _i18n("%d revision(s) pushed.") % int(count)