Plugins/VcsPlugins/vcsMercurial/QueuesExtension/queues.py

changeset 1254
c077fa008aae
parent 1087
fb8cd56819a9
child 1255
e1d8a8a4d40c
equal deleted inserted replaced
1253:4a994190cf8b 1254:c077fa008aae
93 @param withSummary flag indicating to get a summary as well (boolean) 93 @param withSummary flag indicating to get a summary as well (boolean)
94 @return list of patches (list of string) 94 @return list of patches (list of string)
95 """ 95 """
96 patchesList = [] 96 patchesList = []
97 97
98 ioEncoding = Preferences.getSystem("IOEncoding")
99 process = QProcess()
100 args = [] 98 args = []
101 if listType == Queues.APPLIED_LIST: 99 if listType == Queues.APPLIED_LIST:
102 args.append("qapplied") 100 args.append("qapplied")
103 elif listType == Queues.UNAPPLIED_LIST: 101 elif listType == Queues.UNAPPLIED_LIST:
104 args.append("qunapplied") 102 args.append("qunapplied")
107 else: 105 else:
108 raise ValueError("illegal value for listType") 106 raise ValueError("illegal value for listType")
109 if withSummary: 107 if withSummary:
110 args.append("--summary") 108 args.append("--summary")
111 109
112 process.setWorkingDirectory(repodir) 110 client = self.vcs.getClient()
113 process.start('hg', args) 111 output = ""
114 procStarted = process.waitForStarted() 112 if client:
115 if procStarted: 113 output = client.runcommand(args)[0]
116 finished = process.waitForFinished(30000) 114 else:
117 if finished and process.exitCode() == 0: 115 ioEncoding = Preferences.getSystem("IOEncoding")
118 output = \ 116 process = QProcess()
119 str(process.readAllStandardOutput(), ioEncoding, 'replace') 117 process.setWorkingDirectory(repodir)
120 for line in output.splitlines(): 118 process.start('hg', args)
121 if withSummary: 119 procStarted = process.waitForStarted()
122 l = line.strip().split(": ") 120 if procStarted:
123 if len(l) == 1: 121 finished = process.waitForFinished(30000)
124 patch, summary = l[0][:-1], "" 122 if finished and process.exitCode() == 0:
125 else: 123 output = \
126 patch, summary = l[0], l[1] 124 str(process.readAllStandardOutput(), ioEncoding, 'replace')
127 patchesList.append("{0}@@{1}".format(patch, summary)) 125
128 else: 126 for line in output.splitlines():
129 patchesList.append(line.strip()) 127 if withSummary:
128 l = line.strip().split(": ")
129 if len(l) == 1:
130 patch, summary = l[0][:-1], ""
131 else:
132 patch, summary = l[0], l[1]
133 patchesList.append("{0}@@{1}".format(patch, summary))
134 else:
135 patchesList.append(line.strip())
130 136
131 return patchesList 137 return patchesList
132 138
133 def __getCurrentPatch(self, repodir): 139 def __getCurrentPatch(self, repodir):
134 """ 140 """
137 @param repodir directory name of the repository (string) 143 @param repodir directory name of the repository (string)
138 @return name of the current patch (string) 144 @return name of the current patch (string)
139 """ 145 """
140 currentPatch = "" 146 currentPatch = ""
141 147
142 ioEncoding = Preferences.getSystem("IOEncoding")
143 process = QProcess()
144 args = [] 148 args = []
145 args.append("qtop") 149 args.append("qtop")
146 150
147 process.setWorkingDirectory(repodir) 151 client = self.vcs.getClient()
148 process.start('hg', args) 152 if client:
149 procStarted = process.waitForStarted() 153 currentPatch = client.runcommand(args)[0].strip()
150 if procStarted: 154 else:
151 finished = process.waitForFinished(30000) 155 ioEncoding = Preferences.getSystem("IOEncoding")
152 if finished and process.exitCode() == 0: 156 process = QProcess()
153 currentPatch = str( 157 process.setWorkingDirectory(repodir)
154 process.readAllStandardOutput(), 158 process.start('hg', args)
155 ioEncoding, 'replace').strip() 159 procStarted = process.waitForStarted()
160 if procStarted:
161 finished = process.waitForFinished(30000)
162 if finished and process.exitCode() == 0:
163 currentPatch = str(
164 process.readAllStandardOutput(),
165 ioEncoding, 'replace').strip()
156 166
157 return currentPatch 167 return currentPatch
158 168
159 def __getCommitMessage(self, repodir): 169 def __getCommitMessage(self, repodir):
160 """ 170 """
163 @param repodir directory name of the repository (string) 173 @param repodir directory name of the repository (string)
164 @return name of the current patch (string) 174 @return name of the current patch (string)
165 """ 175 """
166 message = "" 176 message = ""
167 177
168 ioEncoding = Preferences.getSystem("IOEncoding")
169 process = QProcess()
170 args = [] 178 args = []
171 args.append("qheader") 179 args.append("qheader")
172 180
173 process.setWorkingDirectory(repodir) 181 client = self.vcs.getClient()
174 process.start('hg', args) 182 if client:
175 procStarted = process.waitForStarted() 183 message = client.runcommand(args)[0]
176 if procStarted: 184 else:
177 finished = process.waitForFinished(30000) 185 ioEncoding = Preferences.getSystem("IOEncoding")
178 if finished and process.exitCode() == 0: 186 process = QProcess()
179 message = str( 187 process.setWorkingDirectory(repodir)
180 process.readAllStandardOutput(), 188 process.start('hg', args)
181 ioEncoding, 'replace') 189 procStarted = process.waitForStarted()
190 if procStarted:
191 finished = process.waitForFinished(30000)
192 if finished and process.exitCode() == 0:
193 message = str(
194 process.readAllStandardOutput(),
195 ioEncoding, 'replace')
182 196
183 return message 197 return message
184 198
185 def getGuardsList(self, repodir, all=True): 199 def getGuardsList(self, repodir, all=True):
186 """ 200 """
190 @param all flag indicating to get all guards (boolean) 204 @param all flag indicating to get all guards (boolean)
191 @return sorted list of guards (list of strings) 205 @return sorted list of guards (list of strings)
192 """ 206 """
193 guardsList = [] 207 guardsList = []
194 208
195 ioEncoding = Preferences.getSystem("IOEncoding")
196 process = QProcess()
197 args = [] 209 args = []
198 args.append("qselect") 210 args.append("qselect")
199 if all: 211 if all:
200 args.append("--series") 212 args.append("--series")
201 213
202 process.setWorkingDirectory(repodir) 214 client = self.vcs.getClient()
203 process.start('hg', args) 215 output = ""
204 procStarted = process.waitForStarted() 216 if client:
205 if procStarted: 217 output = client.runcommand(args)[0]
206 finished = process.waitForFinished(30000) 218 else:
207 if finished and process.exitCode() == 0: 219 ioEncoding = Preferences.getSystem("IOEncoding")
208 output = \ 220 process = QProcess()
209 str(process.readAllStandardOutput(), ioEncoding, 'replace') 221 process.setWorkingDirectory(repodir)
210 for guard in output.splitlines(): 222 process.start('hg', args)
211 guard = guard.strip() 223 procStarted = process.waitForStarted()
212 if all: 224 if procStarted:
213 guard = guard[1:] 225 finished = process.waitForFinished(30000)
214 if guard not in guardsList: 226 if finished and process.exitCode() == 0:
215 guardsList.append(guard) 227 output = \
228 str(process.readAllStandardOutput(), ioEncoding, 'replace')
229
230 for guard in output.splitlines():
231 guard = guard.strip()
232 if all:
233 guard = guard[1:]
234 if guard not in guardsList:
235 guardsList.append(guard)
216 236
217 return sorted(guardsList) 237 return sorted(guardsList)
218 238
219 def hgQueueNewPatch(self, name): 239 def hgQueueNewPatch(self, name):
220 """ 240 """
251 else: 271 else:
252 args.append("--date") 272 args.append("--date")
253 args.append(dateStr) 273 args.append(dateStr)
254 args.append(name) 274 args.append(name)
255 275
256 dia = HgDialog(self.trUtf8('New Patch')) 276 dia = HgDialog(self.trUtf8('New Patch'), self.vcs)
257 res = dia.startProcess(args, repodir) 277 res = dia.startProcess(args, repodir)
258 if res: 278 if res:
259 dia.exec_() 279 dia.exec_()
260 self.vcs.checkVCSStatus() 280 self.vcs.checkVCSStatus()
261 281
300 args.append("--date") 320 args.append("--date")
301 args.append(dateStr) 321 args.append(dateStr)
302 else: 322 else:
303 return 323 return
304 324
305 dia = HgDialog(self.trUtf8('Update Current Patch')) 325 dia = HgDialog(self.trUtf8('Update Current Patch'), self.vcs)
306 res = dia.startProcess(args, repodir) 326 res = dia.startProcess(args, repodir)
307 if res: 327 if res:
308 dia.exec_() 328 dia.exec_()
309 self.vcs.checkVCSStatus() 329 self.vcs.checkVCSStatus()
310 330
387 E5MessageBox.information(None, 407 E5MessageBox.information(None,
388 self.trUtf8("Select Patch"), 408 self.trUtf8("Select Patch"),
389 self.trUtf8("""No patches to select from.""")) 409 self.trUtf8("""No patches to select from."""))
390 return False 410 return False
391 411
392 dia = HgDialog(title) 412 dia = HgDialog(title, self.vcs)
393 res = dia.startProcess(args, repodir) 413 res = dia.startProcess(args, repodir)
394 if res: 414 if res:
395 dia.exec_() 415 dia.exec_()
396 res = dia.hasAddOrDelete() 416 res = dia.hasAddOrDelete()
397 self.vcs.checkVCSStatus() 417 self.vcs.checkVCSStatus()
422 442
423 args = [] 443 args = []
424 args.append("qfinish") 444 args.append("qfinish")
425 args.append("--applied") 445 args.append("--applied")
426 446
427 dia = HgDialog(self.trUtf8('Finish Applied Patches')) 447 dia = HgDialog(self.trUtf8('Finish Applied Patches'), self.vcs)
428 res = dia.startProcess(args, repodir) 448 res = dia.startProcess(args, repodir)
429 if res: 449 if res:
430 dia.exec_() 450 dia.exec_()
431 self.vcs.checkVCSStatus() 451 self.vcs.checkVCSStatus()
432 452
454 newName, selectedPatch = dlg.getData() 474 newName, selectedPatch = dlg.getData()
455 if selectedPatch: 475 if selectedPatch:
456 args.append(selectedPatch) 476 args.append(selectedPatch)
457 args.append(newName) 477 args.append(newName)
458 478
459 dia = HgDialog(self.trUtf8("Rename Patch")) 479 dia = HgDialog(self.trUtf8("Rename Patch"), self.vcs)
460 res = dia.startProcess(args, repodir) 480 res = dia.startProcess(args, repodir)
461 if res: 481 if res:
462 dia.exec_() 482 dia.exec_()
463 483
464 def hgQueueDeletePatch(self, name): 484 def hgQueueDeletePatch(self, name):
485 patchnames, 505 patchnames,
486 0, False) 506 0, False)
487 if ok and patch: 507 if ok and patch:
488 args.append(patch) 508 args.append(patch)
489 509
490 dia = HgDialog(self.trUtf8("Delete Patch")) 510 dia = HgDialog(self.trUtf8("Delete Patch"), self.vcs)
491 res = dia.startProcess(args, repodir) 511 res = dia.startProcess(args, repodir)
492 if res: 512 if res:
493 dia.exec_() 513 dia.exec_()
494 else: 514 else:
495 E5MessageBox.information(None, 515 E5MessageBox.information(None,
521 args.append("--message") 541 args.append("--message")
522 args.append(message) 542 args.append(message)
523 if patchesList: 543 if patchesList:
524 args.extend(patchesList) 544 args.extend(patchesList)
525 545
526 dia = HgDialog(self.trUtf8("Fold Patches")) 546 dia = HgDialog(self.trUtf8("Fold Patches"), self.vcs)
527 res = dia.startProcess(args, repodir) 547 res = dia.startProcess(args, repodir)
528 if res: 548 if res:
529 dia.exec_() 549 dia.exec_()
530 else: 550 else:
531 E5MessageBox.information(None, 551 E5MessageBox.information(None,
617 self.trUtf8("Select the patch to drop guards for" 637 self.trUtf8("Select the patch to drop guards for"
618 " (leave empty for the current patch):"), 638 " (leave empty for the current patch):"),
619 [""] + patchnames, 639 [""] + patchnames,
620 0, False) 640 0, False)
621 if ok: 641 if ok:
622 process = QProcess()
623 args = [] 642 args = []
624 args.append("qguard") 643 args.append("qguard")
625 if patch: 644 if patch:
626 args.append(patch) 645 args.append(patch)
627 args.append("--none") 646 args.append("--none")
628 647
629 process.setWorkingDirectory(repodir) 648 client = self.vcs.getClient()
630 process.start('hg', args) 649 if client:
631 procStarted = process.waitForStarted() 650 client.runcommand(args)
632 if procStarted: 651 else:
633 process.waitForFinished(30000) 652 process = QProcess()
653 process.setWorkingDirectory(repodir)
654 process.start('hg', args)
655 procStarted = process.waitForStarted()
656 if procStarted:
657 process.waitForFinished(30000)
634 else: 658 else:
635 E5MessageBox.information(None, 659 E5MessageBox.information(None,
636 self.trUtf8("Drop All Guards"), 660 self.trUtf8("Drop All Guards"),
637 self.trUtf8("""No patches available to define guards for.""")) 661 self.trUtf8("""No patches available to define guards for."""))
638 662
659 if guards: 683 if guards:
660 args = [] 684 args = []
661 args.append("qselect") 685 args.append("qselect")
662 args.extend(guards) 686 args.extend(guards)
663 687
664 dia = HgDialog(self.trUtf8('Set Active Guards')) 688 dia = HgDialog(self.trUtf8('Set Active Guards'), self.vcs)
665 res = dia.startProcess(args, repodir) 689 res = dia.startProcess(args, repodir)
666 if res: 690 if res:
667 dia.exec_() 691 dia.exec_()
668 else: 692 else:
669 E5MessageBox.information(None, 693 E5MessageBox.information(None,
686 710
687 args = [] 711 args = []
688 args.append("qselect") 712 args.append("qselect")
689 args.append("--none") 713 args.append("--none")
690 714
691 dia = HgDialog(self.trUtf8('Deactivate Guards')) 715 dia = HgDialog(self.trUtf8('Deactivate Guards'), self.vcs)
692 res = dia.startProcess(args, repodir) 716 res = dia.startProcess(args, repodir)
693 if res: 717 if res:
694 dia.exec_() 718 dia.exec_()
695 719
696 def hgQueueGuardsIdentifyActive(self, name): 720 def hgQueueGuardsIdentifyActive(self, name):
732 dlg = HgQueuesQueueManagementDialog(HgQueuesQueueManagementDialog.NAME_INPUT, 756 dlg = HgQueuesQueueManagementDialog(HgQueuesQueueManagementDialog.NAME_INPUT,
733 title, False, repodir) 757 title, False, repodir)
734 if dlg.exec_() == QDialog.Accepted: 758 if dlg.exec_() == QDialog.Accepted:
735 queueName = dlg.getData() 759 queueName = dlg.getData()
736 if queueName: 760 if queueName:
737 ioEncoding = Preferences.getSystem("IOEncoding")
738 process = QProcess()
739 args = [] 761 args = []
740 args.append("qqueue") 762 args.append("qqueue")
741 if isCreate: 763 if isCreate:
742 args.append("--create") 764 args.append("--create")
743 else: 765 else:
744 args.append("--rename") 766 args.append("--rename")
745 args.append(queueName) 767 args.append(queueName)
746 768
747 process.setWorkingDirectory(repodir) 769 client = self.vcs.getClient()
748 process.start('hg', args) 770 error = ""
749 procStarted = process.waitForStarted() 771 if client:
750 if procStarted: 772 error = client.runcommand(args)[1]
751 finished = process.waitForFinished(30000) 773 else:
752 if finished: 774 ioEncoding = Preferences.getSystem("IOEncoding")
753 if process.exitCode() != 0: 775 process = QProcess()
754 error = \ 776 process.setWorkingDirectory(repodir)
755 str(process.readAllStandardError(), ioEncoding, 'replace') 777 process.start('hg', args)
756 if isCreate: 778 procStarted = process.waitForStarted()
757 errMsg = self.trUtf8( 779 if procStarted:
758 "Error while creating a new queue.") 780 finished = process.waitForFinished(30000)
759 else: 781 if finished:
760 errMsg = self.trUtf8( 782 if process.exitCode() != 0:
761 "Error while renaming the active queue.") 783 error = \
762 E5MessageBox.warning(None, 784 str(process.readAllStandardError(),
763 title, 785 ioEncoding, 'replace')
764 """<p>{0}</p><p>{1}</p>""".format(errMsg, error)) 786
765 else: 787 if error:
766 if self.queuesListQueuesDialog is not None and \ 788 if isCreate:
767 self.queuesListQueuesDialog.isVisible(): 789 errMsg = self.trUtf8(
768 self.queuesListQueuesDialog.refresh() 790 "Error while creating a new queue.")
791 else:
792 errMsg = self.trUtf8(
793 "Error while renaming the active queue.")
794 E5MessageBox.warning(None,
795 title,
796 """<p>{0}</p><p>{1}</p>""".format(errMsg, error))
797 else:
798 if self.queuesListQueuesDialog is not None and \
799 self.queuesListQueuesDialog.isVisible():
800 self.queuesListQueuesDialog.refresh()
769 801
770 def hgQueueDeletePurgeActivateQueue(self, name, operation): 802 def hgQueueDeletePurgeActivateQueue(self, name, operation):
771 """ 803 """
772 Public method to delete the reference to a queue and optionally 804 Public method to delete the reference to a queue and optionally
773 remove the patch directory or set the active queue. 805 remove the patch directory or set the active queue.
795 dlg = HgQueuesQueueManagementDialog(HgQueuesQueueManagementDialog.QUEUE_INPUT, 827 dlg = HgQueuesQueueManagementDialog(HgQueuesQueueManagementDialog.QUEUE_INPUT,
796 title, True, repodir) 828 title, True, repodir)
797 if dlg.exec_() == QDialog.Accepted: 829 if dlg.exec_() == QDialog.Accepted:
798 queueName = dlg.getData() 830 queueName = dlg.getData()
799 if queueName: 831 if queueName:
800 ioEncoding = Preferences.getSystem("IOEncoding")
801 process = QProcess()
802 args = [] 832 args = []
803 args.append("qqueue") 833 args.append("qqueue")
804 if operation == Queues.QUEUE_PURGE: 834 if operation == Queues.QUEUE_PURGE:
805 args.append("--purge") 835 args.append("--purge")
806 elif operation == Queues.QUEUE_DELETE: 836 elif operation == Queues.QUEUE_DELETE:
807 args.append("--delete") 837 args.append("--delete")
808 args.append(queueName) 838 args.append(queueName)
809 839
810 process.setWorkingDirectory(repodir) 840 client = self.vcs.getClient()
811 process.start('hg', args) 841 error = ""
812 procStarted = process.waitForStarted() 842 if client:
813 if procStarted: 843 error = client.runcommand(args)[1]
814 finished = process.waitForFinished(30000) 844 else:
815 if finished: 845 ioEncoding = Preferences.getSystem("IOEncoding")
816 if process.exitCode() != 0: 846 process = QProcess()
817 error = \ 847 process.setWorkingDirectory(repodir)
818 str(process.readAllStandardError(), ioEncoding, 'replace') 848 process.start('hg', args)
819 if operation == Queues.QUEUE_PURGE: 849 procStarted = process.waitForStarted()
820 errMsg = self.trUtf8("Error while purging the queue.") 850 if procStarted:
821 elif operation == Queues.QUEUE_DELETE: 851 finished = process.waitForFinished(30000)
822 errMsg = self.trUtf8("Error while deleting the queue.") 852 if finished:
823 elif operation == Queues.QUEUE_ACTIVATE: 853 if process.exitCode() != 0:
824 errMsg = self.trUtf8( 854 error = \
825 "Error while setting the active queue.") 855 str(process.readAllStandardError(),
826 E5MessageBox.warning(None, 856 ioEncoding, 'replace')
827 title, 857
828 """<p>{0}</p><p>{1}</p>""".format(errMsg, error)) 858 if error:
829 else: 859 if operation == Queues.QUEUE_PURGE:
830 if self.queuesListQueuesDialog is not None and \ 860 errMsg = self.trUtf8("Error while purging the queue.")
831 self.queuesListQueuesDialog.isVisible(): 861 elif operation == Queues.QUEUE_DELETE:
832 self.queuesListQueuesDialog.refresh() 862 errMsg = self.trUtf8("Error while deleting the queue.")
863 elif operation == Queues.QUEUE_ACTIVATE:
864 errMsg = self.trUtf8(
865 "Error while setting the active queue.")
866 E5MessageBox.warning(None,
867 title,
868 """<p>{0}</p><p>{1}</p>""".format(errMsg, error))
869 else:
870 if self.queuesListQueuesDialog is not None and \
871 self.queuesListQueuesDialog.isVisible():
872 self.queuesListQueuesDialog.refresh()
833 873
834 def hgQueueListQueues(self, name): 874 def hgQueueListQueues(self, name):
835 """ 875 """
836 Public method to list available queues. 876 Public method to list available queues.
837 877

eric ide

mercurial