| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
from breezy.plugins.qbrz.lib.i18n import gettext |
| 25 |
from breezy.plugins.qbrz.lib.subprocess import SubProcessDialog |
| 26 |
from breezy.plugins.qbrz.lib.ui_update_branch import Ui_UpdateBranchForm |
| 27 |
from breezy.plugins.qbrz.lib.ui_update_checkout import Ui_UpdateCheckoutForm |
| 28 |
from breezy.plugins.qbrz.lib.util import ( |
| 29 |
iter_saved_pull_locations, |
| 30 |
save_pull_location, |
| 31 |
fill_combo_with, |
| 32 |
fill_pull_combo, |
| 33 |
hookup_directory_picker, |
| 34 |
DIRECTORYPICKER_SOURCE, |
| 35 |
url_for_display, |
| 36 |
) |
| 37 |
|
| 38 |
|
| 39 |
class UpdateBranchWindow(SubProcessDialog): |
| 40 |
|
| 41 |
NAME = "update_branch" |
| 42 |
|
| 43 |
def __init__(self, branch, ui_mode=True, parent=None): |
| 44 |
self.branch = branch |
| 45 |
super(UpdateBranchWindow, self).__init__( |
| 46 |
name = self.NAME, |
| 47 |
ui_mode = ui_mode, |
| 48 |
parent = parent) |
| 49 |
|
| 50 |
self.ui = Ui_UpdateBranchForm() |
| 51 |
self.ui.setupUi(self) |
| 52 |
|
| 53 |
for w in self.make_default_layout_widgets(): |
| 54 |
self.layout().addWidget(w) |
| 55 |
|
| 56 |
while self.ui.location.count(): |
| 57 |
self.ui.location.removeItem(0) |
| 58 |
|
| 59 |
fill_pull_combo(self.ui.location, self.branch) |
| 60 |
|
| 61 |
|
| 62 |
hookup_directory_picker(self, |
| 63 |
self.ui.location_picker, |
| 64 |
self.ui.location, |
| 65 |
DIRECTORYPICKER_SOURCE) |
| 66 |
|
| 67 |
self.ui.but_pull.setChecked(not not self.branch.get_parent()) |
| 68 |
|
| 69 |
def _is_pull_selected(self): |
| 70 |
return self.ui.but_pull.isChecked() |
| 71 |
|
| 72 |
def _get_pull_location(self): |
| 73 |
return str(self.ui.location.currentText()) |
| 74 |
|
| 75 |
def validate(self): |
| 76 |
if self._is_pull_selected() and not self._get_pull_location(): |
| 77 |
self.operation_blocked(gettext("You should specify source branch location")) |
| 78 |
return False |
| 79 |
return True |
| 80 |
|
| 81 |
def do_start(self): |
| 82 |
if self._is_pull_selected(): |
| 83 |
|
| 84 |
args = ['--directory', self.branch.base] |
| 85 |
if self.ui.but_pull_overwrite.isChecked(): |
| 86 |
args.append('--overwrite') |
| 87 |
if self.ui.but_pull_remember.isChecked(): |
| 88 |
args.append('--remember') |
| 89 |
location = self._get_pull_location() |
| 90 |
self.process_widget.do_start(None, 'pull', location, *args) |
| 91 |
save_pull_location(self.branch, location) |
| 92 |
else: |
| 93 |
|
| 94 |
self.process_widget.do_start(None, 'update', self.branch.base) |
| 95 |
|
| 96 |
|
| 97 |
class UpdateCheckoutWindow(SubProcessDialog): |
| 98 |
|
| 99 |
NAME = "update_checkout" |
| 100 |
|
| 101 |
def __init__(self, branch, ui_mode=True, parent=None): |
| 102 |
self.branch = branch |
| 103 |
super(UpdateCheckoutWindow, self).__init__( |
| 104 |
name = self.NAME, |
| 105 |
ui_mode = ui_mode, |
| 106 |
parent = parent) |
| 107 |
|
| 108 |
self.ui = Ui_UpdateCheckoutForm() |
| 109 |
self.ui.setupUi(self) |
| 110 |
|
| 111 |
for w in self.make_default_layout_widgets(): |
| 112 |
self.layout().addWidget(w) |
| 113 |
|
| 114 |
while self.ui.location.count(): |
| 115 |
self.ui.location.removeItem(0) |
| 116 |
|
| 117 |
|
| 118 |
fill_combo_with(self.ui.location, |
| 119 |
'', |
| 120 |
iter_saved_pull_locations()) |
| 121 |
|
| 122 |
hookup_directory_picker(self, |
| 123 |
self.ui.location_picker, |
| 124 |
self.ui.location, |
| 125 |
DIRECTORYPICKER_SOURCE) |
| 126 |
|
| 127 |
|
| 128 |
loc = url_for_display(self.branch.get_bound_location()) |
| 129 |
self.ui.label.setText(str(self.ui.label.text()) % loc) |
| 130 |
self.ui.but_pull.setChecked(False) |
| 131 |
|
| 132 |
def _is_pull_selected(self): |
| 133 |
return self.ui.but_pull.isChecked() |
| 134 |
|
| 135 |
def _get_pull_location(self): |
| 136 |
return str(self.ui.location.currentText()) |
| 137 |
|
| 138 |
def validate(self): |
| 139 |
if self._is_pull_selected() and not self._get_pull_location(): |
| 140 |
self.operation_blocked(gettext("You should specify source branch location")) |
| 141 |
return False |
| 142 |
return True |
| 143 |
|
| 144 |
def do_start(self): |
| 145 |
if self._is_pull_selected(): |
| 146 |
args = ['--directory', self.branch.base] |
| 147 |
if self.ui.but_pull_overwrite.isChecked(): |
| 148 |
args.append('--overwrite') |
| 149 |
location = self._get_pull_location() |
| 150 |
self.process_widget.do_start(None, 'pull', location, *args) |
| 151 |
else: |
| 152 |
|
| 153 |
self.process_widget.do_start(None, 'update', self.branch.base) |