eric6/Plugins/VcsPlugins/vcsMercurial/HgUtilities.py

changeset 8288
809d5d5ac2ba
parent 7923
91e843545d9a
equal deleted inserted replaced
8287:30eb7bc13d63 8288:809d5d5ac2ba
7 Module implementing some common utility functions for the Mercurial package. 7 Module implementing some common utility functions for the Mercurial package.
8 """ 8 """
9 9
10 import os 10 import os
11 import re 11 import re
12 import sys
12 13
13 from PyQt5.QtCore import QProcess, QProcessEnvironment, QCoreApplication 14 from PyQt5.QtCore import QProcess, QProcessEnvironment, QCoreApplication
14 15
15 import Utilities 16 import Utilities
17 from Globals import isWindowsPlatform
18
19
20 def getHgExecutable():
21 """
22 Function to get the full path of the Mercurial executable.
23
24 @return path of the Mercurial executable
25 @rtype str
26 """
27 exe = ""
28 program = "hg"
29 if isWindowsPlatform():
30 program += ".exe"
31 dirName = os.path.dirname(sys.executable)
32 if os.path.exists(os.path.join(dirName, program)):
33 exe = os.path.join(dirName, program)
34 elif os.path.exists(os.path.join(dirName, "Scripts", program)):
35 exe = os.path.join(dirName, "Scripts", program)
36 else:
37 dirName = os.path.dirname(sys.executable)
38 if os.path.exists(os.path.join(dirName, program)):
39 exe = os.path.join(dirName, program)
40
41 if not exe:
42 exe = program
43
44 return exe
16 45
17 46
18 def getConfigPath(): 47 def getConfigPath():
19 """ 48 """
20 Public function to get the filename of the config file. 49 Function to get the filename of the config file.
21 50
22 @return filename of the config file (string) 51 @return filename of the config file
52 @rtype str
23 """ 53 """
24 if Utilities.isWindowsPlatform(): 54 if Utilities.isWindowsPlatform():
25 userprofile = os.environ["USERPROFILE"] 55 userprofile = os.environ["USERPROFILE"]
26 return os.path.join(userprofile, "Mercurial.ini") 56 return os.path.join(userprofile, "Mercurial.ini")
27 else: 57 else:
29 return os.path.join(homedir, ".hgrc") 59 return os.path.join(homedir, ".hgrc")
30 60
31 61
32 def prepareProcess(proc, encoding="", language=""): 62 def prepareProcess(proc, encoding="", language=""):
33 """ 63 """
34 Public function to prepare the given process. 64 Function to prepare the given process.
35 65
36 @param proc reference to the process to be prepared (QProcess) 66 @param proc reference to the process to be prepared
37 @param encoding encoding to be used by the process (string) 67 @type QProcess
38 @param language language to be set (string) 68 @param encoding encoding to be used by the process
69 @type str
70 @param language language to be set
71 @type str
39 """ 72 """
40 env = QProcessEnvironment.systemEnvironment() 73 env = QProcessEnvironment.systemEnvironment()
41 env.insert("HGPLAIN", '1') 74 env.insert("HGPLAIN", '1')
42 75
43 # set the encoding for the process 76 # set the encoding for the process
63 """ 96 """
64 versionStr = "" 97 versionStr = ""
65 version = () 98 version = ()
66 errorMsg = "" 99 errorMsg = ""
67 100
101 exe = getHgExecutable()
102
68 args = ["version"] 103 args = ["version"]
69 args.extend(plugin.getGlobalOptions()) 104 args.extend(plugin.getGlobalOptions())
70 process = QProcess() 105 process = QProcess()
71 process.start('hg', args) 106 process.start(exe, args)
72 procStarted = process.waitForStarted(5000) 107 procStarted = process.waitForStarted(5000)
73 if procStarted: 108 if procStarted:
74 finished = process.waitForFinished(30000) 109 finished = process.waitForFinished(30000)
75 if finished and process.exitCode() == 0: 110 if finished and process.exitCode() == 0:
76 output = str(process.readAllStandardOutput(), 111 output = str(process.readAllStandardOutput(),

eric ide

mercurial