Sun, 28 Aug 2011 20:08:21 +0200
Continued implementing an interface to the Mercurial command server.
Modified Annotate, Log Browser and Status dialogs.
diff -r 4d5fc346bd3b -r 09c6155ee612 Plugins/VcsPlugins/vcsMercurial/HgAnnotateDialog.py --- a/Plugins/VcsPlugins/vcsMercurial/HgAnnotateDialog.py Sun Aug 28 18:53:13 2011 +0200 +++ b/Plugins/VcsPlugins/vcsMercurial/HgAnnotateDialog.py Sun Aug 28 20:08:21 2011 +0200 @@ -38,8 +38,8 @@ self.buttonBox.button(QDialogButtonBox.Close).setEnabled(False) self.buttonBox.button(QDialogButtonBox.Cancel).setDefault(True) - self.process = QProcess() self.vcs = vcs + self.__hgClient = vcs.getClient() self.annotateList.headerItem().setText(self.annotateList.columnCount(), "") font = QFont(self.annotateList.font()) @@ -51,9 +51,13 @@ self.__ioEncoding = Preferences.getSystem("IOEncoding") - self.process.finished.connect(self.__procFinished) - self.process.readyReadStandardOutput.connect(self.__readStdout) - self.process.readyReadStandardError.connect(self.__readStderr) + if self.__hgClient: + self.process = None + else: + self.process = QProcess() + self.process.finished.connect(self.__procFinished) + self.process.readyReadStandardOutput.connect(self.__readStdout) + self.process.readyReadStandardError.connect(self.__readStderr) def closeEvent(self, e): """ @@ -99,23 +103,35 @@ args.append('--quiet') args.append(fn) - 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): """ @@ -193,13 +209,21 @@ while self.process.canReadLine(): s = str(self.process.readLine(), self.__ioEncoding, 'replace').strip() - try: - info, text = s.split(": ", 1) - except ValueError: - info = s[:-2] - text = "" - author, rev, changeset, date, file = info.split() - self.__generateItem(rev, changeset, author, date, text) + self.__processOutputLine(s) + + def __processOutputLine(self, line): + """ + Private method to process the lines of output. + + @param line output line to be processed (string) + """ + try: + info, text = line.split(": ", 1) + except ValueError: + info = line[:-2] + text = "" + author, rev, changeset, date, file = info.split() + self.__generateItem(rev, changeset, author, date, text) def __readStderr(self): """ @@ -213,8 +237,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): """
diff -r 4d5fc346bd3b -r 09c6155ee612 Plugins/VcsPlugins/vcsMercurial/HgClient.py --- a/Plugins/VcsPlugins/vcsMercurial/HgClient.py Sun Aug 28 18:53:13 2011 +0200 +++ b/Plugins/VcsPlugins/vcsMercurial/HgClient.py Sun Aug 28 20:08:21 2011 +0200 @@ -36,6 +36,7 @@ super().__init__(parent) self.__server = QProcess() + self.__server.setWorkingDirectory(repoPath) self.__started = False self.__version = None self.__encoding = Preferences.getSystem("IOEncoding")
diff -r 4d5fc346bd3b -r 09c6155ee612 Plugins/VcsPlugins/vcsMercurial/HgLogBrowserDialog.py --- a/Plugins/VcsPlugins/vcsMercurial/HgLogBrowserDialog.py Sun Aug 28 18:53:13 2011 +0200 +++ b/Plugins/VcsPlugins/vcsMercurial/HgLogBrowserDialog.py Sun Aug 28 20:08:21 2011 +0200 @@ -80,6 +80,7 @@ else: self.commandMode = "log" self.bundle = bundle + self.__hgClient = vcs.getClient() self.__initData() @@ -106,10 +107,13 @@ self.__edgesRole = Qt.UserRole + 2 self.__parentsRole = Qt.UserRole + 3 - self.process = QProcess() - self.process.finished.connect(self.__procFinished) - self.process.readyReadStandardOutput.connect(self.__readStdout) - self.process.readyReadStandardError.connect(self.__readStderr) + if self.__hgClient: + self.process = None + else: + self.process = QProcess() + self.process.finished.connect(self.__procFinished) + self.process.readyReadStandardOutput.connect(self.__readStdout) + self.process.readyReadStandardError.connect(self.__readStderr) self.flags = { 'A': self.trUtf8('Added'), @@ -360,7 +364,6 @@ errMsg = "" parents = [-1] - process = QProcess() args = [] args.append("parents") if self.commandMode == "incoming": @@ -377,29 +380,36 @@ if not self.projectMode: args.append(self.filename) - process.setWorkingDirectory(self.repodir) - process.start('hg', args) - procStarted = process.waitForStarted() - if procStarted: - finished = process.waitForFinished(30000) - if finished and process.exitCode() == 0: - output = \ - str(process.readAllStandardOutput(), - Preferences.getSystem("IOEncoding"), - 'replace') - parents = [int(p) for p in output.strip().splitlines()] + output = "" + if self.__hgClient: + output, errMsg = self.__hgClient.runcommand(args) + else: + process = QProcess() + process.setWorkingDirectory(self.repodir) + process.start('hg', args) + procStarted = process.waitForStarted() + if procStarted: + finished = process.waitForFinished(30000) + if finished and process.exitCode() == 0: + output = \ + str(process.readAllStandardOutput(), + Preferences.getSystem("IOEncoding"), + 'replace') + else: + if not finished: + errMsg = self.trUtf8( + "The hg process did not finish within 30s.") else: - if not finished: - errMsg = self.trUtf8( - "The hg process did not finish within 30s.") - else: - errMsg = self.trUtf8("Could not start the hg executable.") + errMsg = self.trUtf8("Could not start the hg executable.") if errMsg: E5MessageBox.critical(self, self.trUtf8("Mercurial Error"), errMsg) + if output: + parents = [int(p) for p in output.strip().splitlines()] + return parents def __identifyProject(self): @@ -408,35 +418,41 @@ """ errMsg = "" - process = QProcess() args = [] args.append("identify") args.append("-n") - process.setWorkingDirectory(self.repodir) - process.start('hg', args) - procStarted = process.waitForStarted() - if procStarted: - finished = process.waitForFinished(30000) - if finished and process.exitCode() == 0: - output = \ - str(process.readAllStandardOutput(), - Preferences.getSystem("IOEncoding"), - 'replace') - self.__projectRevision = output.strip() - if self.__projectRevision.endswith("+"): - self.__projectRevision = self.__projectRevision[:-1] + output = "" + if self.__hgClient: + output, errMsg = self.__hgClient.runcommand(args) + else: + process = QProcess() + process.setWorkingDirectory(self.repodir) + process.start('hg', args) + procStarted = process.waitForStarted() + if procStarted: + finished = process.waitForFinished(30000) + if finished and process.exitCode() == 0: + output = \ + str(process.readAllStandardOutput(), + Preferences.getSystem("IOEncoding"), + 'replace') + else: + if not finished: + errMsg = self.trUtf8( + "The hg process did not finish within 30s.") else: - if not finished: - errMsg = self.trUtf8( - "The hg process did not finish within 30s.") - else: - errMsg = self.trUtf8("Could not start the hg executable.") + errMsg = self.trUtf8("Could not start the hg executable.") if errMsg: E5MessageBox.critical(self, self.trUtf8("Mercurial Error"), errMsg) + + if output: + self.__projectRevision = output.strip() + if self.__projectRevision.endswith("+"): + self.__projectRevision = self.__projectRevision[:-1] def __getClosedBranches(self): """ @@ -445,37 +461,43 @@ self.__closedBranchesRevs = [] errMsg = "" - process = QProcess() args = [] args.append("branches") args.append("--closed") - process.setWorkingDirectory(self.repodir) - process.start('hg', args) - procStarted = process.waitForStarted() - if procStarted: - finished = process.waitForFinished(30000) - if finished and process.exitCode() == 0: - output = \ - str(process.readAllStandardOutput(), - Preferences.getSystem("IOEncoding"), - 'replace') - for line in output.splitlines(): - if line.strip().endswith("(closed)"): - parts = line.split() - self.__closedBranchesRevs.append( - parts[-2].split(":", 1)[0]) + output = "" + if self.__hgClient: + output, errMsg = self.__hgClient.runcommand(args) + else: + process = QProcess() + process.setWorkingDirectory(self.repodir) + process.start('hg', args) + procStarted = process.waitForStarted() + if procStarted: + finished = process.waitForFinished(30000) + if finished and process.exitCode() == 0: + output = \ + str(process.readAllStandardOutput(), + Preferences.getSystem("IOEncoding"), + 'replace') + else: + if not finished: + errMsg = self.trUtf8( + "The hg process did not finish within 30s.") else: - if not finished: - errMsg = self.trUtf8( - "The hg process did not finish within 30s.") - else: - errMsg = self.trUtf8("Could not start the hg executable.") + errMsg = self.trUtf8("Could not start the hg executable.") if errMsg: E5MessageBox.critical(self, self.trUtf8("Mercurial Error"), errMsg) + + if output: + for line in output.splitlines(): + if line.strip().endswith("(closed)"): + parts = line.split() + self.__closedBranchesRevs.append( + parts[-2].split(":", 1)[0]) def __generateLogItem(self, author, date, message, revision, changedPaths, parents, branches, tags, bookmarks=None): @@ -585,16 +607,10 @@ QApplication.setOverrideCursor(QCursor(Qt.WaitCursor)) QApplication.processEvents() - self.intercept = False - self.process.kill() - self.buf = [] self.cancelled = False self.errors.clear() - self.inputGroup.setEnabled(True) - self.inputGroup.show() - args = [] args.append(self.commandMode) self.vcs.addArguments(args, self.vcs.options['global']) @@ -633,18 +649,32 @@ if not self.projectMode: args.append(self.filename) - self.process.setWorkingDirectory(self.repodir) - - self.process.start('hg', args) - procStarted = self.process.waitForStarted() - if not procStarted: - self.inputGroup.setEnabled(False) - 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')) + if self.__hgClient: + out, err = self.__hgClient.runcommand(args) + self.buf = out.splitlines(True) + if err: + self.__showError(err) + self.__processBuffer() + self.__finish() + else: + self.intercept = False + self.process.kill() + + self.process.setWorkingDirectory(self.repodir) + + self.inputGroup.setEnabled(True) + self.inputGroup.show() + + self.process.start('hg', args) + procStarted = self.process.waitForStarted() + if not procStarted: + self.inputGroup.setEnabled(False) + 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')) def start(self, fn): """ @@ -871,8 +901,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 __diffRevisions(self, rev1, rev2): """
diff -r 4d5fc346bd3b -r 09c6155ee612 Plugins/VcsPlugins/vcsMercurial/HgStatusDialog.py --- a/Plugins/VcsPlugins/vcsMercurial/HgStatusDialog.py Sun Aug 28 18:53:13 2011 +0200 +++ b/Plugins/VcsPlugins/vcsMercurial/HgStatusDialog.py Sun Aug 28 20:08:21 2011 +0200 @@ -53,6 +53,7 @@ self.process = None self.vcs = vcs self.vcs.committed.connect(self.__committed) + self.__hgClient = self.vcs.getClient() self.statusList.headerItem().setText(self.__lastColumn, "") self.statusList.header().setSortIndicator(self.__pathColumn, Qt.AscendingOrder) @@ -180,13 +181,7 @@ self.statusFilterCombo.clear() self.__statusFilters = [] - if self.process: - self.process.kill() - else: - self.process = QProcess() - self.process.finished.connect(self.__procFinished) - self.process.readyReadStandardOutput.connect(self.__readStdout) - self.process.readyReadStandardError.connect(self.__readStderr) + self.setWindowTitle(self.trUtf8('Mercurial Status')) args = [] args.append('status') @@ -207,24 +202,42 @@ if repodir == os.sep: return - self.process.setWorkingDirectory(repodir) - - self.setWindowTitle(self.trUtf8('Mercurial Status')) - - 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() + if self.process: + self.process.kill() + else: + self.process = QProcess() + self.process.finished.connect(self.__procFinished) + self.process.readyReadStandardOutput.connect(self.__readStdout) + self.process.readyReadStandardError.connect(self.__readStderr) + + 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): """ @@ -297,9 +310,17 @@ line = str(self.process.readLine(), Preferences.getSystem("IOEncoding"), 'replace') - if line[0] in "ACIMR?!" and line[1] == " ": - status, path = line.strip().split(" ", 1) - self.__generateItem(status, path) + self.__processOutputLine(line) + + def __processOutputLine(self, line): + """ + Private method to process the lines of output. + + @param line output line to be processed (string) + """ + if line[0] in "ACIMR?!" and line[1] == " ": + status, path = line.strip().split(" ", 1) + self.__generateItem(status, path) def __readStderr(self): """ @@ -313,8 +334,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): """