27 @param parent reference to the parent object (QObject) |
24 @param parent reference to the parent object (QObject) |
28 """ |
25 """ |
29 VcsStatusMonitorThread.__init__(self, interval, project, vcs, parent) |
26 VcsStatusMonitorThread.__init__(self, interval, project, vcs, parent) |
30 |
27 |
31 self.__client = None |
28 self.__client = None |
32 self.__useCommandLine = False |
|
33 |
29 |
34 def _performMonitor(self): |
30 def _performMonitor(self): |
35 """ |
31 """ |
36 Protected method implementing the monitoring action. |
32 Protected method implementing the monitoring action. |
37 |
33 |
38 This method populates the statusList member variable |
34 This method populates the statusList member variable with a list of |
39 with a list of strings giving the status in the first column and the |
35 strings giving the status in the first column and the path relative |
40 path relative to the project directory starting with the third column. |
36 to the project directory starting with the third column. The allowed |
41 The allowed status flags are: |
37 status flags are: |
42 <ul> |
38 <ul> |
43 <li>"A" path was added but not yet comitted</li> |
39 <li>"A" path was added but not yet comitted</li> |
44 <li>"M" path has local changes</li> |
40 <li>"M" path has local changes</li> |
45 <li>"O" path was removed</li> |
41 <li>"O" path was removed</li> |
46 <li>"R" path was deleted and then re-added</li> |
42 <li>"R" path was deleted and then re-added</li> |
47 <li>"U" path needs an update</li> |
43 <li>"U" path needs an update</li> |
48 <li>"Z" path contains a conflict</li> |
44 <li>"Z" path contains a conflict</li> |
49 <li>" " path is back at normal</li> |
45 <li>" " path is back at normal</li> |
50 </ul> |
46 </ul> |
51 |
47 |
52 @return tuple of flag indicating successful operation (boolean) and |
48 @return tuple of flag indicating successful operation and a status |
53 a status message in case of non successful operation (string) |
49 message in case of non successful operation |
|
50 @rtype tuple of (bool, str) |
54 """ |
51 """ |
55 self.shouldUpdate = False |
52 self.shouldUpdate = False |
56 |
53 |
57 self.__initClient() |
54 ok, err = self.__initClient() |
|
55 if not ok: |
|
56 return False, err |
58 |
57 |
59 # step 1: get overall status |
58 # step 1: get overall status |
60 args = self.vcs.initCommand("status") |
59 args = self.vcs.initCommand("status") |
61 args.append('--noninteractive') |
60 args.append('--noninteractive') |
62 args.append('--all') |
61 args.append('--all') |
63 |
62 |
64 output = "" |
63 output, error = self.__client.runcommand(args) |
65 error = "" |
|
66 if self.__client: |
|
67 output, error = self.__client.runcommand(args) |
|
68 else: |
|
69 process = QProcess() |
|
70 process.setWorkingDirectory(self.projectDir) |
|
71 process.start('hg', args) |
|
72 procStarted = process.waitForStarted(5000) |
|
73 if procStarted: |
|
74 finished = process.waitForFinished(300000) |
|
75 if finished and process.exitCode() == 0: |
|
76 output = str(process.readAllStandardOutput(), |
|
77 self.vcs.getEncoding(), 'replace') |
|
78 else: |
|
79 process.kill() |
|
80 process.waitForFinished() |
|
81 error = str(process.readAllStandardError(), |
|
82 self.vcs.getEncoding(), 'replace') |
|
83 else: |
|
84 process.kill() |
|
85 process.waitForFinished() |
|
86 error = self.tr("Could not start the Mercurial process.") |
|
87 |
64 |
88 if error: |
65 if error: |
89 return False, error |
66 return False, error |
90 |
67 |
91 states = {} |
68 states = {} |
101 |
78 |
102 # step 2: get conflicting changes |
79 # step 2: get conflicting changes |
103 args = self.vcs.initCommand("resolve") |
80 args = self.vcs.initCommand("resolve") |
104 args.append('--list') |
81 args.append('--list') |
105 |
82 |
106 output = "" |
83 output, error = self.__client.runcommand(args) |
107 error = "" |
|
108 if self.__client: |
|
109 output, error = self.__client.runcommand(args) |
|
110 else: |
|
111 process.setWorkingDirectory(self.projectDir) |
|
112 process.start('hg', args) |
|
113 procStarted = process.waitForStarted(5000) |
|
114 if procStarted: |
|
115 finished = process.waitForFinished(300000) |
|
116 if finished and process.exitCode() == 0: |
|
117 output = str(process.readAllStandardOutput(), |
|
118 self.vcs.getEncoding(), 'replace') |
|
119 |
84 |
120 for line in output.splitlines(): |
85 for line in output.splitlines(): |
121 flag, name = line.split(" ", 1) |
86 flag, name = line.split(" ", 1) |
122 if flag == "U": |
87 if flag == "U": |
123 states[name] = "Z" # conflict |
88 states[name] = "Z" # conflict |
142 |
107 |
143 def _getInfo(self): |
108 def _getInfo(self): |
144 """ |
109 """ |
145 Protected method implementing the real info action. |
110 Protected method implementing the real info action. |
146 |
111 |
147 This method should be overridden and create a short info message to be |
|
148 shown in the main window status bar right next to the status indicator. |
|
149 |
|
150 @return short info message |
112 @return short info message |
151 @rtype str |
113 @rtype str |
152 """ |
114 """ |
153 self.__initClient() |
115 ok, err = self.__initClient() |
|
116 if not ok: |
|
117 return "" |
154 |
118 |
155 args = self.vcs.initCommand("identify") |
119 args = self.vcs.initCommand("identify") |
156 args.append('--num') |
120 args.append('--num') |
157 args.append('--id') |
121 args.append('--id') |
158 args.append('--branch') |
122 args.append('--branch') |
159 |
123 |
160 output = "" |
124 output, error = self.__client.runcommand(args) |
161 error = "" |
|
162 if self.__client: |
|
163 output, error = self.__client.runcommand(args) |
|
164 else: |
|
165 process = QProcess() |
|
166 process.setWorkingDirectory(self.projectDir) |
|
167 process.start('hg', args) |
|
168 procStarted = process.waitForStarted(5000) |
|
169 if procStarted: |
|
170 finished = process.waitForFinished(300000) |
|
171 if finished and process.exitCode() == 0: |
|
172 output = str(process.readAllStandardOutput(), |
|
173 self.vcs.getEncoding(), 'replace') |
|
174 else: |
|
175 process.kill() |
|
176 process.waitForFinished() |
|
177 error = str(process.readAllStandardError(), |
|
178 self.vcs.getEncoding(), 'replace') |
|
179 else: |
|
180 process.kill() |
|
181 process.waitForFinished() |
|
182 error = self.tr("Could not start the Mercurial process.") |
|
183 |
125 |
184 if error: |
126 if error: |
185 # ignore errors |
127 # ignore errors |
186 return "" |
128 return "" |
187 |
129 |
202 self.__client.stopServer() |
144 self.__client.stopServer() |
203 |
145 |
204 def __initClient(self): |
146 def __initClient(self): |
205 """ |
147 """ |
206 Private method to initialize the Mercurial client. |
148 Private method to initialize the Mercurial client. |
|
149 |
|
150 @return tuple containing an OK flag and potentially an error message |
|
151 @rtype tuple of (bool, str) |
207 """ |
152 """ |
208 if self.__client is None and not self.__useCommandLine: |
153 if self.__client is None: |
209 from .HgClient import HgClient |
154 from .HgClient import HgClient |
210 client = HgClient(self.projectDir, "utf-8", self.vcs) |
155 client = HgClient(self.projectDir, "utf-8", self.vcs) |
211 ok, err = client.startServer() |
156 ok, err = client.startServer() |
212 if ok: |
157 if ok: |
213 self.__client = client |
158 self.__client = client |
214 else: |
159 else: |
215 self.__useCommandLine = True |
160 ok = True |
|
161 err = "" |
|
162 |
|
163 return ok, err |