11 import re |
11 import re |
12 |
12 |
13 from PyQt6.QtCore import QCoreApplication, QProcess, QProcessEnvironment |
13 from PyQt6.QtCore import QCoreApplication, QProcess, QProcessEnvironment |
14 |
14 |
15 from eric7.SystemUtilities import OSUtilities, PythonUtilities |
15 from eric7.SystemUtilities import OSUtilities, PythonUtilities |
|
16 |
|
17 # progress bar topic, bar (ignored), value, maximum, estimate |
|
18 progressRe = re.compile(r"(\w+)\s+(?:\[[=> ]*\])\s+(\d+)/(\d+)\s+(\w+)") |
|
19 |
|
20 # version major, minor, patch, additional |
|
21 versionRe = re.compile(r".*?(\d+)\.(\d+)\.?(\d+)?(\+[0-9a-f-]+)?") |
16 |
22 |
17 |
23 |
18 def getHgExecutable(): |
24 def getHgExecutable(): |
19 """ |
25 """ |
20 Function to get the full path of the Mercurial executable. |
26 Function to get the full path of the Mercurial executable. |
65 @type str |
71 @type str |
66 @param language language to be set |
72 @param language language to be set |
67 @type str |
73 @type str |
68 """ |
74 """ |
69 env = QProcessEnvironment.systemEnvironment() |
75 env = QProcessEnvironment.systemEnvironment() |
70 env.insert("HGPLAIN", "1") |
76 env.insert("HGPLAINEXCEPT", "progress") |
71 |
77 |
72 # set the encoding for the process |
78 # set the encoding for the process |
73 if encoding: |
79 if encoding: |
74 env.insert("HGENCODING", encoding) |
80 env.insert("HGENCODING", encoding) |
75 |
81 |
108 process.readAllStandardOutput(), |
114 process.readAllStandardOutput(), |
109 plugin.getPreferences("Encoding"), |
115 plugin.getPreferences("Encoding"), |
110 "replace", |
116 "replace", |
111 ) |
117 ) |
112 versionStr = output.splitlines()[0].split()[-1][0:-1] |
118 versionStr = output.splitlines()[0].split()[-1][0:-1] |
113 v = list( |
119 v = list(versionRe.match(versionStr).groups()) |
114 re.match( |
|
115 r".*?(\d+)\.(\d+)\.?(\d+)?(\+[0-9a-f-]+)?", versionStr |
|
116 ).groups() |
|
117 ) |
|
118 if v[-1] is None: |
120 if v[-1] is None: |
119 del v[-1] |
121 del v[-1] |
120 for i in range(3): |
122 for i in range(3): |
121 try: |
123 try: |
122 v[i] = int(v[i]) |
124 v[i] = int(v[i]) |
138 errorMsg = QCoreApplication.translate( |
140 errorMsg = QCoreApplication.translate( |
139 "HgUtilities", "Could not start the hg executable." |
141 "HgUtilities", "Could not start the hg executable." |
140 ) |
142 ) |
141 |
143 |
142 return versionStr, version, errorMsg |
144 return versionStr, version, errorMsg |
|
145 |
|
146 |
|
147 def isProgressInfo(line): |
|
148 """ |
|
149 Function to check, if the given line contains progress information. |
|
150 |
|
151 @param line output line to be checked |
|
152 @type str |
|
153 @return flag indicating a line containing progress information |
|
154 @rtype bool |
|
155 """ |
|
156 return progressRe.match(line.strip()) is not None |
|
157 |
|
158 |
|
159 def parseProgressInfo(progressLine): |
|
160 """ |
|
161 Function to parse an output line containing progress information. |
|
162 |
|
163 @param progressLine progress information line to be parsed |
|
164 @type str |
|
165 @return tuple containing the progress topic, current value, maximum value and |
|
166 the completion estimate |
|
167 @rtype tuple of (str, int, int, str) |
|
168 """ |
|
169 match = progressRe.match(progressLine) |
|
170 if match is not None: |
|
171 return ( |
|
172 match[1], # topic |
|
173 int(match[2]), # value |
|
174 int(match[3]), # maximum |
|
175 match[4], # estimate |
|
176 ) |
|
177 else: |
|
178 return "", 0, 0, "" |