eric6/Plugins/VcsPlugins/vcsMercurial/HgStatusMonitorThread.py

Sat, 31 Aug 2019 12:58:11 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 31 Aug 2019 12:58:11 +0200
branch
without_py2_and_pyqt4
changeset 7192
a22eee00b052
parent 6970
cf9c2dc3f3cc
child 7229
53054eb5b15a
permissions
-rw-r--r--

Started removing runtime support for Python2 and PyQt4.

178
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
6645
ad476851d7e0 Updated copyright for 2019.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6529
diff changeset
3 # Copyright (c) 2010 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
178
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing the VCS status monitor thread class for Mercurial.
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
3145
a9de05d4a22f # __IGNORE_WARNING__ added/ removed.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3060
diff changeset
10 from __future__ import unicode_literals
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2405
diff changeset
11
3656
441956d8fce5 Started porting eric5 to PyQt5.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3555
diff changeset
12 from PyQt5.QtCore import QProcess
178
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 from VCS.StatusMonitorThread import VcsStatusMonitorThread
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
16
178
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 class HgStatusMonitorThread(VcsStatusMonitorThread):
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 """
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 Class implementing the VCS status monitor thread class for Mercurial.
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 """
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
21 def __init__(self, interval, project, vcs, parent=None):
178
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22 """
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 Constructor
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 @param interval new interval in seconds (integer)
248
f4561c24989a Changed code to better deal with project relative paths on Windows systems.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 216
diff changeset
26 @param project reference to the project object (Project)
178
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 @param vcs reference to the version control object
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 @param parent reference to the parent object (QObject)
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 """
248
f4561c24989a Changed code to better deal with project relative paths on Windows systems.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 216
diff changeset
30 VcsStatusMonitorThread.__init__(self, interval, project, vcs, parent)
178
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31
1255
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
32 self.__client = None
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
33 self.__useCommandLine = False
178
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 def _performMonitor(self):
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 """
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 Protected method implementing the monitoring action.
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 This method populates the statusList member variable
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 with a list of strings giving the status in the first column and the
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 path relative to the project directory starting with the third column.
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 The allowed status flags are:
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 <ul>
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 <li>"A" path was added but not yet comitted</li>
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 <li>"M" path has local changes</li>
216
6f9713e8d570 Added actions to identify the repo, to forget about files and added an additional status to be reported by the status monitor.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 197
diff changeset
46 <li>"O" path was removed</li>
178
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 <li>"R" path was deleted and then re-added</li>
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 <li>"U" path needs an update</li>
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 <li>"Z" path contains a conflict</li>
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 <li>" " path is back at normal</li>
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 </ul>
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
53 @return tuple of flag indicating successful operation (boolean) and
178
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 a status message in case of non successful operation (string)
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 """
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56 self.shouldUpdate = False
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57
6529
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
58 self.__initClient()
1255
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
59
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
60 # step 1: get overall status
3302
e92f0dd51979 Removed the Mercurial support for a command options dialog and added useable global options to the Mercurial config page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3190
diff changeset
61 args = self.vcs.initCommand("status")
178
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 args.append('--noninteractive')
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 args.append('--all')
1255
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
64
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
65 output = ""
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
66 error = ""
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
67 if self.__client:
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
68 output, error = self.__client.runcommand(args)
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
69 else:
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
70 process = QProcess()
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
71 process.setWorkingDirectory(self.projectDir)
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
72 process.start('hg', args)
2771
281c9b30dd91 Changed all QProcess.waitForStarted() calls to use a 5s timeout (except the debugger interfaces, which have a 10s timeout).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2405
diff changeset
73 procStarted = process.waitForStarted(5000)
1255
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
74 if procStarted:
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
75 finished = process.waitForFinished(300000)
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
76 if finished and process.exitCode() == 0:
3008
7848489bcb92 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2771
diff changeset
77 output = str(process.readAllStandardOutput(),
3302
e92f0dd51979 Removed the Mercurial support for a command options dialog and added useable global options to the Mercurial config page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3190
diff changeset
78 self.vcs.getEncoding(), 'replace')
1255
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
79 else:
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
80 process.kill()
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
81 process.waitForFinished()
3008
7848489bcb92 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2771
diff changeset
82 error = str(process.readAllStandardError(),
3302
e92f0dd51979 Removed the Mercurial support for a command options dialog and added useable global options to the Mercurial config page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3190
diff changeset
83 self.vcs.getEncoding(), 'replace')
178
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 else:
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 process.kill()
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 process.waitForFinished()
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
87 error = self.tr("Could not start the Mercurial process.")
1255
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
88
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
89 if error:
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
90 return False, error
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
91
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
92 states = {}
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
93 for line in output.splitlines():
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
94 if not line.startswith(" "):
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
95 flag, name = line.split(" ", 1)
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
96 if flag in "AMR":
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
97 if flag == "R":
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
98 status = "O"
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
99 else:
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
100 status = flag
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
101 states[name] = status
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
102
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
103 # step 2: get conflicting changes
3302
e92f0dd51979 Removed the Mercurial support for a command options dialog and added useable global options to the Mercurial config page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3190
diff changeset
104 args = self.vcs.initCommand("resolve")
1255
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
105 args.append('--list')
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
106
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
107 output = ""
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
108 error = ""
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
109 if self.__client:
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
110 output, error = self.__client.runcommand(args)
178
dd9f0bca5e2f Added plugin for Mercurial version control system.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 else:
1255
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
112 process.setWorkingDirectory(self.projectDir)
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
113 process.start('hg', args)
2771
281c9b30dd91 Changed all QProcess.waitForStarted() calls to use a 5s timeout (except the debugger interfaces, which have a 10s timeout).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2405
diff changeset
114 procStarted = process.waitForStarted(5000)
1255
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
115 if procStarted:
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
116 finished = process.waitForFinished(300000)
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
117 if finished and process.exitCode() == 0:
3302
e92f0dd51979 Removed the Mercurial support for a command options dialog and added useable global options to the Mercurial config page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3190
diff changeset
118 output = str(process.readAllStandardOutput(),
e92f0dd51979 Removed the Mercurial support for a command options dialog and added useable global options to the Mercurial config page.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3190
diff changeset
119 self.vcs.getEncoding(), 'replace')
1255
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
120
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
121 for line in output.splitlines():
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
122 flag, name = line.split(" ", 1)
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
123 if flag == "U":
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
124 states[name] = "Z" # conflict
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
125
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
126 # step 3: collect the status to be reported back
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
127 for name in states:
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
128 try:
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
129 if self.reportedStates[name] != states[name]:
3008
7848489bcb92 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2771
diff changeset
130 self.statusList.append(
7848489bcb92 Continued to shorten the code lines to max. 79 characters.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2771
diff changeset
131 "{0} {1}".format(states[name], name))
1255
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
132 except KeyError:
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
133 self.statusList.append("{0} {1}".format(states[name], name))
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
134 for name in self.reportedStates.keys():
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
135 if name not in states:
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
136 self.statusList.append(" {0}".format(name))
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
137 self.reportedStates = states
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
138
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
139 return True, \
3190
a9a94491c4fd Changed the code to use QObject.tr() instead of QObject.trUtf8().
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3160
diff changeset
140 self.tr("Mercurial status checked successfully")
1255
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
141
6529
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
142 def _getInfo(self):
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
143 """
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
144 Protected method implementing the real info action.
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
145
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
146 This method should be overridden and create a short info message to be
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
147 shown in the main window status bar right next to the status indicator.
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
148
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
149 @return short info message
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
150 @rtype str
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
151 """
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
152 self.__initClient()
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
153
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
154 args = self.vcs.initCommand("identify")
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
155 args.append('--num')
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
156 args.append('--id')
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
157 args.append('--branch')
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
158
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
159 output = ""
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
160 error = ""
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
161 if self.__client:
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
162 output, error = self.__client.runcommand(args)
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
163 else:
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
164 process = QProcess()
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
165 process.setWorkingDirectory(self.projectDir)
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
166 process.start('hg', args)
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
167 procStarted = process.waitForStarted(5000)
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
168 if procStarted:
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
169 finished = process.waitForFinished(300000)
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
170 if finished and process.exitCode() == 0:
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
171 output = str(process.readAllStandardOutput(),
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
172 self.vcs.getEncoding(), 'replace')
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
173 else:
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
174 process.kill()
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
175 process.waitForFinished()
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
176 error = str(process.readAllStandardError(),
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
177 self.vcs.getEncoding(), 'replace')
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
178 else:
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
179 process.kill()
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
180 process.waitForFinished()
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
181 error = self.tr("Could not start the Mercurial process.")
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
182
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
183 if error:
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
184 # ignore errors
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
185 return ""
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
186
6970
cf9c2dc3f3cc HgStatusMonitorThread: fixed an issue handling branches with spaces in their name.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6942
diff changeset
187 globalRev, localRev, branch = output.splitlines()[0].split(None, 2)
6529
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
188 if globalRev.endswith("+"):
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
189 globalRev = globalRev[:-1]
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
190 if localRev.endswith("+"):
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
191 localRev = localRev[:-1]
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
192
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
193 return self.tr("{0} / {1}:{2}", "branch, local id, global id").format(
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
194 branch, localRev, globalRev)
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
195
1255
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
196 def _shutdown(self):
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
197 """
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
198 Protected method performing shutdown actions.
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
199 """
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
200 if self.__client:
e1d8a8a4d40c Continued implementing an interface to the Mercurial command server.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 945
diff changeset
201 self.__client.stopServer()
6529
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
202
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
203 def __initClient(self):
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
204 """
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
205 Private method to initialize the Mercurial client.
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
206 """
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
207 if self.__client is None and not self.__useCommandLine:
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
208 from .HgClient import HgClient
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
209 client = HgClient(self.projectDir, "utf-8", self.vcs)
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
210 ok, err = client.startServer()
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
211 if ok:
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
212 self.__client = client
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
213 else:
1c2968f124b7 VCS: added capability to show some VCS info in the status bar of the main window (next to the status LED).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 6048
diff changeset
214 self.__useCommandLine = True

eric ide

mercurial