Continued implementing an interface to the Mercurial command server.

Tue, 30 Aug 2011 18:20:55 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 30 Aug 2011 18:20:55 +0200
changeset 1249
77f836a883c1
parent 1248
7d0eff6435a9
child 1250
dafdd7d97a9f

Continued implementing an interface to the Mercurial command server.
Modified tag/branch list dialog and the fetch, GPG, purge, rebase and transplant extensions.

Plugins/VcsPlugins/vcsMercurial/FetchExtension/fetch.py file | annotate | diff | comparison | revisions
Plugins/VcsPlugins/vcsMercurial/GpgExtension/HgGpgSignaturesDialog.py file | annotate | diff | comparison | revisions
Plugins/VcsPlugins/vcsMercurial/GpgExtension/gpg.py file | annotate | diff | comparison | revisions
Plugins/VcsPlugins/vcsMercurial/HgTagBranchListDialog.py file | annotate | diff | comparison | revisions
Plugins/VcsPlugins/vcsMercurial/PurgeExtension/purge.py file | annotate | diff | comparison | revisions
Plugins/VcsPlugins/vcsMercurial/RebaseExtension/rebase.py file | annotate | diff | comparison | revisions
Plugins/VcsPlugins/vcsMercurial/TransplantExtension/transplant.py file | annotate | diff | comparison | revisions
--- a/Plugins/VcsPlugins/vcsMercurial/FetchExtension/fetch.py	Tue Aug 30 18:19:32 2011 +0200
+++ b/Plugins/VcsPlugins/vcsMercurial/FetchExtension/fetch.py	Tue Aug 30 18:20:55 2011 +0200
@@ -57,7 +57,8 @@
                 args.append("--switch-parent")
             args.append("-v")
             
-            dia = HgDialog(self.trUtf8('Fetching from a remote Mercurial repository'))
+            dia = HgDialog(self.trUtf8('Fetching from a remote Mercurial repository'),
+                           self.vcs)
             res = dia.startProcess(args, repodir)
             if res:
                 dia.exec_()
--- a/Plugins/VcsPlugins/vcsMercurial/GpgExtension/HgGpgSignaturesDialog.py	Tue Aug 30 18:19:32 2011 +0200
+++ b/Plugins/VcsPlugins/vcsMercurial/GpgExtension/HgGpgSignaturesDialog.py	Tue Aug 30 18:20:55 2011 +0200
@@ -42,6 +42,7 @@
         
         self.process = QProcess()
         self.vcs = vcs
+        self.__hgClient = vcs.getClient()
         
         self.process.finished.connect(self.__procFinished)
         self.process.readyReadStandardOutput.connect(self.__readStdout)
@@ -85,23 +86,35 @@
         args = []
         args.append('sigs')
         
-        self.process.kill()
-        self.process.setWorkingDirectory(repodir)
-        
-        self.process.start('hg', args)
-        procStarted = self.process.waitForStarted()
-        if not procStarted:
+        if self.__hgClient:
             self.inputGroup.setEnabled(False)
             self.inputGroup.hide()
-            E5MessageBox.critical(self,
-                self.trUtf8('Process Generation Error'),
-                self.trUtf8(
-                    'The process {0} could not be started. '
-                    'Ensure, that it is in the search path.'
-                ).format('hg'))
+            
+            out, err = self.__hgClient.runcommand(args)
+            if err:
+                self.__showError(err)
+            if out:
+                for line in out.splitlines():
+                    self.__processOutputLine(line)
+            self.__finish()
         else:
-            self.inputGroup.setEnabled(True)
-            self.inputGroup.show()
+            self.process.kill()
+            self.process.setWorkingDirectory(repodir)
+            
+            self.process.start('hg', args)
+            procStarted = self.process.waitForStarted()
+            if not procStarted:
+                self.inputGroup.setEnabled(False)
+                self.inputGroup.hide()
+                E5MessageBox.critical(self,
+                    self.trUtf8('Process Generation Error'),
+                    self.trUtf8(
+                        'The process {0} could not be started. '
+                        'Ensure, that it is in the search path.'
+                    ).format('hg'))
+            else:
+                self.inputGroup.setEnabled(True)
+                self.inputGroup.show()
     
     def __finish(self):
         """
@@ -139,7 +152,10 @@
         if button == self.buttonBox.button(QDialogButtonBox.Close):
             self.close()
         elif button == self.buttonBox.button(QDialogButtonBox.Cancel):
-            self.__finish()
+            if self.__hgClient:
+                self.__hgClient.cancel()
+            else:
+                self.__finish()
     
     def __procFinished(self, exitCode, exitStatus):
         """
@@ -202,13 +218,21 @@
             s = str(self.process.readLine(),
                     Preferences.getSystem("IOEncoding"),
                     'replace').strip()
-            l = s.split()
-            if l[-1][0] in "1234567890":
-                # last element is a rev:changeset
-                rev, changeset = l[-1].split(":", 1)
-                del l[-1]
-                signature = " ".join(l)
-                self.__generateItem(rev, changeset, signature)
+            self.__processOutputLine(s)
+    
+    def __processOutputLine(self, line):
+        """
+        Private method to process the lines of output.
+        
+        @param line output line to be processed (string)
+        """
+        l = line.split()
+        if l[-1][0] in "1234567890":
+            # last element is a rev:changeset
+            rev, changeset = l[-1].split(":", 1)
+            del l[-1]
+            signature = " ".join(l)
+            self.__generateItem(rev, changeset, signature)
     
     def __readStderr(self):
         """
@@ -222,8 +246,17 @@
             s = str(self.process.readAllStandardError(),
                     Preferences.getSystem("IOEncoding"),
                     'replace')
-            self.errors.insertPlainText(s)
-            self.errors.ensureCursorVisible()
+            self.__showError(s)
+    
+    def __showError(self, out):
+        """
+        Private slot to show some error.
+        
+        @param out error to be shown (string)
+        """
+        self.errorGroup.show()
+        self.errors.insertPlainText(out)
+        self.errors.ensureCursorVisible()
     
     @pyqtSlot()
     def on_signaturesList_itemSelectionChanged(self):
--- a/Plugins/VcsPlugins/vcsMercurial/GpgExtension/gpg.py	Tue Aug 30 18:19:32 2011 +0200
+++ b/Plugins/VcsPlugins/vcsMercurial/GpgExtension/gpg.py	Tue Aug 30 18:20:55 2011 +0200
@@ -84,7 +84,7 @@
             args.append("sigcheck")
             args.append(rev)
             
-            dia = HgDialog(self.trUtf8('Verify Signatures'))
+            dia = HgDialog(self.trUtf8('Verify Signatures'), self.vcs)
             res = dia.startProcess(args, repodir)
             if res:
                 dia.exec_()
@@ -130,7 +130,7 @@
             if revision:
                 args.append(revision)
             
-            dia = HgDialog(self.trUtf8('Sign Revision'))
+            dia = HgDialog(self.trUtf8('Sign Revision'), self.vcs)
             res = dia.startProcess(args, repodir)
             if res:
                 dia.exec_()
--- a/Plugins/VcsPlugins/vcsMercurial/HgTagBranchListDialog.py	Tue Aug 30 18:19:32 2011 +0200
+++ b/Plugins/VcsPlugins/vcsMercurial/HgTagBranchListDialog.py	Tue Aug 30 18:20:55 2011 +0200
@@ -41,6 +41,7 @@
         self.vcs = vcs
         self.tagsList = None
         self.allTagsList = None
+        self.__hgClient = vcs.getClient()
         
         self.tagList.headerItem().setText(self.tagList.columnCount(), "")
         self.tagList.header().setSortIndicator(3, Qt.AscendingOrder)
@@ -101,23 +102,35 @@
             args.append('branches')
             args.append('--closed')
         
-        self.process.kill()
-        self.process.setWorkingDirectory(repodir)
-        
-        self.process.start('hg', args)
-        procStarted = self.process.waitForStarted()
-        if not procStarted:
+        if self.__hgClient:
             self.inputGroup.setEnabled(False)
             self.inputGroup.hide()
-            E5MessageBox.critical(self,
-                self.trUtf8('Process Generation Error'),
-                self.trUtf8(
-                    'The process {0} could not be started. '
-                    'Ensure, that it is in the search path.'
-                ).format('hg'))
+            
+            out, err = self.__hgClient.runcommand(args)
+            if err:
+                self.__showError(err)
+            if out:
+                for line in out.splitlines():
+                    self.__processOutputLine(line)
+            self.__finish()
         else:
-            self.inputGroup.setEnabled(True)
-            self.inputGroup.show()
+            self.process.kill()
+            self.process.setWorkingDirectory(repodir)
+            
+            self.process.start('hg', args)
+            procStarted = self.process.waitForStarted()
+            if not procStarted:
+                self.inputGroup.setEnabled(False)
+                self.inputGroup.hide()
+                E5MessageBox.critical(self,
+                    self.trUtf8('Process Generation Error'),
+                    self.trUtf8(
+                        'The process {0} could not be started. '
+                        'Ensure, that it is in the search path.'
+                    ).format('hg'))
+            else:
+                self.inputGroup.setEnabled(True)
+                self.inputGroup.show()
     
     def __finish(self):
         """
@@ -152,7 +165,10 @@
         if button == self.buttonBox.button(QDialogButtonBox.Close):
             self.close()
         elif button == self.buttonBox.button(QDialogButtonBox.Cancel):
-            self.__finish()
+            if self.__hgClient:
+                self.__hgClient.cancel()
+            else:
+                self.__finish()
     
     def __procFinished(self, exitCode, exitStatus):
         """
@@ -208,29 +224,37 @@
             s = str(self.process.readLine(),
                     Preferences.getSystem("IOEncoding"),
                     'replace').strip()
-            l = s.split()
-            if l[-1][0] in "1234567890":
-                # last element is a rev:changeset
-                if self.tagsMode:
-                    status = ""
-                else:
-                    status = self.trUtf8("active")
-                rev, changeset = l[-1].split(":", 1)
-                del l[-1]
+            self.__processOutputLine(s)
+    
+    def __processOutputLine(self, line):
+        """
+        Private method to process the lines of output.
+        
+        @param line output line to be processed (string)
+        """
+        l = line.split()
+        if l[-1][0] in "1234567890":
+            # last element is a rev:changeset
+            if self.tagsMode:
+                status = ""
             else:
-                if self.tagsMode:
-                    status = self.trUtf8("yes")
-                else:
-                    status = l[-1][1:-1]
-                rev, changeset = l[-2].split(":", 1)
-                del l[-2:]
-            name = " ".join(l)
-            self.__generateItem(rev, changeset, status, name)
-            if name not in ["tip", "default"]:
-                if self.tagsList is not None:
-                    self.tagsList.append(name)
-                if self.allTagsList is not None:
-                    self.allTagsList.append(name)
+                status = self.trUtf8("active")
+            rev, changeset = l[-1].split(":", 1)
+            del l[-1]
+        else:
+            if self.tagsMode:
+                status = self.trUtf8("yes")
+            else:
+                status = l[-1][1:-1]
+            rev, changeset = l[-2].split(":", 1)
+            del l[-2:]
+        name = " ".join(l)
+        self.__generateItem(rev, changeset, status, name)
+        if name not in ["tip", "default"]:
+            if self.tagsList is not None:
+                self.tagsList.append(name)
+            if self.allTagsList is not None:
+                self.allTagsList.append(name)
     
     def __readStderr(self):
         """
@@ -244,8 +268,17 @@
             s = str(self.process.readAllStandardError(),
                     Preferences.getSystem("IOEncoding"),
                     'replace')
-            self.errors.insertPlainText(s)
-            self.errors.ensureCursorVisible()
+            self.__showError(s)
+    
+    def __showError(self, out):
+        """
+        Private slot to show some error.
+        
+        @param out error to be shown (string)
+        """
+        self.errorGroup.show()
+        self.errors.insertPlainText(out)
+        self.errors.ensureCursorVisible()
     
     def on_passwordCheckBox_toggled(self, isOn):
         """
--- a/Plugins/VcsPlugins/vcsMercurial/PurgeExtension/purge.py	Tue Aug 30 18:19:32 2011 +0200
+++ b/Plugins/VcsPlugins/vcsMercurial/PurgeExtension/purge.py	Tue Aug 30 18:20:55 2011 +0200
@@ -53,23 +53,29 @@
         """
         purgeEntries = []
         
-        ioEncoding = Preferences.getSystem("IOEncoding")
-        process = QProcess()
         args = []
         args.append("purge")
         args.append("--print")
         if all:
             args.append("--all")
         
-        process.setWorkingDirectory(repodir)
-        process.start('hg', args)
-        procStarted = process.waitForStarted()
-        if procStarted:
-            finished = process.waitForFinished(30000)
-            if finished and process.exitCode() == 0:
-                purgeEntries = str(
-                    process.readAllStandardOutput(),
-                    ioEncoding, 'replace').strip().split()
+        client = self.vcs.getClient()
+        if client:
+            out, err = client.runcommand(args)
+            if out:
+                purgeEntries = out.strip().split()
+        else:
+            ioEncoding = Preferences.getSystem("IOEncoding")
+            process = QProcess()
+            process.setWorkingDirectory(repodir)
+            process.start('hg', args)
+            procStarted = process.waitForStarted()
+            if procStarted:
+                finished = process.waitForFinished(30000)
+                if finished and process.exitCode() == 0:
+                    purgeEntries = str(
+                        process.readAllStandardOutput(),
+                        ioEncoding, 'replace').strip().split()
         
         return purgeEntries
     
@@ -104,7 +110,7 @@
                 args.append("--all")
             args.append("-v")
             
-            dia = HgDialog(title)
+            dia = HgDialog(title, self.vcs)
             res = dia.startProcess(args, repodir)
             if res:
                 dia.exec_()
--- a/Plugins/VcsPlugins/vcsMercurial/RebaseExtension/rebase.py	Tue Aug 30 18:19:32 2011 +0200
+++ b/Plugins/VcsPlugins/vcsMercurial/RebaseExtension/rebase.py	Tue Aug 30 18:20:55 2011 +0200
@@ -77,7 +77,7 @@
                 args.append("--detach")
             args.append("--verbose")
             
-            dia = HgDialog(self.trUtf8('Rebase Changesets'))
+            dia = HgDialog(self.trUtf8('Rebase Changesets'), self.vcs)
             res = dia.startProcess(args, repodir)
             if res:
                 dia.exec_()
@@ -104,7 +104,7 @@
         args.append("--continue")
         args.append("--verbose")
         
-        dia = HgDialog(self.trUtf8('Rebase Changesets (Continue)'))
+        dia = HgDialog(self.trUtf8('Rebase Changesets (Continue)'), self.vcs)
         res = dia.startProcess(args, repodir)
         if res:
             dia.exec_()
@@ -131,7 +131,7 @@
         args.append("--abort")
         args.append("--verbose")
         
-        dia = HgDialog(self.trUtf8('Rebase Changesets (Abort)'))
+        dia = HgDialog(self.trUtf8('Rebase Changesets (Abort)'), self.vcs)
         res = dia.startProcess(args, repodir)
         if res:
             dia.exec_()
--- a/Plugins/VcsPlugins/vcsMercurial/TransplantExtension/transplant.py	Tue Aug 30 18:19:32 2011 +0200
+++ b/Plugins/VcsPlugins/vcsMercurial/TransplantExtension/transplant.py	Tue Aug 30 18:20:55 2011 +0200
@@ -69,7 +69,7 @@
                 args.append("--log")
             args.extend(revs)
             
-            dia = HgDialog(self.trUtf8('Transplant Changesets'))
+            dia = HgDialog(self.trUtf8('Transplant Changesets'), self.vcs)
             res = dia.startProcess(args, repodir)
             if res:
                 dia.exec_()
@@ -96,7 +96,7 @@
         args.append("--continue")
         args.append("--verbose")
         
-        dia = HgDialog(self.trUtf8('Transplant Changesets (Continue)'))
+        dia = HgDialog(self.trUtf8('Transplant Changesets (Continue)'), self.vcs)
         res = dia.startProcess(args, repodir)
         if res:
             dia.exec_()

eric ide

mercurial