6 """ |
6 """ |
7 Module implementing an abstract base class to be subclassed by all specific |
7 Module implementing an abstract base class to be subclassed by all specific |
8 VCS interfaces. |
8 VCS interfaces. |
9 """ |
9 """ |
10 |
10 |
|
11 import contextlib |
|
12 import json |
11 import os |
13 import os |
12 import contextlib |
|
13 |
14 |
14 from PyQt6.QtCore import ( |
15 from PyQt6.QtCore import ( |
15 QObject, QThread, QMutex, QProcess, Qt, pyqtSignal, QCoreApplication |
16 QObject, QThread, QMutex, QProcess, Qt, pyqtSignal, QCoreApplication, |
|
17 QLockFile |
16 ) |
18 ) |
17 from PyQt6.QtWidgets import QApplication |
19 from PyQt6.QtWidgets import QApplication |
18 |
20 |
19 from EricWidgets import EricMessageBox |
21 from EricWidgets import EricMessageBox |
|
22 from EricWidgets.EricApplication import ericApp |
20 |
23 |
21 import Preferences |
24 import Preferences |
22 |
25 |
23 |
26 |
24 class VersionControl(QObject): |
27 class VersionControl(QObject): |
198 implemented by a subclass |
204 implemented by a subclass |
199 """ |
205 """ |
200 raise RuntimeError('Not implemented') |
206 raise RuntimeError('Not implemented') |
201 |
207 |
202 return False |
208 return False |
203 |
209 |
|
210 def vcsCommitMessages(self): |
|
211 """ |
|
212 Public method to get the list of saved commit messages. |
|
213 |
|
214 @return list of saved commit messages |
|
215 @rtype list of str |
|
216 @exception RuntimeError to indicate that this method must be |
|
217 implemented by a subclass |
|
218 """ |
|
219 raise RuntimeError('Not implemented') |
|
220 |
|
221 return [] |
|
222 |
|
223 def _vcsProjectCommitMessages(self): |
|
224 """ |
|
225 Protected method to get the list of saved commit messages. |
|
226 |
|
227 @return list of saved commit messages |
|
228 @rtype list of str |
|
229 """ |
|
230 messages = [] |
|
231 if Preferences.getVCS("PerProjectCommitHistory"): |
|
232 projectMgmtDir = ( |
|
233 ericApp().getObject("Project").getProjectManagementDir |
|
234 ) |
|
235 with contextlib.suppress(OSError, json.JSONDecodeError): |
|
236 with open(os.path.join(projectMgmtDir, |
|
237 VersionControl.commitHistoryData), |
|
238 "r") as f: |
|
239 jsonString = f.read() |
|
240 messages = json.loads(jsonString) |
|
241 |
|
242 return messages |
|
243 |
|
244 def vcsAddCommitMessage(self, message): |
|
245 """ |
|
246 Public method to add a commit message to the list of saved messages. |
|
247 |
|
248 @param message message to be added |
|
249 @type str |
|
250 @exception RuntimeError to indicate that this method must be |
|
251 implemented by a subclass |
|
252 """ |
|
253 raise RuntimeError('Not implemented') |
|
254 |
|
255 def _vcsAddProjectCommitMessage(self, message): |
|
256 """ |
|
257 Protected method to add a commit message to the list of project |
|
258 specific saved messages. |
|
259 |
|
260 @param message message to be added |
|
261 @type str |
|
262 @return flag indicating success |
|
263 @rtype bool |
|
264 """ |
|
265 if Preferences.getVCS("PerProjectCommitHistory"): |
|
266 projectMgmtDir = ( |
|
267 ericApp().getObject("Project").getProjectManagementDir |
|
268 ) |
|
269 lockFile = QLockFile( |
|
270 os.path.join(projectMgmtDir, VersionControl.commitHistoryLock)) |
|
271 if lockFile.lock(): |
|
272 noMessages = Preferences.getVCS("CommitMessages") |
|
273 messages = self.vcsCommitMessages() |
|
274 if message in messages: |
|
275 messages.remove(message) |
|
276 messages.insert(0, message) |
|
277 del messages[noMessages:] |
|
278 |
|
279 with contextlib.suppress(TypeError, OSError): |
|
280 jsonString = json.dumps(messages, indent=2) |
|
281 with open(os.path.join(projectMgmtDir, |
|
282 VersionControl.commitHistoryData), |
|
283 "w") as f: |
|
284 f.write(jsonString) |
|
285 lockFile.unlock() |
|
286 return True |
|
287 |
|
288 return False |
|
289 |
|
290 def vcsClearCommitMessages(self): |
|
291 """ |
|
292 Public method to clear the list of saved messages. |
|
293 |
|
294 @exception RuntimeError to indicate that this method must be |
|
295 implemented by a subclass |
|
296 """ |
|
297 raise RuntimeError('Not implemented') |
|
298 |
|
299 def _vcsClearProjectCommitMessages(self): |
|
300 """ |
|
301 Protected method to clear the list of project specific saved messages. |
|
302 |
|
303 @return flag indicating success |
|
304 @rtype bool |
|
305 """ |
|
306 if Preferences.getVCS("PerProjectCommitHistory"): |
|
307 projectMgmtDir = ( |
|
308 ericApp().getObject("Project").getProjectManagementDir |
|
309 ) |
|
310 lockFile = QLockFile( |
|
311 os.path.join(projectMgmtDir, VersionControl.commitHistoryLock)) |
|
312 if lockFile.lock(): |
|
313 with contextlib.suppress(TypeError, OSError): |
|
314 jsonString = json.dumps([], indent=2) |
|
315 with open(os.path.join(projectMgmtDir, |
|
316 VersionControl.commitHistoryData), |
|
317 "w") as f: |
|
318 f.write(jsonString) |
|
319 lockFile.unlock() |
|
320 return True |
|
321 |
|
322 return False |
|
323 |
204 def vcsUpdate(self, name, noDialog=False): |
324 def vcsUpdate(self, name, noDialog=False): |
205 """ |
325 """ |
206 Public method used to update a file/directory in the vcs. |
326 Public method used to update a file/directory in the vcs. |
207 |
327 |
208 @param name file/directory name to be updated (string) |
328 @param name file/directory name to be updated (string) |