eric6/Plugins/VcsPlugins/vcsMercurial/HgClient.py

Wed, 30 Dec 2020 11:00:44 +0100

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Wed, 30 Dec 2020 11:00:44 +0100
branch
maintenance
changeset 7924
8a96736d465e
parent 7759
51aa6c6b66f7
child 7979
54b73174ab61
permissions
-rw-r--r--

Updated copyright for 2021.

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
7924
8a96736d465e Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7759
diff changeset
3 # Copyright (c) 2011 - 2021 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
7441
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
36 @param repoPath root directory of the repository
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
37 @type str
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
38 @param encoding encoding to be used by the command server
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
39 @type str
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
40 @param vcs reference to the VCS object
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
41 @type Hg
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
42 @param parent reference to the parent object
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
43 @type QObject
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 """
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
45 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
46
1261
bb9ce68a0236 Change the Mercurial client to terminate more reliably.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1260
diff changeset
47 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
48 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
49 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
50 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
51 self.__cancel = False
1256
885706dbb69f Refined the Mercurial command server interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1247
diff changeset
52 self.__commandRunning = False
1261
bb9ce68a0236 Change the Mercurial client to terminate more reliably.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1260
diff changeset
53 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
54
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 # 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
56 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
57 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
58 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
59 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
60 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
61 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
62 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
63 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
64
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65 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
66 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
67 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
68 # 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
69 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
70 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
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 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
73 """
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 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
75
7441
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
76 @return tuple of flag indicating a successful start and an error
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
77 message in case of failure
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
78 @rtype tuple of (bool, str)
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
79 """
1261
bb9ce68a0236 Change the Mercurial client to terminate more reliably.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1260
diff changeset
80 self.__server = QProcess()
bb9ce68a0236 Change the Mercurial client to terminate more reliably.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1260
diff changeset
81 self.__server.setWorkingDirectory(self.__repoPath)
bb9ce68a0236 Change the Mercurial client to terminate more reliably.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1260
diff changeset
82
bb9ce68a0236 Change the Mercurial client to terminate more reliably.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1260
diff changeset
83 # connect signals
bb9ce68a0236 Change the Mercurial client to terminate more reliably.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1260
diff changeset
84 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
85
2816
05aab5164d64 A little optimization for the Mercurial interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2771
diff changeset
86 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
87
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
88 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
89 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
90 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
91 return False, self.tr(
3036
30c81c9e88b8 Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3008
diff changeset
92 'The process {0} could not be started. '
30c81c9e88b8 Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3008
diff changeset
93 '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
94 ).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
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 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
97 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
98 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
99 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
100
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 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
102 """
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 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
104 """
1550
0550f9915d65 Fixed an issue stopping the Mercurial commandline server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
105 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
106 self.__server.closeWriteChannel()
0550f9915d65 Fixed an issue stopping the Mercurial commandline server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
107 res = self.__server.waitForFinished(5000)
1244
ffdb35928247 Improved the Mercurial command server client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1242
diff changeset
108 if not res:
1550
0550f9915d65 Fixed an issue stopping the Mercurial commandline server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
109 self.__server.terminate()
0550f9915d65 Fixed an issue stopping the Mercurial commandline server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
110 res = self.__server.waitForFinished(3000)
0550f9915d65 Fixed an issue stopping the Mercurial commandline server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
111 if not res:
0550f9915d65 Fixed an issue stopping the Mercurial commandline server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
112 self.__server.kill()
0550f9915d65 Fixed an issue stopping the Mercurial commandline server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
113 self.__server.waitForFinished(3000)
0550f9915d65 Fixed an issue stopping the Mercurial commandline server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
114
0550f9915d65 Fixed an issue stopping the Mercurial commandline server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
115 self.__started = False
2318
3a3ee7cc2ad6 Changed some signal handlings (disconnect).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
116 self.__server.deleteLater()
1550
0550f9915d65 Fixed an issue stopping the Mercurial commandline server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1509
diff changeset
117 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
118
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 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
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 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
122
7441
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
123 @return tuple of flag indicating a successful start and an error
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
124 message in case of failure
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
125 @rtype tuple of (bool, str)
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
126 """
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 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
128 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
129
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 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
131 """
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 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
133
7441
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
134 @return tuple of flag indicating success and an error message in case
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
135 of failure
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
136 @rtype tuple of (bool, str)
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
137 """
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 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
139 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
140 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
141 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
142 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
143
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 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
145
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
146 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
147 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
148 "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
149 " 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
150 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
151 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
152 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
153 " 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
154
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
155 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
156 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
157 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
158
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
159 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
160 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
161 "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
162 " 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
163 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
164 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
165 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
166 " 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
167 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
168
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 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
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 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
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 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
174
7441
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
175 @param exitCode exit code of the process
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
176 @type int
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
177 @param exitStatus exit status of the process
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
178 @type QProcess.ExitStatus
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 """
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
180 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
181
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
182 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
183 """
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
184 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
185
1244
ffdb35928247 Improved the Mercurial command server client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1242
diff changeset
186 @return tuple of channel designator and channel data
7441
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
187 @rtype tuple of (str, int or str 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
188 """
7257
c4d0cac9b5c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7192
diff changeset
189 if (
c4d0cac9b5c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7192
diff changeset
190 self.__server.bytesAvailable() > 0 or
c4d0cac9b5c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7192
diff changeset
191 self.__server.waitForReadyRead(10000)
c4d0cac9b5c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7192
diff changeset
192 ):
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
193 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
194 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
195 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
196
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
197 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
198 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
199 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
200 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
201 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
202 else:
7257
c4d0cac9b5c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7192
diff changeset
203 if (
c4d0cac9b5c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7192
diff changeset
204 self.__server.bytesAvailable() <
c4d0cac9b5c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7192
diff changeset
205 HgClient.OutputFormatSize + length
c4d0cac9b5c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7192
diff changeset
206 ):
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
207 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
208 self.__server.read(HgClient.OutputFormatSize)
1244
ffdb35928247 Improved the Mercurial command server client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1242
diff changeset
209 data = self.__server.read(length)
ffdb35928247 Improved the Mercurial command server client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1242
diff changeset
210 if channel == "r":
ffdb35928247 Improved the Mercurial command server client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1242
diff changeset
211 return (channel, data)
ffdb35928247 Improved the Mercurial command server client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1242
diff changeset
212 else:
ffdb35928247 Improved the Mercurial command server client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1242
diff changeset
213 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
214 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
215 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
216
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
217 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
218 """
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 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
220
7441
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
221 @param data data to be sent
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
222 @type str
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
223 """
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 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
225 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
226 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
227 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
228 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
229 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
230
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
231 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
232 """
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
233 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
234
7441
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
235 @param args list of arguments for the command
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
236 @type list of str
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
237 @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
238 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
239 receiving the number of bytes to write.
7441
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
240 @type dict
2962
d6c9d1ca2da4 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2816
diff changeset
241 @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
242 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
243 receiving the data.
7441
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
244 @type dict
2962
d6c9d1ca2da4 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2816
diff changeset
245 @return result code of the command, -1 if the command server wasn't
7441
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
246 started or -10, if the command was canceled
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
247 @rtype int
2962
d6c9d1ca2da4 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2816
diff changeset
248 @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
249 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
250 """
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
251 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
252 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
253
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 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
255 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
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 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
258 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
259
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
260 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
261 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
262
1391
5acd6ee51956 A small refinement to the Mercurial command server interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1365
diff changeset
263 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
264 return -1
5acd6ee51956 A small refinement to the Mercurial command server interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1365
diff changeset
265
1392
3c6c60c498a6 A small refinement to the Mercurial command server interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1391
diff changeset
266 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
267 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
268 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
269 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
270
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 # 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
272 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
273 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
274 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
275 # 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
276 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
277 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
278 else:
5588
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
279 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
280 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
281
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 # 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
283 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
284 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
285
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
286 # 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
287 elif channel == "r":
1244
ffdb35928247 Improved the Mercurial command server client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1242
diff changeset
288 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
289
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
290 # 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
291 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
292 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
293 "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
294
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
295 # 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
296 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
297 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
298
1323
3126121aeb4f Added a prompt window for the Mercurial command server client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1266
diff changeset
299 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
300 """
3126121aeb4f Added a prompt window for the Mercurial command server client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1266
diff changeset
301 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
302
7441
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
303 @param size maximum length of the requested input
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
304 @type int
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
305 @param message message sent by the server
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
306 @type str
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
307 @return tuple containing data entered by the user and
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
308 a flag indicating a password input
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
309 @rtype tuple of (str, bool)
1323
3126121aeb4f Added a prompt window for the Mercurial command server client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1266
diff changeset
310 """
2405
d4b5f3bd4720 Continued implementing the delayed import.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2318
diff changeset
311 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
312 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
313 isPassword = False
1323
3126121aeb4f Added a prompt window for the Mercurial command server client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1266
diff changeset
314 dlg = HgClientPromptDialog(size, message)
7759
51aa6c6b66f7 Changed calls to exec_() into exec() (remainder of Python2 elimination).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7639
diff changeset
315 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
316 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
317 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
318 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
319
5588
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
320 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
321 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
322 """
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
323 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
324
7441
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
325 @param args list of arguments for the command
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
326 @type list of str
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
327 @param 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
328 receives the max number of bytes to return and the contents
7441
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
329 of the output channel received so far. If an output function is
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
330 given as well, the prompt data is passed through the output
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
331 function. The function must return the input data and a flag
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
332 indicating a password input.
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
333 @type func(int, str) -> (str, bool)
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
334 @param inputData function to reply to bulk data requests by the
5588
6ba512d9f46a Continued fixing code style issues detected by the extended style checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 5587
diff changeset
335 server. It receives the max number of bytes to return.
7441
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
336 @type func(int) -> bytes
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
337 @param output function receiving the data from the server. If a
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
338 prompt function is given, it is assumed, that the prompt output
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
339 is passed via this function.
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
340 @type func(str)
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
341 @param error function receiving error messages from the server
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
342 @type func(str)
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
343 @return tuple of output and errors of the command server. In case
2962
d6c9d1ca2da4 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2816
diff changeset
344 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
345 value will be an empty string.
7441
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
346 @rtype tuple of (str, str)
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
347 """
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
348 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
349 # 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
350 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
351 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
352 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
353
1256
885706dbb69f Refined the Mercurial command server interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1247
diff changeset
354 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
355 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
356 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
357 errorBuffer = None
1256
885706dbb69f Refined the Mercurial command server interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1247
diff changeset
358
7441
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
359 if output is None:
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
360 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
361 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
362 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
363 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
364 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
365 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
366 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
367 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
368 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
369
4d5fc346bd3b Started implementing an interface to the Mercurial command server (as of Mercurial >= 1.9).
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
370 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
371 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
372 def func(size):
7441
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
373 if outputBuffer is None:
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
374 msg = ""
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
375 else:
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
376 msg = outputBuffer.getvalue()
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
377 reply, isPassword = prompt(size, msg)
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
378 return reply, isPassword
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
379 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
380 else:
3126121aeb4f Added a prompt window for the Mercurial command server client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1266
diff changeset
381 def myprompt(size):
1935
df157512654c Fixed an issue in the Mercurial client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1550
diff changeset
382 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
383 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
384 else:
df157512654c Fixed an issue in the Mercurial client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1550
diff changeset
385 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
386 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
387 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
388 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
389 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
390 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
391
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
392 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
393 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
394 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
395 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
396 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
397 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
398 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
399 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
400 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
401 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
402
1256
885706dbb69f Refined the Mercurial command server interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1247
diff changeset
403 self.__commandRunning = False
885706dbb69f Refined the Mercurial command server interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1247
diff changeset
404
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
405 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
406
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
407 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
408 """
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
409 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
410 """
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
411 self.__cancel = True
1244
ffdb35928247 Improved the Mercurial command server client.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1242
diff changeset
412 self.restartServer()
1256
885706dbb69f Refined the Mercurial command server interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1247
diff changeset
413
885706dbb69f Refined the Mercurial command server interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1247
diff changeset
414 def wasCanceled(self):
885706dbb69f Refined the Mercurial command server interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1247
diff changeset
415 """
885706dbb69f Refined the Mercurial command server interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1247
diff changeset
416 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
417
7441
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
418 @return flag indicating the cancel state
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
419 @rtype bool
1256
885706dbb69f Refined the Mercurial command server interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1247
diff changeset
420 """
885706dbb69f Refined the Mercurial command server interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1247
diff changeset
421 return self.__cancel
885706dbb69f Refined the Mercurial command server interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1247
diff changeset
422
885706dbb69f Refined the Mercurial command server interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1247
diff changeset
423 def isExecuting(self):
885706dbb69f Refined the Mercurial command server interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1247
diff changeset
424 """
885706dbb69f Refined the Mercurial command server interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1247
diff changeset
425 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
426
7441
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
427 @return flag indicating the execution of a command
f115f4469795 HgDialog: extended the dialog to allow inputting user responses to client prompts.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7399
diff changeset
428 @rtype bool
1256
885706dbb69f Refined the Mercurial command server interface.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 1247
diff changeset
429 """
2962
d6c9d1ca2da4 Continued correcting doc strings by using the new doc string checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2816
diff changeset
430 return self.__commandRunning

eric ide

mercurial