48 # set the language for the process |
49 # set the language for the process |
49 if language: |
50 if language: |
50 env.insert("LANGUAGE", language) |
51 env.insert("LANGUAGE", language) |
51 |
52 |
52 proc.setProcessEnvironment(env) |
53 proc.setProcessEnvironment(env) |
|
54 |
|
55 |
|
56 def hgVersion(plugin): |
|
57 """ |
|
58 Public method to determine the Mercurial version. |
|
59 |
|
60 @param plugin reference to the plugin object |
|
61 @type VcsMercurialPlugin |
|
62 @return tuple containing the Mercurial version as a string and as a tuple |
|
63 and an error message. |
|
64 @rtype tuple of str, tuple of int and str |
|
65 """ |
|
66 versionStr = "" |
|
67 version = () |
|
68 errorMsg = "" |
|
69 |
|
70 |
|
71 args = ["version"] |
|
72 args.extend(plugin.getGlobalOptions()) |
|
73 process = QProcess() |
|
74 process.start('hg', args) |
|
75 procStarted = process.waitForStarted(5000) |
|
76 if procStarted: |
|
77 finished = process.waitForFinished(30000) |
|
78 if finished and process.exitCode() == 0: |
|
79 output = str(process.readAllStandardOutput(), |
|
80 plugin.getPreferences("Encoding"), 'replace') |
|
81 versionStr = output.splitlines()[0].split()[-1][0:-1] |
|
82 v = list(re.match(r'.*?(\d+)\.(\d+)\.?(\d+)?(\+[0-9a-f-]+)?', |
|
83 versionStr).groups()) |
|
84 if v[-1] is None: |
|
85 del v[-1] |
|
86 for i in range(3): |
|
87 try: |
|
88 v[i] = int(v[i]) |
|
89 except TypeError: |
|
90 v[i] = 0 |
|
91 except IndexError: |
|
92 v.append(0) |
|
93 version = tuple(v) |
|
94 else: |
|
95 if finished: |
|
96 errorMsg = QCoreApplication.translate( |
|
97 "HgUtilities", |
|
98 "The hg process finished with the exit code {0}")\ |
|
99 .format(process.exitCode()) |
|
100 else: |
|
101 errorMsg = QCoreApplication.translate( |
|
102 "HgUtilities", |
|
103 "The hg process did not finish within 30s.") |
|
104 else: |
|
105 errorMsg = QCoreApplication.translate( |
|
106 "HgUtilities", |
|
107 "Could not start the hg executable.") |
|
108 |
|
109 return versionStr, version, errorMsg |