Plugins/VcsPlugins/vcsMercurial/HgUtilities.py

changeset 5292
ac8b476ba122
parent 4631
5c1a96925da4
child 5293
26f1e696a2a5
equal deleted inserted replaced
5291:e93d14b48c34 5292:ac8b476ba122
8 """ 8 """
9 9
10 from __future__ import unicode_literals 10 from __future__ import unicode_literals
11 11
12 import os 12 import os
13 import re
13 14
14 from PyQt5.QtCore import QProcessEnvironment 15 from PyQt5.QtCore import QProcess, QProcessEnvironment, QCoreApplication
15 16
16 import Utilities 17 import Utilities
17 18
18 19
19 def getConfigPath(): 20 def getConfigPath():
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

eric ide

mercurial