Plugins/VcsPlugins/vcsSubversion/SvnStatusMonitorThread.py

changeset 0
de9c2efb9d02
child 12
1d8dd9706f46
equal deleted inserted replaced
-1:000000000000 0:de9c2efb9d02
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2006 - 2009 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the VCS status monitor thread class for Subversion.
8 """
9
10 from PyQt4.QtCore import QRegExp, QProcess
11
12 from VCS.StatusMonitorThread import VcsStatusMonitorThread
13
14 import Preferences
15
16 class SvnStatusMonitorThread(VcsStatusMonitorThread):
17 """
18 Class implementing the VCS status monitor thread class for Subversion.
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 self.rx_status1 = \
34 QRegExp('(.{8})\\s+([0-9-]+)\\s+(.+)\\s*')
35 self.rx_status2 = \
36 QRegExp('(.{8})\\s+([0-9-]+)\\s+([0-9?]+)\\s+([\\w?]+)\\s+(.+)\\s*')
37
38 def _performMonitor(self):
39 """
40 Protected method implementing the monitoring action.
41
42 This method populates the statusList member variable
43 with a list of strings giving the status in the first column and the
44 path relative to the project directory starting with the third column.
45 The allowed status flags are:
46 <ul>
47 <li>"A" path was added but not yet comitted</li>
48 <li>"M" path has local changes</li>
49 <li>"R" path was deleted and then re-added</li>
50 <li>"U" path needs an update</li>
51 <li>"Z" path contains a conflict</li>
52 <li>" " path is back at normal</li>
53 </ul>
54
55 @return tuple of flag indicating successful operation (boolean) and
56 a status message in case of non successful operation (QString)
57 """
58 self.shouldUpdate = False
59
60 process = QProcess()
61 args = []
62 args.append('status')
63 if not Preferences.getVCS("MonitorLocalStatus"):
64 args.append('--show-updates')
65 args.append('--non-interactive')
66 args.append('.')
67 process.setWorkingDirectory(self.projectDir)
68 process.start('svn', args)
69 procStarted = process.waitForStarted()
70 if procStarted:
71 finished = process.waitForFinished(300000)
72 if finished and process.exitCode() == 0:
73 output = \
74 unicode(process.readAllStandardOutput(), self.__ioEncoding, 'replace')
75 states = {}
76 for line in output.splitlines():
77 if self.rx_status1.exactMatch(line):
78 flags = str(self.rx_status1.cap(1))
79 path = self.rx_status1.cap(3).strip()
80 elif self.rx_status2.exactMatch(line):
81 flags = str(self.rx_status2.cap(1))
82 path = self.rx_status2.cap(5).strip()
83 else:
84 continue
85 if flags[0] in "ACMR" or \
86 (flags[0] == " " and flags[7] == "*"):
87 if flags[7] == "*":
88 status = "U"
89 else:
90 status = flags[0]
91 if status == "C":
92 status = "Z" # give it highest priority
93 if status == "U":
94 self.shouldUpdate = True
95 name = path
96 states[name] = status
97 try:
98 if self.reportedStates[name] != status:
99 self.statusList.append("%s %s" % (status, name))
100 except KeyError:
101 self.statusList.append("%s %s" % (status, name))
102 for name in self.reportedStates.keys():
103 if name not in states:
104 self.statusList.append(" %s" % name)
105 self.reportedStates = states
106 return True, \
107 self.trUtf8("Subversion status checked successfully (using svn)")
108 else:
109 process.kill()
110 process.waitForFinished()
111 return False, unicode(process.readAllStandardError())
112 else:
113 process.kill()
114 process.waitForFinished()
115 return False, self.trUtf8("Could not start the Subversion process.")

eric ide

mercurial