Debian Codegraph @

lib/getnew.py

raw symbols SCIP
1 # -*- coding: utf-8 -*-
2 #
3 # QBrz - Qt frontend to Breezy commands
4 # Copyright (C) 2008 Canonical
5 #
6 # This program is free software; you can redistribute it and/or
7 # modify it under the terms of the GNU General Public License
8 # as published by the Free Software Foundation; either version 2
9 # of the License, or (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software
18 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19
20 # This implements the 'qupdate-hybrid' command - a hybrid update command
21 # that examines the tree being updated and displays one of 2 dialogs
22 # depending on if the tree is bound (ie, a checkout) or not.
23
24 import os
25 import re
26 from PyQt5 import QtCore
27 from breezy.plugins.qbrz.lib.i18n import gettext
28 from breezy.plugins.qbrz.lib.subprocess import SubProcessDialog
29 from breezy.plugins.qbrz.lib.ui_new_tree import Ui_NewWorkingTreeForm
30 from breezy.plugins.qbrz.lib.util import (
31 save_pull_location,
32 fill_pull_combo,
33 hookup_directory_picker,
34 DIRECTORYPICKER_SOURCE,
35 DIRECTORYPICKER_TARGET,
36 get_qbrz_config,
37 )
38
39
40 class GetNewWorkingTreeWindow(SubProcessDialog):
41
42 NAME = "new_tree"
43
44 def __init__(self, to_location, ui_mode=True, parent=None):
45 config = get_qbrz_config()
46 checkout_basedir = config.get_option("checkout_basedir")
47 branchsource_basedir = config.get_option("branchsource_basedir")
48 if not to_location:
49 to_location = checkout_basedir or '.'
50 self.to_location = os.path.abspath(to_location)
51 super(GetNewWorkingTreeWindow, self).__init__(
52 name = self.NAME,
53 ui_mode = ui_mode,
54 parent = parent)
55
56 self.ui = Ui_NewWorkingTreeForm()
57 self.ui.setupUi(self)
58 fill_pull_combo(self.ui.from_location, None)
59 # and add the subprocess widgets.
60 for w in self.make_default_layout_widgets():
61 self.layout().addWidget(w)
62
63 # Our 2 directory pickers hook up to our combos.
64 hookup_directory_picker(self,
65 self.ui.from_picker,
66 self.ui.from_location,
67 DIRECTORYPICKER_SOURCE)
68
69 hookup_directory_picker(self,
70 self.ui.to_picker,
71 self.ui.to_location,
72 DIRECTORYPICKER_TARGET)
73
74 # signal to manage updating the 'location' on the fly.
75 self.ui.from_location.editTextChanged['QString'].connect(self.from_location_changed)
76 self.ui.to_location.textChanged['QString'].connect(self.to_location_changed)
77
78 self.ui.but_checkout.setChecked(True)
79 self.ui.but_rev_tip.setChecked(True)
80 self.ui.to_location.setText(self.to_location)
81 if branchsource_basedir is not None:
82 self.from_location = branchsource_basedir
83 self.ui.from_location.setEditText(self.from_location)
84
85 def to_location_changed(self):
86 self.ui.from_location.editTextChanged['QString'].disconnect(self.from_location_changed)
87 self.ui.to_location.textChanged['QString'].disconnect(self.to_location_changed)
88
89 def from_location_changed(self, new_text):
90 new_val = self.to_location
91 tail = re.split("[:$#\\\\/]", str(new_text))[-1]
92 try:
93 projectname = re.split("[:$#\\\\/]", str(new_text))[-2]
94 except:
95 projectname = ""
96 if tail:
97 if self.checkout_basedir is not None:
98 new_val = os.path.join(self.checkout_basedir, projectname)
99 else:
100 new_val = os.path.join(new_val, tail)
101 self.ui.to_location.setText(new_val)
102
103 def _get_from_location(self):
104 return str(self.ui.from_location.currentText())
105
106 def _get_to_location(self):
107 return str(self.ui.to_location.text())
108
109 def _is_checkout_action(self):
110 return self.ui.but_checkout.isChecked()
111
112 def validate(self):
113 if not self._get_from_location():
114 self.operation_blocked(gettext("You should specify branch source"))
115 return False
116 to_location = self._get_to_location()
117 if not to_location:
118 self.operation_blocked(gettext("You should select destination directory"))
119 return False
120 # This is a check if the user really wants to checkout to a non-empty directory.
121 # Because this may create conflicts, we want to make sure this is intended.
122 if os.path.exists(to_location) and os.listdir(to_location):
123 if self._is_checkout_action():
124 quiz = gettext("Do you really want to checkout into a non-empty folder?")
125 else:
126 quiz = gettext("Do you really want to branch into a non-empty folder?")
127 reason = gettext("The destination folder is not empty.\n"
128 "Populating new working tree there may create conflicts.")
129 if not self.ask_confirmation(reason+'\n\n'+quiz, type='warning'):
130 return False
131 return True
132
133 def do_start(self):
134 from_location = self._get_from_location()
135 to_location = self._get_to_location()
136 revision_args = []
137 if self.ui.but_rev_specific.isChecked() and self.ui.revision.text():
138 revision_args.append('--revision='+str(self.ui.revision.text()))
139
140 if self._is_checkout_action():
141 args = ['checkout']
142 if self.ui.but_lightweight.isChecked():
143 args.append('--lightweight')
144 args.extend(revision_args)
145 args.append(from_location)
146 args.append(to_location)
147 else:
148 # its a 'branch'
149 args = ['branch']
150 if self.ui.but_stacked.isChecked():
151 args.append('--stacked')
152 args.extend(revision_args)
153 args.append(from_location)
154 args.append(to_location)
155
156 self.process_widget.do_start(None, *args)
157 save_pull_location(None, from_location)