7 Module implementing a dialog to define guards for patches. |
7 Module implementing a dialog to define guards for patches. |
8 """ |
8 """ |
9 |
9 |
10 from __future__ import unicode_literals |
10 from __future__ import unicode_literals |
11 try: |
11 try: |
12 str = unicode # __IGNORE_WARNING__ |
12 str = unicode |
13 except (NameError): |
13 except NameError: |
14 pass |
14 pass |
15 |
15 |
16 import os |
16 import os |
17 |
17 |
18 from PyQt4.QtCore import pyqtSlot, Qt, QProcess, QTimer, QCoreApplication |
18 from PyQt4.QtCore import pyqtSlot, Qt, QProcess, QTimer, QCoreApplication |
77 self.process.waitForFinished(3000) |
76 self.process.waitForFinished(3000) |
78 |
77 |
79 if self.__dirtyList: |
78 if self.__dirtyList: |
80 res = E5MessageBox.question( |
79 res = E5MessageBox.question( |
81 self, |
80 self, |
82 self.trUtf8("Unsaved Changes"), |
81 self.tr("Unsaved Changes"), |
83 self.trUtf8("""The guards list has been changed.""" |
82 self.tr("""The guards list has been changed.""" |
84 """ Shall the changes be applied?"""), |
83 """ Shall the changes be applied?"""), |
85 E5MessageBox.StandardButtons( |
84 E5MessageBox.StandardButtons( |
86 E5MessageBox.Apply | |
85 E5MessageBox.Apply | |
87 E5MessageBox.Discard), |
86 E5MessageBox.Discard), |
88 E5MessageBox.Apply) |
87 E5MessageBox.Apply) |
89 if res == E5MessageBox.Apply: |
88 if res == E5MessageBox.Apply: |
120 @param patch selected patch name (empty for current patch) |
119 @param patch selected patch name (empty for current patch) |
121 """ |
120 """ |
122 if self.__dirtyList: |
121 if self.__dirtyList: |
123 res = E5MessageBox.question( |
122 res = E5MessageBox.question( |
124 self, |
123 self, |
125 self.trUtf8("Unsaved Changes"), |
124 self.tr("Unsaved Changes"), |
126 self.trUtf8("""The guards list has been changed.""" |
125 self.tr("""The guards list has been changed.""" |
127 """ Shall the changes be applied?"""), |
126 """ Shall the changes be applied?"""), |
128 E5MessageBox.StandardButtons( |
127 E5MessageBox.StandardButtons( |
129 E5MessageBox.Apply | |
128 E5MessageBox.Apply | |
130 E5MessageBox.Discard), |
129 E5MessageBox.Discard), |
131 E5MessageBox.Apply) |
130 E5MessageBox.Apply) |
132 if res == E5MessageBox.Apply: |
131 if res == E5MessageBox.Apply: |
140 self.guardCombo.clear() |
139 self.guardCombo.clear() |
141 guardsList = self.extension.getGuardsList(self.__repodir) |
140 guardsList = self.extension.getGuardsList(self.__repodir) |
142 self.guardCombo.addItems(guardsList) |
141 self.guardCombo.addItems(guardsList) |
143 self.guardCombo.setEditText("") |
142 self.guardCombo.setEditText("") |
144 |
143 |
145 args = [] |
144 args = self.vcs.initCommand("qguard") |
146 args.append("qguard") |
|
147 if patch: |
145 if patch: |
148 args.append(patch) |
146 args.append(patch) |
149 |
147 |
150 output = "" |
148 output = "" |
151 if self.__hgClient: |
149 if self.__hgClient: |
152 output = self.__hgClient.runcommand(args)[0] |
150 output = self.__hgClient.runcommand(args)[0] |
153 else: |
151 else: |
154 ioEncoding = Preferences.getSystem("IOEncoding") |
|
155 process = QProcess() |
152 process = QProcess() |
156 process.setWorkingDirectory(self.__repodir) |
153 process.setWorkingDirectory(self.__repodir) |
157 process.start('hg', args) |
154 process.start('hg', args) |
158 procStarted = process.waitForStarted(5000) |
155 procStarted = process.waitForStarted(5000) |
159 if procStarted: |
156 if procStarted: |
160 finished = process.waitForFinished(30000) |
157 finished = process.waitForFinished(30000) |
161 if finished and process.exitCode() == 0: |
158 if finished and process.exitCode() == 0: |
162 output = str(process.readAllStandardOutput(), ioEncoding, |
159 output = str(process.readAllStandardOutput(), |
163 'replace').strip() |
160 self.vcs.getEncoding(), 'replace').strip() |
164 |
161 |
165 if output: |
162 if output: |
166 patchName, guards = output.split(":", 1) |
163 patchName, guards = output.split(":", 1) |
167 self.patchNameLabel.setText(patchName) |
164 self.patchNameLabel.setText(patchName) |
168 guardsList = guards.strip().split() |
165 guardsList = guards.strip().split() |
243 """ |
240 """ |
244 Private slot to remove guard definitions from the list. |
241 Private slot to remove guard definitions from the list. |
245 """ |
242 """ |
246 res = E5MessageBox.yesNo( |
243 res = E5MessageBox.yesNo( |
247 self, |
244 self, |
248 self.trUtf8("Remove Guards"), |
245 self.tr("Remove Guards"), |
249 self.trUtf8( |
246 self.tr( |
250 """Do you really want to remove the selected guards?""")) |
247 """Do you really want to remove the selected guards?""")) |
251 if res: |
248 if res: |
252 for guardItem in self.guardsList.selectedItems(): |
249 for guardItem in self.guardsList.selectedItems(): |
253 row = self.guardsList.row(guardItem) |
250 row = self.guardsList.row(guardItem) |
254 itm = self.guardsList.takeItem(row) |
251 itm = self.guardsList.takeItem(row) |
278 for row in range(self.guardsList.count()): |
275 for row in range(self.guardsList.count()): |
279 itm = self.guardsList.item(row) |
276 itm = self.guardsList.item(row) |
280 guard = itm.data(Qt.UserRole) + itm.text() |
277 guard = itm.data(Qt.UserRole) + itm.text() |
281 guardsList.append(guard) |
278 guardsList.append(guard) |
282 |
279 |
283 args = [] |
280 args = self.vcs.initCommand("qguard") |
284 args.append("qguard") |
|
285 args.append(self.patchNameLabel.text()) |
281 args.append(self.patchNameLabel.text()) |
286 if guardsList: |
282 if guardsList: |
287 args.append("--") |
283 args.append("--") |
288 args.extend(guardsList) |
284 args.extend(guardsList) |
289 else: |
285 else: |
291 |
287 |
292 error = "" |
288 error = "" |
293 if self.__hgClient: |
289 if self.__hgClient: |
294 error = self.__hgClient.runcommand(args)[1] |
290 error = self.__hgClient.runcommand(args)[1] |
295 else: |
291 else: |
296 ioEncoding = Preferences.getSystem("IOEncoding") |
|
297 process = QProcess() |
292 process = QProcess() |
298 process.setWorkingDirectory(self.__repodir) |
293 process.setWorkingDirectory(self.__repodir) |
299 process.start('hg', args) |
294 process.start('hg', args) |
300 procStarted = process.waitForStarted(5000) |
295 procStarted = process.waitForStarted(5000) |
301 if procStarted: |
296 if procStarted: |
302 finished = process.waitForFinished(30000) |
297 finished = process.waitForFinished(30000) |
303 if finished: |
298 if finished: |
304 if process.exitCode() != 0: |
299 if process.exitCode() != 0: |
305 error = str( |
300 error = str(process.readAllStandardError(), |
306 process.readAllStandardError(), ioEncoding, |
301 self.vcs.getEncoding(), 'replace') |
307 'replace') |
|
308 else: |
302 else: |
309 E5MessageBox.warning( |
303 E5MessageBox.warning( |
310 self, |
304 self, |
311 self.trUtf8("Apply Guard Definitions"), |
305 self.tr("Apply Guard Definitions"), |
312 self.trUtf8( |
306 self.tr( |
313 """The Mercurial process did not finish""" |
307 """The Mercurial process did not finish""" |
314 """ in time.""")) |
308 """ in time.""")) |
315 |
309 |
316 if error: |
310 if error: |
317 E5MessageBox.warning( |
311 E5MessageBox.warning( |
318 self, |
312 self, |
319 self.trUtf8("Apply Guard Definitions"), |
313 self.tr("Apply Guard Definitions"), |
320 self.trUtf8("""<p>The defined guards could not be""" |
314 self.tr("""<p>The defined guards could not be""" |
321 """ applied.</p><p>Reason: {0}</p>""") |
315 """ applied.</p><p>Reason: {0}</p>""") |
322 .format(error)) |
316 .format(error)) |
323 else: |
317 else: |
324 self.__dirtyList = False |
318 self.__dirtyList = False |
325 self.on_patchSelector_activated( |
319 self.on_patchSelector_activated( |
326 self.patchNameLabel.text()) |
320 self.patchNameLabel.text()) |