eric7/Plugins/VcsPlugins/vcsGit/GitStatusMonitorThread.py

Sun, 16 May 2021 20:07:24 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 16 May 2021 20:07:24 +0200
branch
eric7
changeset 8318
962bce857696
parent 8312
800c432b34c8
child 8618
356a2f1b04b0
permissions
-rw-r--r--

Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.

6020
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
7923
91e843545d9a Updated copyright for 2021.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7780
diff changeset
3 # Copyright (c) 2014 - 2021 Detlev Offenbach <detlev@die-offenbachs.de>
6020
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module implementing the VCS status monitor thread class for Git.
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
8318
962bce857696 Replaced all imports of PyQt5 to PyQt6 and started to replace code using obsoleted methods and adapt to the PyQt6 enum usage.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 8312
diff changeset
10 from PyQt6.QtCore import QProcess
6020
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 from VCS.StatusMonitorThread import VcsStatusMonitorThread
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14 import Preferences
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 class GitStatusMonitorThread(VcsStatusMonitorThread):
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 """
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 Class implementing the VCS status monitor thread class for Git.
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 """
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 ConflictStates = ["AA", "AU", "DD", "DU", "UA", "UD", "UU"]
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 def __init__(self, interval, project, vcs, parent=None):
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 """
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 Constructor
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27 @param interval new interval in seconds (integer)
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 @param project reference to the project object (Project)
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29 @param vcs reference to the version control object
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 @param parent reference to the parent object (QObject)
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31 """
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 VcsStatusMonitorThread.__init__(self, interval, project, vcs, parent)
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 self.__ioEncoding = Preferences.getSystem("IOEncoding")
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 self.__client = None
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 self.__useCommandLine = False
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 def _performMonitor(self):
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 """
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 Protected method implementing the monitoring action.
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 This method populates the statusList member variable
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 with a list of strings giving the status in the first column and the
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 path relative to the project directory starting with the third column.
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
46 The allowed status flags are:
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
47 <ul>
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 <li>"A" path was added but not yet comitted</li>
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49 <li>"M" path has local changes</li>
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 <li>"O" path was removed</li>
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 <li>"R" path was deleted and then re-added</li>
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 <li>"U" path needs an update</li>
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 <li>"Z" path contains a conflict</li>
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 <li>" " path is back at normal</li>
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
55 </ul>
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
56
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
57 @return tuple of flag indicating successful operation (boolean) and
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58 a status message in case of non successful operation (string)
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 """
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60 self.shouldUpdate = False
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
61
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 # step 1: get overall status
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 args = self.vcs.initCommand("status")
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
64 args.append('--porcelain')
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 output = ""
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 error = ""
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 process = QProcess()
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
69 process.setWorkingDirectory(self.projectDir)
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
70 process.start('git', args)
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
71 procStarted = process.waitForStarted(5000)
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
72 if procStarted:
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
73 finished = process.waitForFinished(300000)
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74 if finished and process.exitCode() == 0:
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 output = str(process.readAllStandardOutput(),
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 self.__ioEncoding, 'replace')
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 else:
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 process.kill()
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 process.waitForFinished()
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 error = str(process.readAllStandardError(),
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 self.__ioEncoding, 'replace')
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 else:
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 process.kill()
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 process.waitForFinished()
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 error = self.tr("Could not start the Git process.")
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 if error:
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 return False, error
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 states = {}
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 for line in output.splitlines():
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 flags = line[:2]
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 name = line[3:].split(" -> ")[-1]
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 if flags in self.ConflictStates:
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 states[name] = "Z"
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 if flags[0] in "AMDR":
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 if flags[0] == "D":
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 status = "O"
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 elif flags[0] == "R":
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 status = "A"
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 else:
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
102 status = flags[0]
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
103 states[name] = status
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
104 elif flags[1] in "MD":
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
105 if flags[1] == "D":
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
106 status = "O"
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
107 else:
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
108 status = flags[1]
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
109 states[name] = status
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
110
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
111 # step 2: collect the status to be reported back
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
112 for name in states:
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
113 try:
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
114 if self.reportedStates[name] != states[name]:
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
115 self.statusList.append(
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
116 "{0} {1}".format(states[name], name))
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
117 except KeyError:
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
118 self.statusList.append("{0} {1}".format(states[name], name))
8205
4a0f1f896341 Applied some code simplifications suggested by the new Simplify checker.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7923
diff changeset
119 for name in self.reportedStates:
6020
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
120 if name not in states:
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
121 self.statusList.append(" {0}".format(name))
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
122 self.reportedStates = states
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
123
7257
c4d0cac9b5c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
124 return (
c4d0cac9b5c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
125 True,
6020
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
126 self.tr("Git status checked successfully")
7257
c4d0cac9b5c9 Continued to resolve code style issue M841.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 7229
diff changeset
127 )
6020
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
128
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
129 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
130 """
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
131 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
132
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
133 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
134 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
135
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
136 @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
137 @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
138 """
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
139 args = self.vcs.initCommand("show")
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
140 args.append("--abbrev-commit")
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
141 args.append("--format=%h %D")
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 args.append("--no-patch")
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 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
145 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
146 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
147 process.start('git', 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
148 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
149 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
150 finished = process.waitForFinished(30000)
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 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
152 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
153 Preferences.getSystem("IOEncoding"),
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 '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
155
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 if 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
157 commitId, refs = output.splitlines()[0].strip().split(None, 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
158 ref = refs.split(",", 1)[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
159 if "->" in ref:
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 branch = ref.split("->", 1)[1].strip()
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 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
162 branch = self.tr("<detached>")
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
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 return self.tr("{0} / {1}", "branch, commit").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
165 branch, commitId)
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 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
167 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
168
6020
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
169 def _shutdown(self):
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
170 """
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
171 Protected method performing shutdown actions.
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
172 """
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
173 if self.__client:
baf6da1ae288 Added the git plug-in to the core plug-ins.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
174 self.__client.stopServer()

eric ide

mercurial