eric6/Plugins/VcsPlugins/vcsMercurial/HgClient.py

Fri, 07 Feb 2020 18:49:32 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Fri, 07 Feb 2020 18:49:32 +0100
changeset 7399
7088860e4a00
parent 7370
5fb53279f2df
child 7441
f115f4469795
permissions
-rw-r--r--

HgClient: increased the wait time for starting the Mercurial command server.

1240
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7360
9190402e4505 Updated copyright for 2020.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7257
diff changeset
3 # Copyright (c) 2011 - 2020 Detlev Offenbach <detlev@die-offenbachs.de>
1240
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing an interface to the Mercurial command server.
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 import struct
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 import io
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12
7257
c4d0cac9b5c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7192
diff changeset
13 from PyQt5.QtCore import (
c4d0cac9b5c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7192
diff changeset
14 QProcess, QObject, QByteArray, QCoreApplication, QThread
c4d0cac9b5c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7192
diff changeset
15 )
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3555
diff changeset
16 from PyQt5.QtWidgets import QDialog
1323
3126121aeb4f Added a prompt window for the Mercurial command server client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1266
diff changeset
17
2816
05aab5164d64 A little optimization for the Mercurial interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2771
diff changeset
18 from .HgUtilities import prepareProcess
05aab5164d64 A little optimization for the Mercurial interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2771
diff changeset
19
1240
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 class HgClient(QObject):
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 """
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 Class implementing the Mercurial command server interface.
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 """
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 InputFormat = ">I"
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 OutputFormat = ">cI"
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 OutputFormatSize = struct.calcsize(OutputFormat)
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 ReturnFormat = ">i"
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29
1325
8dd723182a16 Improved the Mercurial command server client fix to be more generic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1323
diff changeset
30 Channels = (b"I", b"L", b"o", b"e", b"r", b"d")
8dd723182a16 Improved the Mercurial command server client fix to be more generic.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1323
diff changeset
31
3555
43473ba956ce Fixed a bug in the Mercurial client exhibited by Mercurial 3.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3532
diff changeset
32 def __init__(self, repoPath, encoding, vcs, parent=None):
1240
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 """
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 Constructor
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 @param repoPath root directory of the repository (string)
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 @param encoding encoding to be used by the command server (string)
3555
43473ba956ce Fixed a bug in the Mercurial client exhibited by Mercurial 3.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3532
diff changeset
38 @param vcs reference to the VCS object (Hg)
1240
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 @param parent reference to the parent object (QObject)
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 """
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2405
diff changeset
41 super(HgClient, self).__init__(parent)
1240
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42
1261
bb9ce68a0236 Change the Mercurial client to terminate more reliably.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1260
diff changeset
43 self.__server = None
1240
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 self.__started = False
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 self.__version = None
3555
43473ba956ce Fixed a bug in the Mercurial client exhibited by Mercurial 3.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3532
diff changeset
46 self.__encoding = vcs.getEncoding()
1242
dfb9609caf51 Continued implementing an interface to the Mercurial command server. Modified client all all dialogs done so far to provide a cancel capability..
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1241
diff changeset
47 self.__cancel = False
1256
885706dbb69f Refined the Mercurial command server interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1247
diff changeset
48 self.__commandRunning = False
1261
bb9ce68a0236 Change the Mercurial client to terminate more reliably.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1260
diff changeset
49 self.__repoPath = repoPath
1240
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 # generate command line and environment
3555
43473ba956ce Fixed a bug in the Mercurial client exhibited by Mercurial 3.0.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3532
diff changeset
52 self.__serverArgs = vcs.initCommand("serve")
1240
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 self.__serverArgs.append("--cmdserver")
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 self.__serverArgs.append("pipe")
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 self.__serverArgs.append("--config")
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 self.__serverArgs.append("ui.interactive=True")
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 if repoPath:
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 self.__serverArgs.append("--repository")
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 self.__serverArgs.append(repoPath)
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61 if encoding:
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 self.__encoding = encoding
3302
e92f0dd51979 Removed the Mercurial support for a command options dialog and added useable global options to the Mercurial config page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3190
diff changeset
63 if "--encoding" in self.__serverArgs:
e92f0dd51979 Removed the Mercurial support for a command options dialog and added useable global options to the Mercurial config page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3190
diff changeset
64 # use the defined encoding via the environment
e92f0dd51979 Removed the Mercurial support for a command options dialog and added useable global options to the Mercurial config page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3190
diff changeset
65 index = self.__serverArgs.index("--encoding")
e92f0dd51979 Removed the Mercurial support for a command options dialog and added useable global options to the Mercurial config page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3190
diff changeset
66 del self.__serverArgs[index:index + 2]
1240
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 def startServer(self):
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 """
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 Public method to start the command server.
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 @return tuple of flag indicating a successful start (boolean) and
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 an error message (string) in case of failure
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 """
1261
bb9ce68a0236 Change the Mercurial client to terminate more reliably.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1260
diff changeset
75 self.__server = QProcess()
bb9ce68a0236 Change the Mercurial client to terminate more reliably.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1260
diff changeset
76 self.__server.setWorkingDirectory(self.__repoPath)
bb9ce68a0236 Change the Mercurial client to terminate more reliably.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1260
diff changeset
77
bb9ce68a0236 Change the Mercurial client to terminate more reliably.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1260
diff changeset
78 # connect signals
bb9ce68a0236 Change the Mercurial client to terminate more reliably.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1260
diff changeset
79 self.__server.finished.connect(self.__serverFinished)
bb9ce68a0236 Change the Mercurial client to terminate more reliably.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1260
diff changeset
80
2816
05aab5164d64 A little optimization for the Mercurial interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2771
diff changeset
81 prepareProcess(self.__server, self.__encoding)
1261
bb9ce68a0236 Change the Mercurial client to terminate more reliably.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1260
diff changeset
82
1240
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 self.__server.start('hg', self.__serverArgs)
7399
7088860e4a00 HgClient: increased the wait time for starting the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7370
diff changeset
84 serverStarted = self.__server.waitForStarted(15000)
1240
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 if not serverStarted:
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
86 return False, self.tr(
3036
30c81c9e88b8 Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3008
diff changeset
87 'The process {0} could not be started. '
30c81c9e88b8 Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3008
diff changeset
88 'Ensure, that it is in the search path.'
30c81c9e88b8 Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3008
diff changeset
89 ).format('hg')
1240
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 self.__server.setReadChannel(QProcess.StandardOutput)
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 ok, error = self.__readHello()
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 self.__started = ok
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 return ok, error
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 def stopServer(self):
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 """
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 Public method to stop the command server.
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 """
1550
0550f9915d65 Fixed an issue stopping the Mercurial commandline server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
100 if self.__server is not None:
0550f9915d65 Fixed an issue stopping the Mercurial commandline server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
101 self.__server.closeWriteChannel()
0550f9915d65 Fixed an issue stopping the Mercurial commandline server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
102 res = self.__server.waitForFinished(5000)
1244
ffdb35928247 Improved the Mercurial command server client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1242
diff changeset
103 if not res:
1550
0550f9915d65 Fixed an issue stopping the Mercurial commandline server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
104 self.__server.terminate()
0550f9915d65 Fixed an issue stopping the Mercurial commandline server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
105 res = self.__server.waitForFinished(3000)
0550f9915d65 Fixed an issue stopping the Mercurial commandline server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
106 if not res:
0550f9915d65 Fixed an issue stopping the Mercurial commandline server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
107 self.__server.kill()
0550f9915d65 Fixed an issue stopping the Mercurial commandline server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
108 self.__server.waitForFinished(3000)
0550f9915d65 Fixed an issue stopping the Mercurial commandline server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
109
0550f9915d65 Fixed an issue stopping the Mercurial commandline server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
110 self.__started = False
2318
3a3ee7cc2ad6 Changed some signal handlings (disconnect).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
111 self.__server.deleteLater()
1550
0550f9915d65 Fixed an issue stopping the Mercurial commandline server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
112 self.__server = None
1240
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 def restartServer(self):
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 """
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 Public method to restart the command server.
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 @return tuple of flag indicating a successful start (boolean) and
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
119 an error message (string) in case of failure
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 """
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 self.stopServer()
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 return self.startServer()
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
124 def __readHello(self):
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
125 """
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 Private method to read the hello message sent by the command server.
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
127
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128 @return tuple of flag indicating success (boolean) and an error message
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
129 in case of failure (string)
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
130 """
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
131 ch, msg = self.__readChannel()
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
132 if not ch:
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
133 return False, self.tr("Did not receive the 'hello' message.")
1240
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
134 elif ch != "o":
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
135 return False, self.tr("Received data on unexpected channel.")
1240
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
136
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
137 msg = msg.split("\n")
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
138
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
139 if not msg[0].startswith("capabilities: "):
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
140 return False, self.tr(
2962
d6c9d1ca2da4 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2816
diff changeset
141 "Bad 'hello' message, expected 'capabilities: '"
d6c9d1ca2da4 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2816
diff changeset
142 " but got '{0}'.").format(msg[0])
1240
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
143 self.__capabilities = msg[0][len('capabilities: '):]
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
144 if not self.__capabilities:
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
145 return False, self.tr("'capabilities' message did not contain"
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
146 " any capability.")
1240
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
147
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
148 self.__capabilities = set(self.__capabilities.split())
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
149 if "runcommand" not in self.__capabilities:
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
150 return False, "'capabilities' did not contain 'runcommand'."
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
151
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
152 if not msg[1].startswith("encoding: "):
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
153 return False, self.tr(
2962
d6c9d1ca2da4 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2816
diff changeset
154 "Bad 'hello' message, expected 'encoding: '"
d6c9d1ca2da4 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2816
diff changeset
155 " but got '{0}'.").format(msg[1])
1240
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
156 encoding = msg[1][len('encoding: '):]
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
157 if not encoding:
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
158 return False, self.tr("'encoding' message did not contain"
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
159 " any encoding.")
1240
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
160 self.__encoding = encoding
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
161
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
162 return True, ""
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
163
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
164 def __serverFinished(self, exitCode, exitStatus):
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
165 """
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
166 Private slot connected to the finished signal.
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
167
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
168 @param exitCode exit code of the process (integer)
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 @param exitStatus exit status of the process (QProcess.ExitStatus)
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 """
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 self.__started = False
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 def __readChannel(self):
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174 """
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
175 Private method to read data from the command server.
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
176
1244
ffdb35928247 Improved the Mercurial command server client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1242
diff changeset
177 @return tuple of channel designator and channel data
ffdb35928247 Improved the Mercurial command server client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1242
diff changeset
178 (string, integer or string or bytes)
1240
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
179 """
7257
c4d0cac9b5c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7192
diff changeset
180 if (
c4d0cac9b5c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7192
diff changeset
181 self.__server.bytesAvailable() > 0 or
c4d0cac9b5c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7192
diff changeset
182 self.__server.waitForReadyRead(10000)
c4d0cac9b5c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7192
diff changeset
183 ):
3518
1d681235c1b4 Fixed the Mercurial command server client handling large data chunks on slow machines.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3302
diff changeset
184 data = bytes(self.__server.peek(HgClient.OutputFormatSize))
1d681235c1b4 Fixed the Mercurial command server client handling large data chunks on slow machines.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3302
diff changeset
185 if not data or len(data) < HgClient.OutputFormatSize:
1240
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
186 return "", ""
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
187
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
188 channel, length = struct.unpack(HgClient.OutputFormat, data)
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
189 channel = channel.decode(self.__encoding)
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
190 if channel in "IL":
3518
1d681235c1b4 Fixed the Mercurial command server client handling large data chunks on slow machines.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3302
diff changeset
191 self.__server.read(HgClient.OutputFormatSize)
1240
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
192 return channel, length
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
193 else:
7257
c4d0cac9b5c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7192
diff changeset
194 if (
c4d0cac9b5c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7192
diff changeset
195 self.__server.bytesAvailable() <
c4d0cac9b5c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7192
diff changeset
196 HgClient.OutputFormatSize + length
c4d0cac9b5c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7192
diff changeset
197 ):
3518
1d681235c1b4 Fixed the Mercurial command server client handling large data chunks on slow machines.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3302
diff changeset
198 return "", ""
1d681235c1b4 Fixed the Mercurial command server client handling large data chunks on slow machines.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3302
diff changeset
199 self.__server.read(HgClient.OutputFormatSize)
1244
ffdb35928247 Improved the Mercurial command server client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1242
diff changeset
200 data = self.__server.read(length)
ffdb35928247 Improved the Mercurial command server client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1242
diff changeset
201 if channel == "r":
ffdb35928247 Improved the Mercurial command server client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1242
diff changeset
202 return (channel, data)
ffdb35928247 Improved the Mercurial command server client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1242
diff changeset
203 else:
ffdb35928247 Improved the Mercurial command server client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1242
diff changeset
204 return (channel, str(data, self.__encoding, "replace"))
1240
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
205 else:
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
206 return "", ""
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
207
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
208 def __writeDataBlock(self, data):
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
209 """
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
210 Private slot to write some data to the command server.
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
211
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
212 @param data data to be sent (string)
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
213 """
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
214 if not isinstance(data, bytes):
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
215 data = data.encode(self.__encoding)
2962
d6c9d1ca2da4 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2816
diff changeset
216 self.__server.write(
d6c9d1ca2da4 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2816
diff changeset
217 QByteArray(struct.pack(HgClient.InputFormat, len(data))))
1240
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
218 self.__server.write(QByteArray(data))
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
219 self.__server.waitForBytesWritten()
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
220
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
221 def __runcommand(self, args, inputChannels, outputChannels):
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
222 """
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
223 Private method to run a command in the server (low level).
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
224
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
225 @param args list of arguments for the command (list of string)
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
226 @param inputChannels dictionary of input channels. The dictionary must
2962
d6c9d1ca2da4 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2816
diff changeset
227 have the keys 'I' and 'L' and each entry must be a function
d6c9d1ca2da4 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2816
diff changeset
228 receiving the number of bytes to write.
d6c9d1ca2da4 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2816
diff changeset
229 @param outputChannels dictionary of output channels. The dictionary
d6c9d1ca2da4 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2816
diff changeset
230 must have the keys 'o' and 'e' and each entry must be a function
d6c9d1ca2da4 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2816
diff changeset
231 receiving the data.
d6c9d1ca2da4 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2816
diff changeset
232 @return result code of the command, -1 if the command server wasn't
d6c9d1ca2da4 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2816
diff changeset
233 started or -10, if the command was canceled (integer)
d6c9d1ca2da4 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2816
diff changeset
234 @exception RuntimeError raised to indicate an unexpected command
d6c9d1ca2da4 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2816
diff changeset
235 channel
1240
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
236 """
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
237 if not self.__started:
1247
a6bedc641fcd Fixed a bug in the Mercurial command server client causing it to return a wrong result code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1244
diff changeset
238 return -1
1240
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
239
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
240 self.__server.write(QByteArray(b'runcommand\n'))
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
241 self.__writeDataBlock('\0'.join(args))
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
242
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
243 while True:
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
244 QCoreApplication.processEvents()
1242
dfb9609caf51 Continued implementing an interface to the Mercurial command server. Modified client all all dialogs done so far to provide a cancel capability..
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1241
diff changeset
245
dfb9609caf51 Continued implementing an interface to the Mercurial command server. Modified client all all dialogs done so far to provide a cancel capability..
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1241
diff changeset
246 if self.__cancel:
1247
a6bedc641fcd Fixed a bug in the Mercurial command server client causing it to return a wrong result code.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1244
diff changeset
247 return -10
1242
dfb9609caf51 Continued implementing an interface to the Mercurial command server. Modified client all all dialogs done so far to provide a cancel capability..
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1241
diff changeset
248
1391
5acd6ee51956 A small refinement to the Mercurial command server interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1365
diff changeset
249 if self.__server is None:
5acd6ee51956 A small refinement to the Mercurial command server interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1365
diff changeset
250 return -1
5acd6ee51956 A small refinement to the Mercurial command server interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1365
diff changeset
251
1392
3c6c60c498a6 A small refinement to the Mercurial command server interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1391
diff changeset
252 if self.__server is None or self.__server.bytesAvailable() == 0:
1365
8f8cad8f989e Slight enhancement to the Mercurial command line server client to make it more CPU usage friendly.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1325
diff changeset
253 QThread.msleep(50)
1240
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
254 continue
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
255 channel, data = self.__readChannel()
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
256
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
257 # input channels
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
258 if channel in inputChannels:
1323
3126121aeb4f Added a prompt window for the Mercurial command server client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1266
diff changeset
259 if channel == "L":
5588
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
260 inputData, isPassword = inputChannels[channel](data)
1323
3126121aeb4f Added a prompt window for the Mercurial command server client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1266
diff changeset
261 # echo the input to the output if it was a prompt
4471
2dedc0c4a8fa Fixed an issue causing a password being entered in visible and shown in the output of the Mercurial command server client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
262 if not isPassword:
5588
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
263 outputChannels["o"](inputData)
4471
2dedc0c4a8fa Fixed an issue causing a password being entered in visible and shown in the output of the Mercurial command server client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
264 else:
5588
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
265 inputData = inputChannels[channel](data)
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
266 self.__writeDataBlock(inputData)
1240
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
267
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
268 # output channels
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
269 elif channel in outputChannels:
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
270 outputChannels[channel](data)
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
271
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
272 # result channel, command is finished
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
273 elif channel == "r":
1244
ffdb35928247 Improved the Mercurial command server client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1242
diff changeset
274 return struct.unpack(HgClient.ReturnFormat, data)[0]
1240
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
275
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
276 # unexpected but required channel
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
277 elif channel.isupper():
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
278 raise RuntimeError(
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
279 "Unexpected but required channel '{0}'.".format(channel))
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
280
3518
1d681235c1b4 Fixed the Mercurial command server client handling large data chunks on slow machines.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3302
diff changeset
281 # optional channels or no channel at all
1240
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
282 else:
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
283 pass
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
284
1323
3126121aeb4f Added a prompt window for the Mercurial command server client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1266
diff changeset
285 def __prompt(self, size, message):
3126121aeb4f Added a prompt window for the Mercurial command server client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1266
diff changeset
286 """
3126121aeb4f Added a prompt window for the Mercurial command server client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1266
diff changeset
287 Private method to prompt the user for some input.
3126121aeb4f Added a prompt window for the Mercurial command server client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1266
diff changeset
288
3126121aeb4f Added a prompt window for the Mercurial command server client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1266
diff changeset
289 @param size maximum length of the requested input (integer)
3126121aeb4f Added a prompt window for the Mercurial command server client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1266
diff changeset
290 @param message message sent by the server (string)
2962
d6c9d1ca2da4 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2816
diff changeset
291 @return data entered by the user (string)
1323
3126121aeb4f Added a prompt window for the Mercurial command server client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1266
diff changeset
292 """
2405
d4b5f3bd4720 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2318
diff changeset
293 from .HgClientPromptDialog import HgClientPromptDialog
5588
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
294 inputData = ""
4471
2dedc0c4a8fa Fixed an issue causing a password being entered in visible and shown in the output of the Mercurial command server client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
295 isPassword = False
1323
3126121aeb4f Added a prompt window for the Mercurial command server client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1266
diff changeset
296 dlg = HgClientPromptDialog(size, message)
3126121aeb4f Added a prompt window for the Mercurial command server client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1266
diff changeset
297 if dlg.exec_() == QDialog.Accepted:
5588
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
298 inputData = dlg.getInput() + '\n'
4471
2dedc0c4a8fa Fixed an issue causing a password being entered in visible and shown in the output of the Mercurial command server client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
299 isPassword = dlg.isPassword()
5588
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
300 return inputData, isPassword
1323
3126121aeb4f Added a prompt window for the Mercurial command server client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1266
diff changeset
301
5588
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
302 def runcommand(self, args, prompt=None, inputData=None, output=None,
2962
d6c9d1ca2da4 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2816
diff changeset
303 error=None):
1240
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
304 """
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
305 Public method to execute a command via the command server.
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
306
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
307 @param args list of arguments for the command (list of string)
1266
ce8a103501a5 Modified Mercurial command server client to allow for passing it output and/or error callbacks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1261
diff changeset
308 @keyparam prompt function to reply to prompts by the server. It
1240
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
309 receives the max number of bytes to return and the contents
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
310 of the output channel received so far.
5588
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
311 @keyparam inputData function to reply to bulk data requests by the
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
312 server. It receives the max number of bytes to return.
1266
ce8a103501a5 Modified Mercurial command server client to allow for passing it output and/or error callbacks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1261
diff changeset
313 @keyparam output function receiving the data from the server (string).
ce8a103501a5 Modified Mercurial command server client to allow for passing it output and/or error callbacks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1261
diff changeset
314 If a prompt function is given, this parameter will be ignored.
2962
d6c9d1ca2da4 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2816
diff changeset
315 @keyparam error function receiving error messages from the server
d6c9d1ca2da4 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2816
diff changeset
316 (string)
d6c9d1ca2da4 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2816
diff changeset
317 @return output and errors of the command server (string). In case
d6c9d1ca2da4 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2816
diff changeset
318 output and/or error functions were given, the respective return
d6c9d1ca2da4 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2816
diff changeset
319 value will be an empty string.
1240
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
320 """
7370
5fb53279f2df Mercurial: removed some old code dealing with using the hg commandline executable instead of the command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
321 if not self.__started:
5fb53279f2df Mercurial: removed some old code dealing with using the hg commandline executable instead of the command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
322 # try to start the Mercurial command server
5fb53279f2df Mercurial: removed some old code dealing with using the hg commandline executable instead of the command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
323 ok, startError = self.startServer()
5fb53279f2df Mercurial: removed some old code dealing with using the hg commandline executable instead of the command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
324 if not ok:
5fb53279f2df Mercurial: removed some old code dealing with using the hg commandline executable instead of the command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
325 return "", startError
5fb53279f2df Mercurial: removed some old code dealing with using the hg commandline executable instead of the command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7360
diff changeset
326
1256
885706dbb69f Refined the Mercurial command server interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1247
diff changeset
327 self.__commandRunning = True
1266
ce8a103501a5 Modified Mercurial command server client to allow for passing it output and/or error callbacks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1261
diff changeset
328 outputChannels = {}
ce8a103501a5 Modified Mercurial command server client to allow for passing it output and/or error callbacks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1261
diff changeset
329 outputBuffer = None
ce8a103501a5 Modified Mercurial command server client to allow for passing it output and/or error callbacks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1261
diff changeset
330 errorBuffer = None
1256
885706dbb69f Refined the Mercurial command server interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1247
diff changeset
331
1266
ce8a103501a5 Modified Mercurial command server client to allow for passing it output and/or error callbacks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1261
diff changeset
332 if prompt is not None or output is None:
ce8a103501a5 Modified Mercurial command server client to allow for passing it output and/or error callbacks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1261
diff changeset
333 outputBuffer = io.StringIO()
ce8a103501a5 Modified Mercurial command server client to allow for passing it output and/or error callbacks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1261
diff changeset
334 outputChannels["o"] = outputBuffer.write
ce8a103501a5 Modified Mercurial command server client to allow for passing it output and/or error callbacks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1261
diff changeset
335 else:
ce8a103501a5 Modified Mercurial command server client to allow for passing it output and/or error callbacks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1261
diff changeset
336 outputChannels["o"] = output
ce8a103501a5 Modified Mercurial command server client to allow for passing it output and/or error callbacks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1261
diff changeset
337 if error:
ce8a103501a5 Modified Mercurial command server client to allow for passing it output and/or error callbacks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1261
diff changeset
338 outputChannels["e"] = error
ce8a103501a5 Modified Mercurial command server client to allow for passing it output and/or error callbacks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1261
diff changeset
339 else:
ce8a103501a5 Modified Mercurial command server client to allow for passing it output and/or error callbacks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1261
diff changeset
340 errorBuffer = io.StringIO()
ce8a103501a5 Modified Mercurial command server client to allow for passing it output and/or error callbacks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1261
diff changeset
341 outputChannels["e"] = errorBuffer.write
1240
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
342
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
343 inputChannels = {}
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
344 if prompt is not None:
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
345 def func(size):
1266
ce8a103501a5 Modified Mercurial command server client to allow for passing it output and/or error callbacks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1261
diff changeset
346 reply = prompt(size, outputBuffer.getvalue())
4471
2dedc0c4a8fa Fixed an issue causing a password being entered in visible and shown in the output of the Mercurial command server client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
347 return reply, False
1240
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
348 inputChannels["L"] = func
1323
3126121aeb4f Added a prompt window for the Mercurial command server client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1266
diff changeset
349 else:
3126121aeb4f Added a prompt window for the Mercurial command server client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1266
diff changeset
350 def myprompt(size):
1935
df157512654c Fixed an issue in the Mercurial client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1550
diff changeset
351 if outputBuffer is None:
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
352 msg = self.tr("For message see output dialog.")
1935
df157512654c Fixed an issue in the Mercurial client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1550
diff changeset
353 else:
df157512654c Fixed an issue in the Mercurial client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1550
diff changeset
354 msg = outputBuffer.getvalue()
4471
2dedc0c4a8fa Fixed an issue causing a password being entered in visible and shown in the output of the Mercurial command server client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
355 reply, isPassword = self.__prompt(size, msg)
2dedc0c4a8fa Fixed an issue causing a password being entered in visible and shown in the output of the Mercurial command server client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 4021
diff changeset
356 return reply, isPassword
1323
3126121aeb4f Added a prompt window for the Mercurial command server client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1266
diff changeset
357 inputChannels["L"] = myprompt
5588
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
358 if inputData is not None:
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
359 inputChannels["I"] = inputData
1240
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
360
1242
dfb9609caf51 Continued implementing an interface to the Mercurial command server. Modified client all all dialogs done so far to provide a cancel capability..
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1241
diff changeset
361 self.__cancel = False
1240
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
362 self.__runcommand(args, inputChannels, outputChannels)
1266
ce8a103501a5 Modified Mercurial command server client to allow for passing it output and/or error callbacks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1261
diff changeset
363 if outputBuffer:
ce8a103501a5 Modified Mercurial command server client to allow for passing it output and/or error callbacks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1261
diff changeset
364 out = outputBuffer.getvalue()
ce8a103501a5 Modified Mercurial command server client to allow for passing it output and/or error callbacks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1261
diff changeset
365 else:
ce8a103501a5 Modified Mercurial command server client to allow for passing it output and/or error callbacks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1261
diff changeset
366 out = ""
ce8a103501a5 Modified Mercurial command server client to allow for passing it output and/or error callbacks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1261
diff changeset
367 if errorBuffer:
ce8a103501a5 Modified Mercurial command server client to allow for passing it output and/or error callbacks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1261
diff changeset
368 err = errorBuffer.getvalue()
ce8a103501a5 Modified Mercurial command server client to allow for passing it output and/or error callbacks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1261
diff changeset
369 else:
ce8a103501a5 Modified Mercurial command server client to allow for passing it output and/or error callbacks.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1261
diff changeset
370 err = ""
1240
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
371
1256
885706dbb69f Refined the Mercurial command server interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1247
diff changeset
372 self.__commandRunning = False
885706dbb69f Refined the Mercurial command server interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1247
diff changeset
373
1240
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
374 return out, err
1242
dfb9609caf51 Continued implementing an interface to the Mercurial command server. Modified client all all dialogs done so far to provide a cancel capability..
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1241
diff changeset
375
dfb9609caf51 Continued implementing an interface to the Mercurial command server. Modified client all all dialogs done so far to provide a cancel capability..
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1241
diff changeset
376 def cancel(self):
dfb9609caf51 Continued implementing an interface to the Mercurial command server. Modified client all all dialogs done so far to provide a cancel capability..
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1241
diff changeset
377 """
dfb9609caf51 Continued implementing an interface to the Mercurial command server. Modified client all all dialogs done so far to provide a cancel capability..
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1241
diff changeset
378 Public method to cancel the running command.
dfb9609caf51 Continued implementing an interface to the Mercurial command server. Modified client all all dialogs done so far to provide a cancel capability..
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1241
diff changeset
379 """
dfb9609caf51 Continued implementing an interface to the Mercurial command server. Modified client all all dialogs done so far to provide a cancel capability..
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1241
diff changeset
380 self.__cancel = True
1244
ffdb35928247 Improved the Mercurial command server client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1242
diff changeset
381 self.restartServer()
1256
885706dbb69f Refined the Mercurial command server interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1247
diff changeset
382
885706dbb69f Refined the Mercurial command server interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1247
diff changeset
383 def wasCanceled(self):
885706dbb69f Refined the Mercurial command server interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1247
diff changeset
384 """
885706dbb69f Refined the Mercurial command server interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1247
diff changeset
385 Public method to check, if the last command was canceled.
2962
d6c9d1ca2da4 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2816
diff changeset
386
d6c9d1ca2da4 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2816
diff changeset
387 @return flag indicating the cancel state (boolean)
1256
885706dbb69f Refined the Mercurial command server interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1247
diff changeset
388 """
885706dbb69f Refined the Mercurial command server interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1247
diff changeset
389 return self.__cancel
885706dbb69f Refined the Mercurial command server interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1247
diff changeset
390
885706dbb69f Refined the Mercurial command server interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1247
diff changeset
391 def isExecuting(self):
885706dbb69f Refined the Mercurial command server interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1247
diff changeset
392 """
885706dbb69f Refined the Mercurial command server interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1247
diff changeset
393 Public method to check, if the server is executing a command.
885706dbb69f Refined the Mercurial command server interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1247
diff changeset
394
885706dbb69f Refined the Mercurial command server interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1247
diff changeset
395 @return flag indicating the execution of a command (boolean)
885706dbb69f Refined the Mercurial command server interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1247
diff changeset
396 """
2962
d6c9d1ca2da4 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2816
diff changeset
397 return self.__commandRunning
4555
861e1741985c Adjustments to future imports for Python 2 compatibility.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 4543
diff changeset
398
861e1741985c Adjustments to future imports for Python 2 compatibility.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 4543
diff changeset
399 #
861e1741985c Adjustments to future imports for Python 2 compatibility.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 4543
diff changeset
400 # eflag: noqa = M702

eric ide

mercurial