Plugins/VcsPlugins/vcsMercurial/HgStatusMonitorThread.py

changeset 178
dd9f0bca5e2f
child 197
0e12ee787967
equal deleted inserted replaced
177:c822ccc4d138 178:dd9f0bca5e2f
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2010 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the VCS status monitor thread class for Mercurial.
8 """
9
10 from PyQt4.QtCore import QProcess
11
12 from VCS.StatusMonitorThread import VcsStatusMonitorThread
13
14 import Preferences
15
16 class HgStatusMonitorThread(VcsStatusMonitorThread):
17 """
18 Class implementing the VCS status monitor thread class for Mercurial.
19 """
20 def __init__(self, interval, projectDir, vcs, parent = None):
21 """
22 Constructor
23
24 @param interval new interval in seconds (integer)
25 @param projectDir project directory to monitor (string)
26 @param vcs reference to the version control object
27 @param parent reference to the parent object (QObject)
28 """
29 VcsStatusMonitorThread.__init__(self, interval, projectDir, vcs, parent)
30
31 self.__ioEncoding = Preferences.getSystem("IOEncoding")
32
33 def _performMonitor(self):
34 """
35 Protected method implementing the monitoring action.
36
37 This method populates the statusList member variable
38 with a list of strings giving the status in the first column and the
39 path relative to the project directory starting with the third column.
40 The allowed status flags are:
41 <ul>
42 <li>"A" path was added but not yet comitted</li>
43 <li>"M" path has local changes</li>
44 <li>"R" path was deleted and then re-added</li>
45 <li>"U" path needs an update</li>
46 <li>"Z" path contains a conflict</li>
47 <li>" " path is back at normal</li>
48 </ul>
49
50 @return tuple of flag indicating successful operation (boolean) and
51 a status message in case of non successful operation (string)
52 """
53 self.shouldUpdate = False
54
55 process = QProcess()
56 args = []
57 args.append('status')
58 args.append('--noninteractive')
59 args.append('--all')
60 ## args.append('.')
61 process.setWorkingDirectory(self.projectDir)
62 process.start('hg', args)
63 procStarted = process.waitForStarted()
64 if procStarted:
65 finished = process.waitForFinished(300000)
66 if finished and process.exitCode() == 0:
67 output = \
68 str(process.readAllStandardOutput(), self.__ioEncoding, 'replace')
69 states = {}
70 for line in output.splitlines():
71 if not line.startswith(" "):
72 flag, name = line.split(" ", 1)
73 if flag in "AM":
74 status = flag
75 states[name] = status
76
77 args = []
78 args.append('resolve')
79 args.append('--list')
80 process.setWorkingDirectory(self.projectDir)
81 process.start('hg', args)
82 procStarted = process.waitForStarted()
83 if procStarted:
84 finished = process.waitForFinished(300000)
85 if finished and process.exitCode() == 0:
86 output = str(
87 process.readAllStandardOutput(), self.__ioEncoding, 'replace')
88 for line in output.splitlines():
89 flag, name = line.split(" ", 1)
90 if flag == "U":
91 states[name] = "Z" # conflict
92
93 for name in states:
94 try:
95 if self.reportedStates[name] != states[name]:
96 self.statusList.append("%s %s" % (states[name], name))
97 except KeyError:
98 self.statusList.append("%s %s" % (states[name], name))
99 for name in self.reportedStates.keys():
100 if name not in states:
101 self.statusList.append(" %s" % name)
102 self.reportedStates = states
103 return True, \
104 self.trUtf8("Mercurial status checked successfully")
105 else:
106 process.kill()
107 process.waitForFinished()
108 return False, \
109 str(process.readAllStandardError(),
110 Preferences.getSystem("IOEncoding"),
111 'replace')
112 else:
113 process.kill()
114 process.waitForFinished()
115 return False, self.trUtf8("Could not start the Mercurial process.")

eric ide

mercurial