Tue, 30 Aug 2011 18:50:20 +0200
Continued implementing an interface to the Mercurial command server.
Modified bookmarks extension.
--- a/Plugins/VcsPlugins/vcsMercurial/BookmarksExtension/HgBookmarksInOutDialog.py Tue Aug 30 18:48:17 2011 +0200 +++ b/Plugins/VcsPlugins/vcsMercurial/BookmarksExtension/HgBookmarksInOutDialog.py Tue Aug 30 18:50:20 2011 +0200 @@ -52,6 +52,7 @@ self.process = QProcess() self.vcs = vcs self.mode = mode + self.__hgClient = vcs.getClient() self.bookmarksList.headerItem().setText(self.bookmarksList.columnCount(), "") self.bookmarksList.header().setSortIndicator(3, Qt.AscendingOrder) @@ -103,23 +104,35 @@ raise ValueError("Bad value for mode") args.append('--bookmarks') - 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): """ @@ -157,7 +170,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): """ @@ -189,10 +205,9 @@ @param changeset changeset of the bookmark (string) @param name name of the bookmark (string) """ - itm = QTreeWidgetItem(self.bookmarksList, [ + QTreeWidgetItem(self.bookmarksList, [ name, changeset]) - itm.setTextAlignment(1, Qt.AlignRight) def __readStdout(self): """ @@ -207,12 +222,20 @@ s = str(self.process.readLine(), Preferences.getSystem("IOEncoding"), 'replace') - if s.startswith(" "): - l = s.strip().split() - changeset = l[-1] - del l[-1] - name = " ".join(l) - self.__generateItem(changeset, name) + self.__processOutputLine(s) + + def __processOutputLine(self, line): + """ + Private method to process the lines of output. + + @param line output line to be processed (string) + """ + if line.startswith(" "): + l = line.strip().split() + changeset = l[-1] + del l[-1] + name = " ".join(l) + self.__generateItem(changeset, name) def __readStderr(self): """ @@ -222,12 +245,20 @@ error pane. """ if self.process is not None: - self.errorGroup.show() 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/BookmarksExtension/HgBookmarksListDialog.py Tue Aug 30 18:48:17 2011 +0200 +++ b/Plugins/VcsPlugins/vcsMercurial/BookmarksExtension/HgBookmarksListDialog.py Tue Aug 30 18:50:20 2011 +0200 @@ -40,6 +40,7 @@ self.process = QProcess() self.vcs = vcs self.__bookmarksList = None + self.__hgClient = vcs.getClient() self.bookmarksList.headerItem().setText(self.bookmarksList.columnCount(), "") self.bookmarksList.header().setSortIndicator(3, Qt.AscendingOrder) @@ -88,23 +89,35 @@ args = [] args.append('bookmarks') - 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): """ @@ -142,7 +155,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): """ @@ -198,20 +214,28 @@ 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] - if l[0] == "*": - status = "current" - del l[0] - else: - status = "" - name = " ".join(l) - self.__generateItem(rev, changeset, status, name) - if self.__bookmarksList is not None: - self.__bookmarksList.append(name) + 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] + if l[0] == "*": + status = "current" + del l[0] + else: + status = "" + name = " ".join(l) + self.__generateItem(rev, changeset, status, name) + if self.__bookmarksList is not None: + self.__bookmarksList.append(name) def __readStderr(self): """ @@ -221,12 +245,20 @@ error pane. """ if self.process is not None: - self.errorGroup.show() 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/BookmarksExtension/bookmarks.py Tue Aug 30 18:48:17 2011 +0200 +++ b/Plugins/VcsPlugins/vcsMercurial/BookmarksExtension/bookmarks.py Tue Aug 30 18:50:20 2011 +0200 @@ -67,28 +67,34 @@ @param repodir directory name of the repository (string) @return list of bookmarks (list of string) """ - ioEncoding = Preferences.getSystem("IOEncoding") - process = QProcess() args = [] args.append('bookmarks') - process.setWorkingDirectory(repodir) - process.start('hg', args) - procStarted = process.waitForStarted() - if procStarted: - finished = process.waitForFinished(30000) - if finished and process.exitCode() == 0: - output = \ - str(process.readAllStandardOutput(), ioEncoding, 'replace') - self.bookmarksList = [] - for line in output.splitlines(): - l = line.strip().split() - if l[-1][0] in "1234567890": - # last element is a rev:changeset - del l[-1] - if l[0] == "*": - del l[0] - name = " ".join(l) - self.bookmarksList.append(name) + + client = self.vcs.getClient() + if client: + output = client.runcommand(args)[0] + 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: + output = \ + str(process.readAllStandardOutput(), ioEncoding, 'replace') + + self.bookmarksList = [] + for line in output.splitlines(): + l = line.strip().split() + if l[-1][0] in "1234567890": + # last element is a rev:changeset + del l[-1] + if l[0] == "*": + del l[0] + name = " ".join(l) + self.bookmarksList.append(name) return self.bookmarksList[:] @@ -119,7 +125,7 @@ args.append(rev) args.append(bookmark) - dia = HgDialog(self.trUtf8('Mercurial Bookmark')) + dia = HgDialog(self.trUtf8('Mercurial Bookmark'), self.vcs) res = dia.startProcess(args, repodir) if res: dia.exec_() @@ -149,7 +155,7 @@ args.append("--delete") args.append(bookmark) - dia = HgDialog(self.trUtf8('Delete Mercurial Bookmark')) + dia = HgDialog(self.trUtf8('Delete Mercurial Bookmark'), self.vcs) res = dia.startProcess(args, repodir) if res: dia.exec_() @@ -177,7 +183,7 @@ args.append(oldName) args.append(newName) - dia = HgDialog(self.trUtf8('Rename Mercurial Bookmark')) + dia = HgDialog(self.trUtf8('Rename Mercurial Bookmark'), self.vcs) res = dia.startProcess(args, repodir) if res: dia.exec_() @@ -210,7 +216,7 @@ args.append(rev) args.append(bookmark) - dia = HgDialog(self.trUtf8('Move Mercurial Bookmark')) + dia = HgDialog(self.trUtf8('Move Mercurial Bookmark'), self.vcs) res = dia.startProcess(args, repodir) if res: dia.exec_() @@ -247,28 +253,34 @@ """ bookmarksList = [] - ioEncoding = Preferences.getSystem("IOEncoding") - process = QProcess() args = [] if incoming: args.append('incoming') else: args.append('outgoing') args.append('--bookmarks') - process.setWorkingDirectory(repodir) - process.start('hg', args) - procStarted = process.waitForStarted() - if procStarted: - finished = process.waitForFinished(30000) - if finished and process.exitCode() == 0: - output = \ - str(process.readAllStandardOutput(), ioEncoding, 'replace') - for line in output.splitlines(): - if line.startswith(" "): - l = line.strip().split() - del l[-1] - name = " ".join(l) - bookmarksList.append(name) + + client = self.vcs.getClient() + if client: + output = client.runcommand(args)[0] + 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: + output = \ + str(process.readAllStandardOutput(), ioEncoding, 'replace') + + for line in output.splitlines(): + if line.startswith(" "): + l = line.strip().split() + del l[-1] + name = " ".join(l) + bookmarksList.append(name) return bookmarksList @@ -298,11 +310,12 @@ args.append('pull') args.append('--bookmark') args.append(bookmark) - - dia = HgDialog(self.trUtf8('Pulling bookmark from a remote Mercurial repository')) - res = dia.startProcess(args, repodir) - if res: - dia.exec_() + + dia = HgDialog(self.trUtf8('Pulling bookmark from a remote Mercurial repository'), + self.vcs) + res = dia.startProcess(args, repodir) + if res: + dia.exec_() def hgBookmarkPush(self, name): """ @@ -330,8 +343,9 @@ args.append('push') args.append('--bookmark') args.append(bookmark) - - dia = HgDialog(self.trUtf8('Pushing bookmark to a remote Mercurial repository')) - res = dia.startProcess(args, repodir) - if res: - dia.exec_() + + dia = HgDialog(self.trUtf8('Pushing bookmark to a remote Mercurial repository'), + self.vcs) + res = dia.startProcess(args, repodir) + if res: + dia.exec_()