38 exe = os.path.join(dirName, "Scripts", program) |
38 exe = os.path.join(dirName, "Scripts", program) |
39 else: |
39 else: |
40 dirName = os.path.dirname(sys.executable) |
40 dirName = os.path.dirname(sys.executable) |
41 if os.path.exists(os.path.join(dirName, program)): |
41 if os.path.exists(os.path.join(dirName, program)): |
42 exe = os.path.join(dirName, program) |
42 exe = os.path.join(dirName, program) |
43 |
43 |
44 if not exe: |
44 if not exe: |
45 exe = program |
45 exe = program |
46 |
46 |
47 return exe |
47 return exe |
48 |
48 |
49 |
49 |
50 def getConfigPath(): |
50 def getConfigPath(): |
51 """ |
51 """ |
52 Function to get the filename of the config file. |
52 Function to get the filename of the config file. |
53 |
53 |
54 @return filename of the config file |
54 @return filename of the config file |
55 @rtype str |
55 @rtype str |
56 """ |
56 """ |
57 if Utilities.isWindowsPlatform(): |
57 if Utilities.isWindowsPlatform(): |
58 userprofile = os.environ["USERPROFILE"] |
58 userprofile = os.environ["USERPROFILE"] |
63 |
63 |
64 |
64 |
65 def prepareProcess(proc, encoding="", language=""): |
65 def prepareProcess(proc, encoding="", language=""): |
66 """ |
66 """ |
67 Function to prepare the given process. |
67 Function to prepare the given process. |
68 |
68 |
69 @param proc reference to the process to be prepared |
69 @param proc reference to the process to be prepared |
70 @type QProcess |
70 @type QProcess |
71 @param encoding encoding to be used by the process |
71 @param encoding encoding to be used by the process |
72 @type str |
72 @type str |
73 @param language language to be set |
73 @param language language to be set |
74 @type str |
74 @type str |
75 """ |
75 """ |
76 env = QProcessEnvironment.systemEnvironment() |
76 env = QProcessEnvironment.systemEnvironment() |
77 env.insert("HGPLAIN", '1') |
77 env.insert("HGPLAIN", "1") |
78 |
78 |
79 # set the encoding for the process |
79 # set the encoding for the process |
80 if encoding: |
80 if encoding: |
81 env.insert("HGENCODING", encoding) |
81 env.insert("HGENCODING", encoding) |
82 |
82 |
83 # set the language for the process |
83 # set the language for the process |
84 if language: |
84 if language: |
85 env.insert("LANGUAGE", language) |
85 env.insert("LANGUAGE", language) |
86 |
86 |
87 proc.setProcessEnvironment(env) |
87 proc.setProcessEnvironment(env) |
88 |
88 |
89 |
89 |
90 def hgVersion(plugin): |
90 def hgVersion(plugin): |
91 """ |
91 """ |
92 Public method to determine the Mercurial version. |
92 Public method to determine the Mercurial version. |
93 |
93 |
94 @param plugin reference to the plugin object |
94 @param plugin reference to the plugin object |
95 @type VcsMercurialPlugin |
95 @type VcsMercurialPlugin |
96 @return tuple containing the Mercurial version as a string and as a tuple |
96 @return tuple containing the Mercurial version as a string and as a tuple |
97 and an error message. |
97 and an error message. |
98 @rtype tuple of str, tuple of int and str |
98 @rtype tuple of str, tuple of int and str |
99 """ |
99 """ |
100 versionStr = "" |
100 versionStr = "" |
101 version = () |
101 version = () |
102 errorMsg = "" |
102 errorMsg = "" |
103 |
103 |
104 exe = getHgExecutable() |
104 exe = getHgExecutable() |
105 |
105 |
106 args = ["version"] |
106 args = ["version"] |
107 args.extend(plugin.getGlobalOptions()) |
107 args.extend(plugin.getGlobalOptions()) |
108 process = QProcess() |
108 process = QProcess() |
109 process.start(exe, args) |
109 process.start(exe, args) |
110 procStarted = process.waitForStarted(5000) |
110 procStarted = process.waitForStarted(5000) |
111 if procStarted: |
111 if procStarted: |
112 finished = process.waitForFinished(30000) |
112 finished = process.waitForFinished(30000) |
113 if finished and process.exitCode() == 0: |
113 if finished and process.exitCode() == 0: |
114 output = str(process.readAllStandardOutput(), |
114 output = str( |
115 plugin.getPreferences("Encoding"), 'replace') |
115 process.readAllStandardOutput(), |
|
116 plugin.getPreferences("Encoding"), |
|
117 "replace", |
|
118 ) |
116 versionStr = output.splitlines()[0].split()[-1][0:-1] |
119 versionStr = output.splitlines()[0].split()[-1][0:-1] |
117 v = list(re.match(r'.*?(\d+)\.(\d+)\.?(\d+)?(\+[0-9a-f-]+)?', |
120 v = list( |
118 versionStr).groups()) |
121 re.match( |
|
122 r".*?(\d+)\.(\d+)\.?(\d+)?(\+[0-9a-f-]+)?", versionStr |
|
123 ).groups() |
|
124 ) |
119 if v[-1] is None: |
125 if v[-1] is None: |
120 del v[-1] |
126 del v[-1] |
121 for i in range(3): |
127 for i in range(3): |
122 try: |
128 try: |
123 v[i] = int(v[i]) |
129 v[i] = int(v[i]) |
127 v.append(0) |
133 v.append(0) |
128 version = tuple(v) |
134 version = tuple(v) |
129 else: |
135 else: |
130 if finished: |
136 if finished: |
131 errorMsg = QCoreApplication.translate( |
137 errorMsg = QCoreApplication.translate( |
132 "HgUtilities", |
138 "HgUtilities", "The hg process finished with the exit code {0}" |
133 "The hg process finished with the exit code {0}" |
|
134 ).format(process.exitCode()) |
139 ).format(process.exitCode()) |
135 else: |
140 else: |
136 errorMsg = QCoreApplication.translate( |
141 errorMsg = QCoreApplication.translate( |
137 "HgUtilities", |
142 "HgUtilities", "The hg process did not finish within 30s." |
138 "The hg process did not finish within 30s.") |
143 ) |
139 else: |
144 else: |
140 errorMsg = QCoreApplication.translate( |
145 errorMsg = QCoreApplication.translate( |
141 "HgUtilities", |
146 "HgUtilities", "Could not start the hg executable." |
142 "Could not start the hg executable.") |
147 ) |
143 |
148 |
144 return versionStr, version, errorMsg |
149 return versionStr, version, errorMsg |