| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
om> |
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
import os |
| 21 |
|
| 22 |
from PyQt5 import QtCore |
| 23 |
|
| 24 |
from breezy import osutils |
| 25 |
from breezy.commands import get_cmd_object |
| 26 |
|
| 27 |
from breezy.plugins.qbrz.lib.subprocess import SubProcessDialog |
| 28 |
from breezy.plugins.qbrz.lib.ui_branch import Ui_BranchForm |
| 29 |
from breezy.plugins.qbrz.lib.util import ( |
| 30 |
iter_saved_pull_locations, |
| 31 |
save_pull_location, |
| 32 |
fill_combo_with, |
| 33 |
hookup_directory_picker, |
| 34 |
DIRECTORYPICKER_SOURCE, |
| 35 |
DIRECTORYPICKER_TARGET, |
| 36 |
) |
| 37 |
|
| 38 |
|
| 39 |
class QBzrBranchWindow(SubProcessDialog): |
| 40 |
|
| 41 |
NAME = "branch" |
| 42 |
|
| 43 |
def __init__(self, from_location, to_location=None, revision=None, |
| 44 |
bind=False, parent_dir=None, ui_mode=True, parent=None): |
| 45 |
super(QBzrBranchWindow, self).__init__(name = self.NAME, |
| 46 |
ui_mode = ui_mode, |
| 47 |
parent = parent) |
| 48 |
|
| 49 |
|
| 50 |
|
| 51 |
if parent_dir is None: |
| 52 |
parent_dir = os.getcwd() |
| 53 |
self.parent_dir = parent_dir |
| 54 |
|
| 55 |
|
| 56 |
self.ui = Ui_BranchForm() |
| 57 |
self.setupUi(self.ui) |
| 58 |
self.cmd_branch_options = get_cmd_object('branch').options() |
| 59 |
if 'bind' not in self.cmd_branch_options: |
| 60 |
self.ui.bind.setVisible(False) |
| 61 |
for w in self.make_default_layout_widgets(): |
| 62 |
self.layout().addWidget(w) |
| 63 |
|
| 64 |
|
| 65 |
self.ui.from_location.editTextChanged['QString'].connect(self.from_changed) |
| 66 |
|
| 67 |
|
| 68 |
fill_combo_with(self.ui.from_location, |
| 69 |
'', |
| 70 |
iter_saved_pull_locations()) |
| 71 |
if from_location: |
| 72 |
self.ui.from_location.setEditText(from_location) |
| 73 |
if to_location: |
| 74 |
self.ui.to_location.setEditText(to_location) |
| 75 |
if bind: |
| 76 |
self.ui.bind.setChecked(True) |
| 77 |
if revision: |
| 78 |
self.ui.revision.setText(revision) |
| 79 |
|
| 80 |
|
| 81 |
hookup_directory_picker(self, |
| 82 |
self.ui.from_picker, |
| 83 |
self.ui.from_location, |
| 84 |
DIRECTORYPICKER_SOURCE) |
| 85 |
hookup_directory_picker(self, |
| 86 |
self.ui.to_picker, |
| 87 |
self.ui.to_location, |
| 88 |
DIRECTORYPICKER_TARGET) |
| 89 |
|
| 90 |
|
| 91 |
if from_location: |
| 92 |
self.ui.to_location.setFocus() |
| 93 |
else: |
| 94 |
self.ui.from_location.setFocus() |
| 95 |
|
| 96 |
def from_changed(self, from_location): |
| 97 |
to_location = self._default_to_location(str(from_location)) |
| 98 |
if to_location is not None: |
| 99 |
self.ui.to_location.setEditText(to_location) |
| 100 |
|
| 101 |
def _default_to_location(self, from_location): |
| 102 |
"""Work out a good To location give a From location. |
| 103 |
|
| 104 |
:return: the To location or None if unsure |
| 105 |
""" |
| 106 |
|
| 107 |
|
| 108 |
from_location = from_location.replace('\\', '/').rstrip('/') |
| 109 |
if from_location.find('/') >= 0: |
| 110 |
basename = osutils.basename(from_location) |
| 111 |
else: |
| 112 |
|
| 113 |
ds_sep = from_location.find(':') |
| 114 |
if ds_sep >= 0: |
| 115 |
basename = from_location[ds_sep + 1:] |
| 116 |
else: |
| 117 |
return None |
| 118 |
|
| 119 |
|
| 120 |
|
| 121 |
to_location = osutils.pathjoin(self.parent_dir, basename) |
| 122 |
if to_location == from_location: |
| 123 |
return None |
| 124 |
else: |
| 125 |
return to_location |
| 126 |
|
| 127 |
def get_to_location(self): |
| 128 |
"""The path the branch was created in.""" |
| 129 |
|
| 130 |
return str(self.ui.to_location.currentText()) |
| 131 |
|
| 132 |
def do_start(self): |
| 133 |
args = [] |
| 134 |
if self.ui.bind.isChecked(): |
| 135 |
args.append('--bind') |
| 136 |
revision = str(self.ui.revision.text()) |
| 137 |
if revision: |
| 138 |
args.append('--revision') |
| 139 |
args.append(revision) |
| 140 |
from_location = str(self.ui.from_location.currentText()) |
| 141 |
to_location = self.get_to_location() |
| 142 |
if 'use-existing-dir' in self.cmd_branch_options: |
| 143 |
|
| 144 |
args.append('--use-existing-dir') |
| 145 |
self.process_widget.do_start(None, 'branch', from_location, to_location, *args) |
| 146 |
save_pull_location(None, from_location) |