--- a/src/eric7/Plugins/VcsPlugins/vcsMercurial/QueuesExtension/queues.py Sun Jan 07 19:54:03 2024 +0100 +++ b/src/eric7/Plugins/VcsPlugins/vcsMercurial/QueuesExtension/queues.py Mon Jan 08 11:14:48 2024 +0100 @@ -7,6 +7,8 @@ Module implementing the queues extension interface. """ +import enum + from PyQt6.QtWidgets import QApplication, QDialog, QInputDialog from eric7.EricWidgets import EricMessageBox @@ -15,26 +17,35 @@ from ..HgExtension import HgExtension +class QueuePatchesListType(enum.Enum): + """ + Class defining the supported queue patch list types. + """ + + APPLIED = 0 + UNAPPLIED = 1 + SERIES = 2 + + +class QueueOperation(enum.Enum): + """ + Class defining the supported queue operations. + """ + + POP = 0 + PUSH = 1 + GOTO = 2 + + DELETE = 3 + PURGE = 4 + ACTIVATE = 5 + + class Queues(HgExtension): """ Class implementing the queues extension interface. """ - # TODO: change this to an enum - APPLIED_LIST = 0 - UNAPPLIED_LIST = 1 - SERIES_LIST = 2 - - # TODO: change this to an enum - POP = 0 - PUSH = 1 - GOTO = 2 - - # TODO: change this to an enum - QUEUE_DELETE = 0 - QUEUE_PURGE = 1 - QUEUE_ACTIVATE = 2 - def __init__(self, vcs): """ Constructor @@ -79,8 +90,7 @@ Private method to get a list of patches of a given type. @param listType type of patches list to get - (Queues.APPLIED_LIST, Queues.UNAPPLIED_LIST, Queues.SERIES_LIST) - @type int + @type QueuePatchesListType @param withSummary flag indicating to get a summary as well @type bool @return list of patches @@ -89,16 +99,12 @@ """ patchesList = [] - if listType not in ( - Queues.APPLIED_LIST, - Queues.UNAPPLIED_LIST, - Queues.SERIES_LIST, - ): + if not isinstance(listType, QueuePatchesListType): raise ValueError("illegal value for listType") - if listType == Queues.APPLIED_LIST: + if listType == QueuePatchesListType.APPLIED: args = self.vcs.initCommand("qapplied") - elif listType == Queues.UNAPPLIED_LIST: + elif listType == QueuePatchesListType.UNAPPLIED: args = self.vcs.initCommand("qunapplied") else: args = self.vcs.initCommand("qseries") @@ -185,9 +191,12 @@ """ Public method to create a new named patch. """ - from .HgQueuesNewPatchDialog import HgQueuesNewPatchDialog + from .HgQueuesNewPatchDialog import ( + HgQueuesNewPatchDialog, + HgQueuesNewPatchDialogMode, + ) - dlg = HgQueuesNewPatchDialog(HgQueuesNewPatchDialog.NEW_MODE) + dlg = HgQueuesNewPatchDialog(HgQueuesNewPatchDialogMode.NEW) if dlg.exec() == QDialog.DialogCode.Accepted: ( name, @@ -228,14 +237,17 @@ commit message @type bool """ - from .HgQueuesNewPatchDialog import HgQueuesNewPatchDialog + from .HgQueuesNewPatchDialog import ( + HgQueuesNewPatchDialog, + HgQueuesNewPatchDialogMode, + ) args = self.vcs.initCommand("qrefresh") if editMessage: currentMessage = self.__getCommitMessage() dlg = HgQueuesNewPatchDialog( - HgQueuesNewPatchDialog.REFRESH_MODE, currentMessage + HgQueuesNewPatchDialogMode.REFRESH, currentMessage ) if dlg.exec() == QDialog.DialogCode.Accepted: ( @@ -298,9 +310,8 @@ Public method to push patches onto the stack or pop patches off the stack. - @param operation operation type to be performed (Queues.POP, - Queues.PUSH, Queues.GOTO) - @type int + @param operation operation to be performed (POP, PUSH or GOTO) + @type QueueOperation @param doAll flag indicating to push/pop all @type bool @param named flag indicating to push/pop until a named patch @@ -312,28 +323,32 @@ @rtype bool @exception ValueError raised to indicate an invalid operation """ - if operation not in (Queues.POP, Queues.PUSH, Queues.GOTO): + if operation not in ( + QueueOperation.POP, + QueueOperation.PUSH, + QueueOperation.GOTO, + ): raise ValueError("illegal value for operation") - if operation == Queues.POP: + if operation == QueueOperation.POP: args = self.vcs.initCommand("qpop") title = self.tr("Pop Patches") - listType = Queues.APPLIED_LIST - elif operation == Queues.PUSH: + listType = QueuePatchesListType + elif operation == QueueOperation.PUSH: args = self.vcs.initCommand("qpush") title = self.tr("Push Patches") - listType = Queues.UNAPPLIED_LIST + listType = QueuePatchesListType.UNAPPLIED else: args = self.vcs.initCommand("qgoto") title = self.tr("Go to Patch") - listType = Queues.SERIES_LIST + listType = QueuePatchesListType.SERIES args.append("-v") if force: args.append("--force") - if doAll and operation in (Queues.POP, Queues.PUSH): + if doAll and operation in (QueueOperation.POP, QueueOperation.PUSH): args.append("--all") - elif named or operation == Queues.GOTO: + elif named or operation == QueueOperation.GOTO: patchnames = self.__getPatchesList(listType) if patchnames: patch, ok = QInputDialog.getItem( @@ -394,7 +409,7 @@ from .HgQueuesRenamePatchDialog import HgQueuesRenamePatchDialog args = self.vcs.initCommand("qrename") - patchnames = sorted(self.__getPatchesList(Queues.SERIES_LIST)) + patchnames = sorted(self.__getPatchesList(QueuePatchesListType.SERIES)) if patchnames: currentPatch = self.__getCurrentPatch() if currentPatch: @@ -415,7 +430,7 @@ Public method to delete a selected unapplied patch. """ args = self.vcs.initCommand("qdelete") - patchnames = sorted(self.__getPatchesList(Queues.UNAPPLIED_LIST)) + patchnames = sorted(self.__getPatchesList(QueuePatchesListType.UNAPPLIED)) if patchnames: patch, ok = QInputDialog.getItem( None, @@ -445,7 +460,7 @@ args = self.vcs.initCommand("qfold") patchnames = sorted( - self.__getPatchesList(Queues.UNAPPLIED_LIST, withSummary=True) + self.__getPatchesList(QueuePatchesListType.UNAPPLIED, withSummary=True) ) if patchnames: dlg = HgQueuesFoldDialog(patchnames) @@ -480,7 +495,7 @@ """ from .HgQueuesListGuardsDialog import HgQueuesListGuardsDialog - patchnames = sorted(self.__getPatchesList(Queues.SERIES_LIST)) + patchnames = sorted(self.__getPatchesList(QueuePatchesListType.SERIES)) if patchnames: self.queuesListGuardsDialog = HgQueuesListGuardsDialog(self.vcs, patchnames) self.queuesListGuardsDialog.show() @@ -508,7 +523,7 @@ """ from .HgQueuesDefineGuardsDialog import HgQueuesDefineGuardsDialog - patchnames = sorted(self.__getPatchesList(Queues.SERIES_LIST)) + patchnames = sorted(self.__getPatchesList(QueuePatchesListType.SERIES)) if patchnames: self.queuesDefineGuardsDialog = HgQueuesDefineGuardsDialog( self.vcs, self, patchnames @@ -526,7 +541,7 @@ """ Public method to drop all guards of the current or a named patch. """ - patchnames = sorted(self.__getPatchesList(Queues.SERIES_LIST)) + patchnames = sorted(self.__getPatchesList(QueuePatchesListType.SERIES)) if patchnames: patch, ok = QInputDialog.getItem( None, @@ -614,13 +629,16 @@ @param isCreate flag indicating to create a new queue @type bool """ - from .HgQueuesQueueManagementDialog import HgQueuesQueueManagementDialog + from .HgQueuesQueueManagementDialog import ( + HgQueuesQueueManagementDialog, + HgQueuesQueueManagementDialogMode, + ) title = ( self.tr("Create New Queue") if isCreate else self.tr("Rename Active Queue") ) dlg = HgQueuesQueueManagementDialog( - HgQueuesQueueManagementDialog.NAME_INPUT, title, False, self.vcs + HgQueuesQueueManagementDialogMode.NAME_INPUT, title, False, self.vcs ) if dlg.exec() == QDialog.DialogCode.Accepted: queueName = dlg.getData() @@ -655,37 +673,39 @@ Public method to delete the reference to a queue and optionally remove the patch directory or set the active queue. - @param operation operation to be performed (Queues.QUEUE_DELETE, - Queues.QUEUE_PURGE, Queues.QUEUE_ACTIVATE) - @type int + @param operation operation to be performed (PURGE, DELETE or ACTIVATE) + @type QueueOperation @exception ValueError raised to indicate an invalid operation """ - from .HgQueuesQueueManagementDialog import HgQueuesQueueManagementDialog + from .HgQueuesQueueManagementDialog import ( + HgQueuesQueueManagementDialog, + HgQueuesQueueManagementDialogMode, + ) if operation not in ( - Queues.QUEUE_PURGE, - Queues.QUEUE_DELETE, - Queues.QUEUE_ACTIVATE, + QueueOperation.PURGE, + QueueOperation.DELETE, + QueueOperation.ACTIVATE, ): raise ValueError("illegal value for operation") - if operation == Queues.QUEUE_PURGE: + if operation == QueueOperation.PURGE: title = self.tr("Purge Queue") - elif operation == Queues.QUEUE_DELETE: + elif operation == QueueOperation.DELETE: title = self.tr("Delete Queue") else: title = self.tr("Activate Queue") dlg = HgQueuesQueueManagementDialog( - HgQueuesQueueManagementDialog.QUEUE_INPUT, title, True, self.vcs + HgQueuesQueueManagementDialogMode.QUEUE_INPUT, title, True, self.vcs ) if dlg.exec() == QDialog.DialogCode.Accepted: queueName = dlg.getData() if queueName: args = self.vcs.initCommand("qqueue") - if operation == Queues.QUEUE_PURGE: + if operation == QueueOperation.PURGE: args.append("--purge") - elif operation == Queues.QUEUE_DELETE: + elif operation == QueueOperation.DELETE: args.append("--delete") args.append(queueName) @@ -693,11 +713,11 @@ error = client.runcommand(args)[1] if error: - if operation == Queues.QUEUE_PURGE: + if operation == QueueOperation.PURGE: errMsg = self.tr("Error while purging the queue.") - elif operation == Queues.QUEUE_DELETE: + elif operation == QueueOperation.DELETE: errMsg = self.tr("Error while deleting the queue.") - elif operation == Queues.QUEUE_ACTIVATE: + elif operation == QueueOperation.ACTIVATE: errMsg = self.tr("Error while setting the active queue.") EricMessageBox.warning( None, title, """<p>{0}</p><p>{1}</p>""".format(errMsg, error) @@ -713,10 +733,13 @@ """ Public method to list available queues. """ - from .HgQueuesQueueManagementDialog import HgQueuesQueueManagementDialog + from .HgQueuesQueueManagementDialog import ( + HgQueuesQueueManagementDialog, + HgQueuesQueueManagementDialogMode, + ) self.queuesListQueuesDialog = HgQueuesQueueManagementDialog( - HgQueuesQueueManagementDialog.NO_INPUT, + HgQueuesQueueManagementDialogMode.NO_INPUT, self.tr("Available Queues"), False, self.vcs,