src/eric7/Plugins/VcsPlugins/vcsMercurial/HgStatusMonitorThread.py

branch
eric7
changeset 9221
bf71ee032bb4
parent 9209
b99e7fd55fd3
child 9413
80c06d472826
equal deleted inserted replaced
9220:e9e7eca7efee 9221:bf71ee032bb4
12 12
13 class HgStatusMonitorThread(VcsStatusMonitorThread): 13 class HgStatusMonitorThread(VcsStatusMonitorThread):
14 """ 14 """
15 Class implementing the VCS status monitor thread class for Mercurial. 15 Class implementing the VCS status monitor thread class for Mercurial.
16 """ 16 """
17
17 def __init__(self, interval, project, vcs, parent=None): 18 def __init__(self, interval, project, vcs, parent=None):
18 """ 19 """
19 Constructor 20 Constructor
20 21
21 @param interval new interval in seconds (integer) 22 @param interval new interval in seconds (integer)
22 @param project reference to the project object (Project) 23 @param project reference to the project object (Project)
23 @param vcs reference to the version control object 24 @param vcs reference to the version control object
24 @param parent reference to the parent object (QObject) 25 @param parent reference to the parent object (QObject)
25 """ 26 """
26 VcsStatusMonitorThread.__init__(self, interval, project, vcs, parent) 27 VcsStatusMonitorThread.__init__(self, interval, project, vcs, parent)
27 28
28 self.__client = None 29 self.__client = None
29 30
30 def _performMonitor(self): 31 def _performMonitor(self):
31 """ 32 """
32 Protected method implementing the monitoring action. 33 Protected method implementing the monitoring action.
33 34
34 This method populates the statusList member variable with a list of 35 This method populates the statusList member variable with a list of
35 strings giving the status in the first column and the path relative 36 strings giving the status in the first column and the path relative
36 to the project directory starting with the third column. The allowed 37 to the project directory starting with the third column. The allowed
37 status flags are: 38 status flags are:
38 <ul> 39 <ul>
44 <li>"Z" path contains a conflict</li> 45 <li>"Z" path contains a conflict</li>
45 <li>"?" path is not tracked</li> 46 <li>"?" path is not tracked</li>
46 <li>"!" path is missing</li> 47 <li>"!" path is missing</li>
47 <li>" " path is back at normal</li> 48 <li>" " path is back at normal</li>
48 </ul> 49 </ul>
49 50
50 @return tuple of flag indicating successful operation and a status 51 @return tuple of flag indicating successful operation and a status
51 message in case of non successful operation 52 message in case of non successful operation
52 @rtype tuple of (bool, str) 53 @rtype tuple of (bool, str)
53 """ 54 """
54 self.shouldUpdate = False 55 self.shouldUpdate = False
55 56
56 ok, err = self.__initClient() 57 ok, err = self.__initClient()
57 if not ok: 58 if not ok:
58 return False, err 59 return False, err
59 60
60 # step 1: get overall status 61 # step 1: get overall status
61 args = self.vcs.initCommand("status") 62 args = self.vcs.initCommand("status")
62 args.append('--noninteractive') 63 args.append("--noninteractive")
63 args.append('--all') 64 args.append("--all")
64 if self.vcs.hasSubrepositories(): 65 if self.vcs.hasSubrepositories():
65 args.append("--subrepos") 66 args.append("--subrepos")
66 67
67 output, error = self.__client.runcommand(args) 68 output, error = self.__client.runcommand(args)
68 69
69 if error: 70 if error:
70 return False, error 71 return False, error
71 72
72 states = {} 73 states = {}
73 for line in output.splitlines(): 74 for line in output.splitlines():
74 if not line.startswith(" "): 75 if not line.startswith(" "):
75 flag, name = line.split(" ", 1) 76 flag, name = line.split(" ", 1)
76 if flag in "AMR?!": 77 if flag in "AMR?!":
77 if flag == "R": 78 if flag == "R":
78 status = "O" 79 status = "O"
79 else: 80 else:
80 status = flag 81 status = flag
81 states[name] = status 82 states[name] = status
82 83
83 # step 2: get conflicting changes 84 # step 2: get conflicting changes
84 args = self.vcs.initCommand("resolve") 85 args = self.vcs.initCommand("resolve")
85 args.append('--list') 86 args.append("--list")
86 87
87 output, error = self.__client.runcommand(args) 88 output, error = self.__client.runcommand(args)
88 89
89 for line in output.splitlines(): 90 for line in output.splitlines():
90 flag, name = line.split(" ", 1) 91 flag, name = line.split(" ", 1)
91 if flag == "U": 92 if flag == "U":
92 states[name] = "Z" # conflict 93 states[name] = "Z" # conflict
93 94
94 # step 3: collect the status to be reported back 95 # step 3: collect the status to be reported back
95 for name in states: 96 for name in states:
96 try: 97 try:
97 if self.reportedStates[name] != states[name]: 98 if self.reportedStates[name] != states[name]:
98 self.statusList.append( 99 self.statusList.append("{0} {1}".format(states[name], name))
99 "{0} {1}".format(states[name], name))
100 except KeyError: 100 except KeyError:
101 self.statusList.append("{0} {1}".format(states[name], name)) 101 self.statusList.append("{0} {1}".format(states[name], name))
102 for name in self.reportedStates: 102 for name in self.reportedStates:
103 if name not in states: 103 if name not in states:
104 self.statusList.append(" {0}".format(name)) 104 self.statusList.append(" {0}".format(name))
105 self.reportedStates = states 105 self.reportedStates = states
106 106
107 return ( 107 return (True, self.tr("Mercurial status checked successfully"))
108 True, 108
109 self.tr("Mercurial status checked successfully")
110 )
111
112 def _getInfo(self): 109 def _getInfo(self):
113 """ 110 """
114 Protected method implementing the real info action. 111 Protected method implementing the real info action.
115 112
116 @return short info message 113 @return short info message
117 @rtype str 114 @rtype str
118 """ 115 """
119 ok, err = self.__initClient() 116 ok, err = self.__initClient()
120 if not ok: 117 if not ok:
121 return "" 118 return ""
122 119
123 args = self.vcs.initCommand("identify") 120 args = self.vcs.initCommand("identify")
124 args.append('--num') 121 args.append("--num")
125 args.append('--id') 122 args.append("--id")
126 args.append('--branch') 123 args.append("--branch")
127 124
128 output, error = self.__client.runcommand(args) 125 output, error = self.__client.runcommand(args)
129 126
130 if error: 127 if error:
131 # ignore errors 128 # ignore errors
132 return "" 129 return ""
133 130
134 globalRev, localRev, branch = output.splitlines()[0].split(None, 2) 131 globalRev, localRev, branch = output.splitlines()[0].split(None, 2)
135 if globalRev.endswith("+"): 132 if globalRev.endswith("+"):
136 globalRev = globalRev[:-1] 133 globalRev = globalRev[:-1]
137 if localRev.endswith("+"): 134 if localRev.endswith("+"):
138 localRev = localRev[:-1] 135 localRev = localRev[:-1]
139 136
140 return self.tr("{0} / {1}:{2}", "branch, local id, global id").format( 137 return self.tr("{0} / {1}:{2}", "branch, local id, global id").format(
141 branch, localRev, globalRev) 138 branch, localRev, globalRev
142 139 )
140
143 def _shutdown(self): 141 def _shutdown(self):
144 """ 142 """
145 Protected method performing shutdown actions. 143 Protected method performing shutdown actions.
146 """ 144 """
147 if self.__client: 145 if self.__client:
148 self.__client.stopServer() 146 self.__client.stopServer()
149 147
150 def __initClient(self): 148 def __initClient(self):
151 """ 149 """
152 Private method to initialize the Mercurial client. 150 Private method to initialize the Mercurial client.
153 151
154 @return tuple containing an OK flag and potentially an error message 152 @return tuple containing an OK flag and potentially an error message
155 @rtype tuple of (bool, str) 153 @rtype tuple of (bool, str)
156 """ 154 """
157 if self.__client is None: 155 if self.__client is None:
158 from .HgClient import HgClient 156 from .HgClient import HgClient
157
159 client = HgClient(self.projectDir, "utf-8", self.vcs) 158 client = HgClient(self.projectDir, "utf-8", self.vcs)
160 ok, err = client.startServer() 159 ok, err = client.startServer()
161 if ok: 160 if ok:
162 self.__client = client 161 self.__client = client
163 else: 162 else:
164 ok = True 163 ok = True
165 err = "" 164 err = ""
166 165
167 return ok, err 166 return ok, err

eric ide

mercurial