|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2011 - 2019 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the queues extension interface. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 try: |
|
12 str = unicode |
|
13 except NameError: |
|
14 pass |
|
15 |
|
16 import os |
|
17 |
|
18 from PyQt5.QtCore import QProcess |
|
19 from PyQt5.QtWidgets import QDialog, QApplication, QInputDialog |
|
20 |
|
21 from E5Gui import E5MessageBox |
|
22 |
|
23 from ..HgExtension import HgExtension |
|
24 from ..HgDialog import HgDialog |
|
25 |
|
26 |
|
27 class Queues(HgExtension): |
|
28 """ |
|
29 Class implementing the queues extension interface. |
|
30 """ |
|
31 APPLIED_LIST = 0 |
|
32 UNAPPLIED_LIST = 1 |
|
33 SERIES_LIST = 2 |
|
34 |
|
35 POP = 0 |
|
36 PUSH = 1 |
|
37 GOTO = 2 |
|
38 |
|
39 QUEUE_DELETE = 0 |
|
40 QUEUE_PURGE = 1 |
|
41 QUEUE_ACTIVATE = 2 |
|
42 |
|
43 def __init__(self, vcs): |
|
44 """ |
|
45 Constructor |
|
46 |
|
47 @param vcs reference to the Mercurial vcs object |
|
48 """ |
|
49 super(Queues, self).__init__(vcs) |
|
50 |
|
51 self.qdiffDialog = None |
|
52 self.qheaderDialog = None |
|
53 self.queuesListDialog = None |
|
54 self.queuesListGuardsDialog = None |
|
55 self.queuesListAllGuardsDialog = None |
|
56 self.queuesDefineGuardsDialog = None |
|
57 self.queuesListQueuesDialog = None |
|
58 self.queueStatusDialog = None |
|
59 |
|
60 def shutdown(self): |
|
61 """ |
|
62 Public method used to shutdown the queues interface. |
|
63 """ |
|
64 if self.qdiffDialog is not None: |
|
65 self.qdiffDialog.close() |
|
66 if self.qheaderDialog is not None: |
|
67 self.qheaderDialog.close() |
|
68 if self.queuesListDialog is not None: |
|
69 self.queuesListDialog.close() |
|
70 if self.queuesListGuardsDialog is not None: |
|
71 self.queuesListGuardsDialog.close() |
|
72 if self.queuesListAllGuardsDialog is not None: |
|
73 self.queuesListAllGuardsDialog.close() |
|
74 if self.queuesDefineGuardsDialog is not None: |
|
75 self.queuesDefineGuardsDialog.close() |
|
76 if self.queuesListQueuesDialog is not None: |
|
77 self.queuesListQueuesDialog.close() |
|
78 if self.queueStatusDialog is not None: |
|
79 self.queueStatusDialog.close() |
|
80 |
|
81 def __getPatchesList(self, repodir, listType, withSummary=False): |
|
82 """ |
|
83 Private method to get a list of patches of a given type. |
|
84 |
|
85 @param repodir directory name of the repository (string) |
|
86 @param listType type of patches list to get |
|
87 (Queues.APPLIED_LIST, Queues.UNAPPLIED_LIST, Queues.SERIES_LIST) |
|
88 @param withSummary flag indicating to get a summary as well (boolean) |
|
89 @return list of patches (list of string) |
|
90 @exception ValueError raised to indicate an invalid patch list type |
|
91 """ |
|
92 patchesList = [] |
|
93 |
|
94 if listType == Queues.APPLIED_LIST: |
|
95 args = self.vcs.initCommand("qapplied") |
|
96 elif listType == Queues.UNAPPLIED_LIST: |
|
97 args = self.vcs.initCommand("qunapplied") |
|
98 elif listType == Queues.SERIES_LIST: |
|
99 args = self.vcs.initCommand("qseries") |
|
100 else: |
|
101 raise ValueError("illegal value for listType") |
|
102 if withSummary: |
|
103 args.append("--summary") |
|
104 |
|
105 client = self.vcs.getClient() |
|
106 output = "" |
|
107 if client: |
|
108 output = client.runcommand(args)[0] |
|
109 else: |
|
110 process = QProcess() |
|
111 process.setWorkingDirectory(repodir) |
|
112 process.start('hg', args) |
|
113 procStarted = process.waitForStarted(5000) |
|
114 if procStarted: |
|
115 finished = process.waitForFinished(30000) |
|
116 if finished and process.exitCode() == 0: |
|
117 output = str(process.readAllStandardOutput(), |
|
118 self.vcs.getEncoding(), 'replace') |
|
119 |
|
120 for line in output.splitlines(): |
|
121 if withSummary: |
|
122 li = line.strip().split(": ") |
|
123 if len(li) == 1: |
|
124 patch, summary = li[0][:-1], "" |
|
125 else: |
|
126 patch, summary = li[0], li[1] |
|
127 patchesList.append("{0}@@{1}".format(patch, summary)) |
|
128 else: |
|
129 patchesList.append(line.strip()) |
|
130 |
|
131 return patchesList |
|
132 |
|
133 def __getCurrentPatch(self, repodir): |
|
134 """ |
|
135 Private method to get the name of the current patch. |
|
136 |
|
137 @param repodir directory name of the repository (string) |
|
138 @return name of the current patch (string) |
|
139 """ |
|
140 currentPatch = "" |
|
141 |
|
142 args = self.vcs.initCommand("qtop") |
|
143 |
|
144 client = self.vcs.getClient() |
|
145 if client: |
|
146 currentPatch = client.runcommand(args)[0].strip() |
|
147 else: |
|
148 process = QProcess() |
|
149 process.setWorkingDirectory(repodir) |
|
150 process.start('hg', args) |
|
151 procStarted = process.waitForStarted(5000) |
|
152 if procStarted: |
|
153 finished = process.waitForFinished(30000) |
|
154 if finished and process.exitCode() == 0: |
|
155 currentPatch = str(process.readAllStandardOutput(), |
|
156 self.vcs.getEncoding(), |
|
157 'replace').strip() |
|
158 |
|
159 return currentPatch |
|
160 |
|
161 def __getCommitMessage(self, repodir): |
|
162 """ |
|
163 Private method to get the commit message of the current patch. |
|
164 |
|
165 @param repodir directory name of the repository (string) |
|
166 @return name of the current patch (string) |
|
167 """ |
|
168 message = "" |
|
169 |
|
170 args = self.vcs.initCommand("qheader") |
|
171 |
|
172 client = self.vcs.getClient() |
|
173 if client: |
|
174 message = client.runcommand(args)[0] |
|
175 else: |
|
176 process = QProcess() |
|
177 process.setWorkingDirectory(repodir) |
|
178 process.start('hg', args) |
|
179 procStarted = process.waitForStarted(5000) |
|
180 if procStarted: |
|
181 finished = process.waitForFinished(30000) |
|
182 if finished and process.exitCode() == 0: |
|
183 message = str(process.readAllStandardOutput(), |
|
184 self.vcs.getEncoding(), 'replace') |
|
185 |
|
186 return message |
|
187 |
|
188 def getGuardsList(self, repodir, allGuards=True): |
|
189 """ |
|
190 Public method to get a list of all guards defined. |
|
191 |
|
192 @param repodir directory name of the repository (string) |
|
193 @param allGuards flag indicating to get all guards (boolean) |
|
194 @return sorted list of guards (list of strings) |
|
195 """ |
|
196 guardsList = [] |
|
197 |
|
198 args = self.vcs.initCommand("qselect") |
|
199 if allGuards: |
|
200 args.append("--series") |
|
201 |
|
202 client = self.vcs.getClient() |
|
203 output = "" |
|
204 if client: |
|
205 output = client.runcommand(args)[0] |
|
206 else: |
|
207 process = QProcess() |
|
208 process.setWorkingDirectory(repodir) |
|
209 process.start('hg', args) |
|
210 procStarted = process.waitForStarted(5000) |
|
211 if procStarted: |
|
212 finished = process.waitForFinished(30000) |
|
213 if finished and process.exitCode() == 0: |
|
214 output = str(process.readAllStandardOutput(), |
|
215 self.vcs.getEncoding(), 'replace') |
|
216 |
|
217 for guard in output.splitlines(): |
|
218 guard = guard.strip() |
|
219 if allGuards: |
|
220 guard = guard[1:] |
|
221 if guard not in guardsList: |
|
222 guardsList.append(guard) |
|
223 |
|
224 return sorted(guardsList) |
|
225 |
|
226 def hgQueueNewPatch(self, name): |
|
227 """ |
|
228 Public method to create a new named patch. |
|
229 |
|
230 @param name file/directory name (string) |
|
231 """ |
|
232 # find the root of the repo |
|
233 repodir = self.vcs.splitPath(name)[0] |
|
234 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)): |
|
235 repodir = os.path.dirname(repodir) |
|
236 if os.path.splitdrive(repodir)[1] == os.sep: |
|
237 return |
|
238 |
|
239 from .HgQueuesNewPatchDialog import HgQueuesNewPatchDialog |
|
240 dlg = HgQueuesNewPatchDialog(HgQueuesNewPatchDialog.NEW_MODE) |
|
241 if dlg.exec_() == QDialog.Accepted: |
|
242 name, message, (userData, currentUser, userName), \ |
|
243 (dateData, currentDate, dateStr) = dlg.getData() |
|
244 |
|
245 args = self.vcs.initCommand("qnew") |
|
246 if message != "": |
|
247 args.append("--message") |
|
248 args.append(message) |
|
249 if userData: |
|
250 if currentUser: |
|
251 args.append("--currentuser") |
|
252 else: |
|
253 args.append("--user") |
|
254 args.append(userName) |
|
255 if dateData: |
|
256 if currentDate: |
|
257 args.append("--currentdate") |
|
258 else: |
|
259 args.append("--date") |
|
260 args.append(dateStr) |
|
261 args.append(name) |
|
262 |
|
263 dia = HgDialog(self.tr('New Patch'), self.vcs) |
|
264 res = dia.startProcess(args, repodir) |
|
265 if res: |
|
266 dia.exec_() |
|
267 self.vcs.checkVCSStatus() |
|
268 |
|
269 def hgQueueRefreshPatch(self, name, editMessage=False): |
|
270 """ |
|
271 Public method to refresh the current patch. |
|
272 |
|
273 @param name file/directory name (string) |
|
274 @param editMessage flag indicating to edit the current |
|
275 commit message (boolean) |
|
276 """ |
|
277 # find the root of the repo |
|
278 repodir = self.vcs.splitPath(name)[0] |
|
279 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)): |
|
280 repodir = os.path.dirname(repodir) |
|
281 if os.path.splitdrive(repodir)[1] == os.sep: |
|
282 return |
|
283 |
|
284 args = self.vcs.initCommand("qrefresh") |
|
285 |
|
286 if editMessage: |
|
287 currentMessage = self.__getCommitMessage(repodir) |
|
288 from .HgQueuesNewPatchDialog import HgQueuesNewPatchDialog |
|
289 dlg = HgQueuesNewPatchDialog(HgQueuesNewPatchDialog.REFRESH_MODE, |
|
290 currentMessage) |
|
291 if dlg.exec_() == QDialog.Accepted: |
|
292 name, message, (userData, currentUser, userName), \ |
|
293 (dateData, currentDate, dateStr) = dlg.getData() |
|
294 if message != "" and message != currentMessage: |
|
295 args.append("--message") |
|
296 args.append(message) |
|
297 if userData: |
|
298 if currentUser: |
|
299 args.append("--currentuser") |
|
300 else: |
|
301 args.append("--user") |
|
302 args.append(userName) |
|
303 if dateData: |
|
304 if currentDate: |
|
305 args.append("--currentdate") |
|
306 else: |
|
307 args.append("--date") |
|
308 args.append(dateStr) |
|
309 else: |
|
310 return |
|
311 |
|
312 dia = HgDialog(self.tr('Update Current Patch'), self.vcs) |
|
313 res = dia.startProcess(args, repodir) |
|
314 if res: |
|
315 dia.exec_() |
|
316 self.vcs.checkVCSStatus() |
|
317 |
|
318 def hgQueueShowPatch(self, name): |
|
319 """ |
|
320 Public method to show the contents of the current patch. |
|
321 |
|
322 @param name file/directory name (string) |
|
323 """ |
|
324 from ..HgDiffDialog import HgDiffDialog |
|
325 self.qdiffDialog = HgDiffDialog(self.vcs) |
|
326 self.qdiffDialog.show() |
|
327 QApplication.processEvents() |
|
328 self.qdiffDialog.start(name, qdiff=True) |
|
329 |
|
330 def hgQueueShowHeader(self, name): |
|
331 """ |
|
332 Public method to show the commit message of the current patch. |
|
333 |
|
334 @param name file/directory name (string) |
|
335 """ |
|
336 from .HgQueuesHeaderDialog import HgQueuesHeaderDialog |
|
337 self.qheaderDialog = HgQueuesHeaderDialog(self.vcs) |
|
338 self.qheaderDialog.show() |
|
339 QApplication.processEvents() |
|
340 self.qheaderDialog.start(name) |
|
341 |
|
342 def hgQueuePushPopPatches(self, name, operation, doAll=False, named=False, |
|
343 force=False): |
|
344 """ |
|
345 Public method to push patches onto the stack or pop patches off the |
|
346 stack. |
|
347 |
|
348 @param name file/directory name (string) |
|
349 @param operation operation type to be performed (Queues.POP, |
|
350 Queues.PUSH, Queues.GOTO) |
|
351 @keyparam doAll flag indicating to push/pop all (boolean) |
|
352 @keyparam named flag indicating to push/pop until a named patch |
|
353 is at the top of the stack (boolean) |
|
354 @keyparam force flag indicating a forceful pop (boolean) |
|
355 @return flag indicating that the project should be reread (boolean) |
|
356 @exception ValueError raised to indicate an invalid operation |
|
357 """ |
|
358 # find the root of the repo |
|
359 repodir = self.vcs.splitPath(name)[0] |
|
360 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)): |
|
361 repodir = os.path.dirname(repodir) |
|
362 if os.path.splitdrive(repodir)[1] == os.sep: |
|
363 return False |
|
364 |
|
365 if operation == Queues.POP: |
|
366 args = self.vcs.initCommand("qpop") |
|
367 title = self.tr("Pop Patches") |
|
368 listType = Queues.APPLIED_LIST |
|
369 elif operation == Queues.PUSH: |
|
370 args = self.vcs.initCommand("qpush") |
|
371 title = self.tr("Push Patches") |
|
372 listType = Queues.UNAPPLIED_LIST |
|
373 elif operation == Queues.GOTO: |
|
374 args = self.vcs.initCommand("qgoto") |
|
375 title = self.tr("Go to Patch") |
|
376 listType = Queues.SERIES_LIST |
|
377 else: |
|
378 raise ValueError("illegal value for operation") |
|
379 args.append("-v") |
|
380 if force: |
|
381 args.append("--force") |
|
382 if doAll and operation in (Queues.POP, Queues.PUSH): |
|
383 args.append("--all") |
|
384 elif named or operation == Queues.GOTO: |
|
385 patchnames = self.__getPatchesList(repodir, listType) |
|
386 if patchnames: |
|
387 patch, ok = QInputDialog.getItem( |
|
388 None, |
|
389 self.tr("Select Patch"), |
|
390 self.tr("Select the target patch name:"), |
|
391 patchnames, |
|
392 0, False) |
|
393 if ok and patch: |
|
394 args.append(patch) |
|
395 else: |
|
396 return False |
|
397 else: |
|
398 E5MessageBox.information( |
|
399 None, |
|
400 self.tr("Select Patch"), |
|
401 self.tr("""No patches to select from.""")) |
|
402 return False |
|
403 |
|
404 dia = HgDialog(title, self.vcs) |
|
405 res = dia.startProcess(args, repodir) |
|
406 if res: |
|
407 dia.exec_() |
|
408 res = dia.hasAddOrDelete() |
|
409 self.vcs.checkVCSStatus() |
|
410 return res |
|
411 |
|
412 def hgQueueListPatches(self, name): |
|
413 """ |
|
414 Public method to show a list of all patches. |
|
415 |
|
416 @param name file/directory name (string) |
|
417 """ |
|
418 from .HgQueuesListDialog import HgQueuesListDialog |
|
419 self.queuesListDialog = HgQueuesListDialog(self.vcs) |
|
420 self.queuesListDialog.show() |
|
421 self.queuesListDialog.start(name) |
|
422 |
|
423 def hgQueueFinishAppliedPatches(self, name): |
|
424 """ |
|
425 Public method to finish all applied patches. |
|
426 |
|
427 @param name file/directory name (string) |
|
428 """ |
|
429 # find the root of the repo |
|
430 repodir = self.vcs.splitPath(name)[0] |
|
431 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)): |
|
432 repodir = os.path.dirname(repodir) |
|
433 if os.path.splitdrive(repodir)[1] == os.sep: |
|
434 return |
|
435 |
|
436 args = self.vcs.initCommand("qfinish") |
|
437 args.append("--applied") |
|
438 |
|
439 dia = HgDialog(self.tr('Finish Applied Patches'), self.vcs) |
|
440 res = dia.startProcess(args, repodir) |
|
441 if res: |
|
442 dia.exec_() |
|
443 self.vcs.checkVCSStatus() |
|
444 |
|
445 def hgQueueRenamePatch(self, name): |
|
446 """ |
|
447 Public method to rename the current or a selected patch. |
|
448 |
|
449 @param name file/directory name (string) |
|
450 """ |
|
451 # find the root of the repo |
|
452 repodir = self.vcs.splitPath(name)[0] |
|
453 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)): |
|
454 repodir = os.path.dirname(repodir) |
|
455 if os.path.splitdrive(repodir)[1] == os.sep: |
|
456 return |
|
457 |
|
458 args = self.vcs.initCommand("qrename") |
|
459 patchnames = sorted(self.__getPatchesList(repodir, Queues.SERIES_LIST)) |
|
460 if patchnames: |
|
461 currentPatch = self.__getCurrentPatch(repodir) |
|
462 if currentPatch: |
|
463 from .HgQueuesRenamePatchDialog import \ |
|
464 HgQueuesRenamePatchDialog |
|
465 dlg = HgQueuesRenamePatchDialog(currentPatch, patchnames) |
|
466 if dlg.exec_() == QDialog.Accepted: |
|
467 newName, selectedPatch = dlg.getData() |
|
468 if selectedPatch: |
|
469 args.append(selectedPatch) |
|
470 args.append(newName) |
|
471 |
|
472 dia = HgDialog(self.tr("Rename Patch"), self.vcs) |
|
473 res = dia.startProcess(args, repodir) |
|
474 if res: |
|
475 dia.exec_() |
|
476 |
|
477 def hgQueueDeletePatch(self, name): |
|
478 """ |
|
479 Public method to delete a selected unapplied patch. |
|
480 |
|
481 @param name file/directory name (string) |
|
482 """ |
|
483 # find the root of the repo |
|
484 repodir = self.vcs.splitPath(name)[0] |
|
485 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)): |
|
486 repodir = os.path.dirname(repodir) |
|
487 if os.path.splitdrive(repodir)[1] == os.sep: |
|
488 return |
|
489 |
|
490 args = self.vcs.initCommand("qdelete") |
|
491 patchnames = sorted(self.__getPatchesList(repodir, |
|
492 Queues.UNAPPLIED_LIST)) |
|
493 if patchnames: |
|
494 patch, ok = QInputDialog.getItem( |
|
495 None, |
|
496 self.tr("Select Patch"), |
|
497 self.tr("Select the patch to be deleted:"), |
|
498 patchnames, |
|
499 0, False) |
|
500 if ok and patch: |
|
501 args.append(patch) |
|
502 |
|
503 dia = HgDialog(self.tr("Delete Patch"), self.vcs) |
|
504 res = dia.startProcess(args, repodir) |
|
505 if res: |
|
506 dia.exec_() |
|
507 else: |
|
508 E5MessageBox.information( |
|
509 None, |
|
510 self.tr("Select Patch"), |
|
511 self.tr("""No patches to select from.""")) |
|
512 |
|
513 def hgQueueFoldUnappliedPatches(self, name): |
|
514 """ |
|
515 Public method to fold patches into the current patch. |
|
516 |
|
517 @param name file/directory name (string) |
|
518 """ |
|
519 # find the root of the repo |
|
520 repodir = self.vcs.splitPath(name)[0] |
|
521 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)): |
|
522 repodir = os.path.dirname(repodir) |
|
523 if os.path.splitdrive(repodir)[1] == os.sep: |
|
524 return |
|
525 |
|
526 args = self.vcs.initCommand("qfold") |
|
527 patchnames = sorted( |
|
528 self.__getPatchesList(repodir, Queues.UNAPPLIED_LIST, |
|
529 withSummary=True)) |
|
530 if patchnames: |
|
531 from .HgQueuesFoldDialog import HgQueuesFoldDialog |
|
532 dlg = HgQueuesFoldDialog(patchnames) |
|
533 if dlg.exec_() == QDialog.Accepted: |
|
534 message, patchesList = dlg.getData() |
|
535 if message: |
|
536 args.append("--message") |
|
537 args.append(message) |
|
538 if patchesList: |
|
539 args.extend(patchesList) |
|
540 |
|
541 dia = HgDialog(self.tr("Fold Patches"), self.vcs) |
|
542 res = dia.startProcess(args, repodir) |
|
543 if res: |
|
544 dia.exec_() |
|
545 else: |
|
546 E5MessageBox.information( |
|
547 None, |
|
548 self.tr("Fold Patches"), |
|
549 self.tr("""No patches selected.""")) |
|
550 else: |
|
551 E5MessageBox.information( |
|
552 None, |
|
553 self.tr("Fold Patches"), |
|
554 self.tr("""No patches available to be folded.""")) |
|
555 |
|
556 def hgQueueGuardsList(self, name): |
|
557 """ |
|
558 Public method to list the guards for the current or a named patch. |
|
559 |
|
560 @param name file/directory name (string) |
|
561 """ |
|
562 # find the root of the repo |
|
563 repodir = self.vcs.splitPath(name)[0] |
|
564 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)): |
|
565 repodir = os.path.dirname(repodir) |
|
566 if os.path.splitdrive(repodir)[1] == os.sep: |
|
567 return |
|
568 |
|
569 patchnames = sorted( |
|
570 self.__getPatchesList(repodir, Queues.SERIES_LIST)) |
|
571 if patchnames: |
|
572 from .HgQueuesListGuardsDialog import HgQueuesListGuardsDialog |
|
573 self.queuesListGuardsDialog = \ |
|
574 HgQueuesListGuardsDialog(self.vcs, patchnames) |
|
575 self.queuesListGuardsDialog.show() |
|
576 self.queuesListGuardsDialog.start(name) |
|
577 else: |
|
578 E5MessageBox.information( |
|
579 None, |
|
580 self.tr("List Guards"), |
|
581 self.tr("""No patches available to list guards for.""")) |
|
582 |
|
583 def hgQueueGuardsListAll(self, name): |
|
584 """ |
|
585 Public method to list all guards of all patches. |
|
586 |
|
587 @param name file/directory name (string) |
|
588 """ |
|
589 from .HgQueuesListAllGuardsDialog import HgQueuesListAllGuardsDialog |
|
590 self.queuesListAllGuardsDialog = HgQueuesListAllGuardsDialog(self.vcs) |
|
591 self.queuesListAllGuardsDialog.show() |
|
592 self.queuesListAllGuardsDialog.start(name) |
|
593 |
|
594 def hgQueueGuardsDefine(self, name): |
|
595 """ |
|
596 Public method to define guards for the current or a named patch. |
|
597 |
|
598 @param name file/directory name (string) |
|
599 """ |
|
600 # find the root of the repo |
|
601 repodir = self.vcs.splitPath(name)[0] |
|
602 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)): |
|
603 repodir = os.path.dirname(repodir) |
|
604 if os.path.splitdrive(repodir)[1] == os.sep: |
|
605 return |
|
606 |
|
607 patchnames = sorted( |
|
608 self.__getPatchesList(repodir, Queues.SERIES_LIST)) |
|
609 if patchnames: |
|
610 from .HgQueuesDefineGuardsDialog import HgQueuesDefineGuardsDialog |
|
611 self.queuesDefineGuardsDialog = HgQueuesDefineGuardsDialog( |
|
612 self.vcs, self, patchnames) |
|
613 self.queuesDefineGuardsDialog.show() |
|
614 self.queuesDefineGuardsDialog.start(name) |
|
615 else: |
|
616 E5MessageBox.information( |
|
617 None, |
|
618 self.tr("Define Guards"), |
|
619 self.tr("""No patches available to define guards for.""")) |
|
620 |
|
621 def hgQueueGuardsDropAll(self, name): |
|
622 """ |
|
623 Public method to drop all guards of the current or a named patch. |
|
624 |
|
625 @param name file/directory name (string) |
|
626 """ |
|
627 # find the root of the repo |
|
628 repodir = self.vcs.splitPath(name)[0] |
|
629 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)): |
|
630 repodir = os.path.dirname(repodir) |
|
631 if os.path.splitdrive(repodir)[1] == os.sep: |
|
632 return |
|
633 |
|
634 patchnames = sorted( |
|
635 self.__getPatchesList(repodir, Queues.SERIES_LIST)) |
|
636 if patchnames: |
|
637 patch, ok = QInputDialog.getItem( |
|
638 None, |
|
639 self.tr("Drop All Guards"), |
|
640 self.tr("Select the patch to drop guards for" |
|
641 " (leave empty for the current patch):"), |
|
642 [""] + patchnames, |
|
643 0, False) |
|
644 if ok: |
|
645 args = self.vcs.initCommand("qguard") |
|
646 if patch: |
|
647 args.append(patch) |
|
648 args.append("--none") |
|
649 |
|
650 client = self.vcs.getClient() |
|
651 if client: |
|
652 client.runcommand(args) |
|
653 else: |
|
654 process = QProcess() |
|
655 process.setWorkingDirectory(repodir) |
|
656 process.start('hg', args) |
|
657 procStarted = process.waitForStarted(5000) |
|
658 if procStarted: |
|
659 process.waitForFinished(30000) |
|
660 else: |
|
661 E5MessageBox.information( |
|
662 None, |
|
663 self.tr("Drop All Guards"), |
|
664 self.tr("""No patches available to define guards for.""")) |
|
665 |
|
666 def hgQueueGuardsSetActive(self, name): |
|
667 """ |
|
668 Public method to set the active guards. |
|
669 |
|
670 @param name file/directory name (string) |
|
671 """ |
|
672 # find the root of the repo |
|
673 repodir = self.vcs.splitPath(name)[0] |
|
674 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)): |
|
675 repodir = os.path.dirname(repodir) |
|
676 if os.path.splitdrive(repodir)[1] == os.sep: |
|
677 return |
|
678 |
|
679 guardsList = self.getGuardsList(repodir) |
|
680 if guardsList: |
|
681 activeGuardsList = self.getGuardsList(repodir, allGuards=False) |
|
682 from .HgQueuesGuardsSelectionDialog import \ |
|
683 HgQueuesGuardsSelectionDialog |
|
684 dlg = HgQueuesGuardsSelectionDialog( |
|
685 guardsList, activeGuards=activeGuardsList, listOnly=False) |
|
686 if dlg.exec_() == QDialog.Accepted: |
|
687 guards = dlg.getData() |
|
688 if guards: |
|
689 args = self.vcs.initCommand("qselect") |
|
690 args.extend(guards) |
|
691 |
|
692 dia = HgDialog(self.tr('Set Active Guards'), self.vcs) |
|
693 res = dia.startProcess(args, repodir) |
|
694 if res: |
|
695 dia.exec_() |
|
696 else: |
|
697 E5MessageBox.information( |
|
698 None, |
|
699 self.tr("Set Active Guards"), |
|
700 self.tr("""No guards available to select from.""")) |
|
701 return |
|
702 |
|
703 def hgQueueGuardsDeactivate(self, name): |
|
704 """ |
|
705 Public method to deactivate all active guards. |
|
706 |
|
707 @param name file/directory name (string) |
|
708 """ |
|
709 # find the root of the repo |
|
710 repodir = self.vcs.splitPath(name)[0] |
|
711 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)): |
|
712 repodir = os.path.dirname(repodir) |
|
713 if os.path.splitdrive(repodir)[1] == os.sep: |
|
714 return |
|
715 |
|
716 args = self.vcs.initCommand("qselect") |
|
717 args.append("--none") |
|
718 |
|
719 dia = HgDialog(self.tr('Deactivate Guards'), self.vcs) |
|
720 res = dia.startProcess(args, repodir) |
|
721 if res: |
|
722 dia.exec_() |
|
723 |
|
724 def hgQueueGuardsIdentifyActive(self, name): |
|
725 """ |
|
726 Public method to list all active guards. |
|
727 |
|
728 @param name file/directory name (string) |
|
729 """ |
|
730 # find the root of the repo |
|
731 repodir = self.vcs.splitPath(name)[0] |
|
732 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)): |
|
733 repodir = os.path.dirname(repodir) |
|
734 if os.path.splitdrive(repodir)[1] == os.sep: |
|
735 return |
|
736 |
|
737 guardsList = self.getGuardsList(repodir, allGuards=False) |
|
738 if guardsList: |
|
739 from .HgQueuesGuardsSelectionDialog import \ |
|
740 HgQueuesGuardsSelectionDialog |
|
741 dlg = HgQueuesGuardsSelectionDialog(guardsList, listOnly=True) |
|
742 dlg.exec_() |
|
743 |
|
744 def hgQueueCreateRenameQueue(self, name, isCreate): |
|
745 """ |
|
746 Public method to create a new queue or rename the active queue. |
|
747 |
|
748 @param name file/directory name (string) |
|
749 @param isCreate flag indicating to create a new queue (boolean) |
|
750 """ |
|
751 # find the root of the repo |
|
752 repodir = self.vcs.splitPath(name)[0] |
|
753 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)): |
|
754 repodir = os.path.dirname(repodir) |
|
755 if os.path.splitdrive(repodir)[1] == os.sep: |
|
756 return |
|
757 |
|
758 if isCreate: |
|
759 title = self.tr("Create New Queue") |
|
760 else: |
|
761 title = self.tr("Rename Active Queue") |
|
762 from .HgQueuesQueueManagementDialog import \ |
|
763 HgQueuesQueueManagementDialog |
|
764 dlg = HgQueuesQueueManagementDialog( |
|
765 HgQueuesQueueManagementDialog.NAME_INPUT, |
|
766 title, False, repodir, self.vcs) |
|
767 if dlg.exec_() == QDialog.Accepted: |
|
768 queueName = dlg.getData() |
|
769 if queueName: |
|
770 args = self.vcs.initCommand("qqueue") |
|
771 if isCreate: |
|
772 args.append("--create") |
|
773 else: |
|
774 args.append("--rename") |
|
775 args.append(queueName) |
|
776 |
|
777 client = self.vcs.getClient() |
|
778 error = "" |
|
779 if client: |
|
780 error = client.runcommand(args)[1] |
|
781 else: |
|
782 process = QProcess() |
|
783 process.setWorkingDirectory(repodir) |
|
784 process.start('hg', args) |
|
785 procStarted = process.waitForStarted(5000) |
|
786 if procStarted: |
|
787 finished = process.waitForFinished(30000) |
|
788 if finished: |
|
789 if process.exitCode() != 0: |
|
790 error = str(process.readAllStandardError(), |
|
791 self.vcs.getEncoding(), 'replace') |
|
792 |
|
793 if error: |
|
794 if isCreate: |
|
795 errMsg = self.tr( |
|
796 "Error while creating a new queue.") |
|
797 else: |
|
798 errMsg = self.tr( |
|
799 "Error while renaming the active queue.") |
|
800 E5MessageBox.warning( |
|
801 None, |
|
802 title, |
|
803 """<p>{0}</p><p>{1}</p>""".format(errMsg, error)) |
|
804 else: |
|
805 if self.queuesListQueuesDialog is not None and \ |
|
806 self.queuesListQueuesDialog.isVisible(): |
|
807 self.queuesListQueuesDialog.refresh() |
|
808 |
|
809 def hgQueueDeletePurgeActivateQueue(self, name, operation): |
|
810 """ |
|
811 Public method to delete the reference to a queue and optionally |
|
812 remove the patch directory or set the active queue. |
|
813 |
|
814 @param name file/directory name (string) |
|
815 @param operation operation to be performed (Queues.QUEUE_DELETE, |
|
816 Queues.QUEUE_PURGE, Queues.QUEUE_ACTIVATE) |
|
817 @exception ValueError raised to indicate an invalid operation |
|
818 """ |
|
819 # find the root of the repo |
|
820 repodir = self.vcs.splitPath(name)[0] |
|
821 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)): |
|
822 repodir = os.path.dirname(repodir) |
|
823 if os.path.splitdrive(repodir)[1] == os.sep: |
|
824 return |
|
825 |
|
826 if operation == Queues.QUEUE_PURGE: |
|
827 title = self.tr("Purge Queue") |
|
828 elif operation == Queues.QUEUE_DELETE: |
|
829 title = self.tr("Delete Queue") |
|
830 elif operation == Queues.QUEUE_ACTIVATE: |
|
831 title = self.tr("Activate Queue") |
|
832 else: |
|
833 raise ValueError("illegal value for operation") |
|
834 |
|
835 from .HgQueuesQueueManagementDialog import \ |
|
836 HgQueuesQueueManagementDialog |
|
837 dlg = HgQueuesQueueManagementDialog( |
|
838 HgQueuesQueueManagementDialog.QUEUE_INPUT, |
|
839 title, True, repodir, self.vcs) |
|
840 if dlg.exec_() == QDialog.Accepted: |
|
841 queueName = dlg.getData() |
|
842 if queueName: |
|
843 args = self.vcs.initCommand("qqueue") |
|
844 if operation == Queues.QUEUE_PURGE: |
|
845 args.append("--purge") |
|
846 elif operation == Queues.QUEUE_DELETE: |
|
847 args.append("--delete") |
|
848 args.append(queueName) |
|
849 |
|
850 client = self.vcs.getClient() |
|
851 error = "" |
|
852 if client: |
|
853 error = client.runcommand(args)[1] |
|
854 else: |
|
855 process = QProcess() |
|
856 process.setWorkingDirectory(repodir) |
|
857 process.start('hg', args) |
|
858 procStarted = process.waitForStarted(5000) |
|
859 if procStarted: |
|
860 finished = process.waitForFinished(30000) |
|
861 if finished: |
|
862 if process.exitCode() != 0: |
|
863 error = str(process.readAllStandardError(), |
|
864 self.vcs.getEncoding(), 'replace') |
|
865 |
|
866 if error: |
|
867 if operation == Queues.QUEUE_PURGE: |
|
868 errMsg = self.tr("Error while purging the queue.") |
|
869 elif operation == Queues.QUEUE_DELETE: |
|
870 errMsg = self.tr("Error while deleting the queue.") |
|
871 elif operation == Queues.QUEUE_ACTIVATE: |
|
872 errMsg = self.tr( |
|
873 "Error while setting the active queue.") |
|
874 E5MessageBox.warning( |
|
875 None, |
|
876 title, |
|
877 """<p>{0}</p><p>{1}</p>""".format(errMsg, error)) |
|
878 else: |
|
879 if self.queuesListQueuesDialog is not None and \ |
|
880 self.queuesListQueuesDialog.isVisible(): |
|
881 self.queuesListQueuesDialog.refresh() |
|
882 |
|
883 def hgQueueListQueues(self, name): |
|
884 """ |
|
885 Public method to list available queues. |
|
886 |
|
887 @param name file/directory name (string) |
|
888 """ |
|
889 # find the root of the repo |
|
890 repodir = self.vcs.splitPath(name)[0] |
|
891 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)): |
|
892 repodir = os.path.dirname(repodir) |
|
893 if os.path.splitdrive(repodir)[1] == os.sep: |
|
894 return |
|
895 |
|
896 from .HgQueuesQueueManagementDialog import \ |
|
897 HgQueuesQueueManagementDialog |
|
898 self.queuesListQueuesDialog = HgQueuesQueueManagementDialog( |
|
899 HgQueuesQueueManagementDialog.NO_INPUT, |
|
900 self.tr("Available Queues"), |
|
901 False, repodir, self.vcs) |
|
902 self.queuesListQueuesDialog.show() |
|
903 |
|
904 def hgQueueInit(self, name): |
|
905 """ |
|
906 Public method to initialize a new queue repository. |
|
907 |
|
908 @param name directory name (string) |
|
909 """ |
|
910 # find the root of the repo |
|
911 repodir = self.vcs.splitPath(name)[0] |
|
912 while not os.path.isdir(os.path.join(repodir, self.vcs.adminDir)): |
|
913 repodir = os.path.dirname(repodir) |
|
914 if os.path.splitdrive(repodir)[1] == os.sep: |
|
915 return |
|
916 |
|
917 args = self.vcs.initCommand("init") |
|
918 args.append('--mq') |
|
919 args.append(repodir) |
|
920 # init is not possible with the command server |
|
921 dia = HgDialog( |
|
922 self.tr('Initializing new queue repository'), self.vcs) |
|
923 res = dia.startProcess(args) |
|
924 if res: |
|
925 dia.exec_() |
|
926 |
|
927 def hgQueueStatus(self, name): |
|
928 """ |
|
929 Public method used to view the status of a queue repository. |
|
930 |
|
931 @param name directory name (string) |
|
932 """ |
|
933 from ..HgStatusDialog import HgStatusDialog |
|
934 self.queueStatusDialog = HgStatusDialog(self.vcs, mq=True) |
|
935 self.queueStatusDialog.show() |
|
936 self.queueStatusDialog.start(name) |