eric6/Plugins/VcsPlugins/vcsSubversion/SvnStatusMonitorThread.py

changeset 6942
2602857055c5
parent 6645
ad476851d7e0
child 7192
a22eee00b052
equal deleted inserted replaced
6941:f99d60d6b59b 6942:2602857055c5
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2006 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the VCS status monitor thread class for Subversion.
8 """
9
10 from __future__ import unicode_literals
11 try:
12 str = unicode
13 except NameError:
14 pass
15
16 from PyQt5.QtCore import QRegExp, QProcess
17
18 from VCS.StatusMonitorThread import VcsStatusMonitorThread
19
20 import Preferences
21
22
23 class SvnStatusMonitorThread(VcsStatusMonitorThread):
24 """
25 Class implementing the VCS status monitor thread class for Subversion.
26 """
27 def __init__(self, interval, project, vcs, parent=None):
28 """
29 Constructor
30
31 @param interval new interval in seconds (integer)
32 @param project reference to the project object (Project)
33 @param vcs reference to the version control object
34 @param parent reference to the parent object (QObject)
35 """
36 VcsStatusMonitorThread.__init__(self, interval, project, vcs, parent)
37
38 self.__ioEncoding = Preferences.getSystem("IOEncoding")
39
40 self.rx_status1 = \
41 QRegExp('(.{8,9})\\s+([0-9-]+)\\s+(.+)\\s*')
42 self.rx_status2 = QRegExp(
43 '(.{8,9})\\s+([0-9-]+)\\s+([0-9?]+)\\s+(\\S+)\\s+(.+)\\s*')
44
45 def _performMonitor(self):
46 """
47 Protected method implementing the monitoring action.
48
49 This method populates the statusList member variable
50 with a list of strings giving the status in the first column and the
51 path relative to the project directory starting with the third column.
52 The allowed status flags are:
53 <ul>
54 <li>"A" path was added but not yet comitted</li>
55 <li>"M" path has local changes</li>
56 <li>"O" path was removed</li>
57 <li>"R" path was deleted and then re-added</li>
58 <li>"U" path needs an update</li>
59 <li>"Z" path contains a conflict</li>
60 <li>" " path is back at normal</li>
61 </ul>
62
63 @return tuple of flag indicating successful operation (boolean) and
64 a status message in case of non successful operation (string)
65 """
66 self.shouldUpdate = False
67
68 process = QProcess()
69 args = []
70 args.append('status')
71 if not Preferences.getVCS("MonitorLocalStatus"):
72 args.append('--show-updates')
73 args.append('--non-interactive')
74 args.append('.')
75 process.setWorkingDirectory(self.projectDir)
76 process.start('svn', args)
77 procStarted = process.waitForStarted(5000)
78 if procStarted:
79 finished = process.waitForFinished(300000)
80 if finished and process.exitCode() == 0:
81 output = str(process.readAllStandardOutput(),
82 self.__ioEncoding, 'replace')
83 states = {}
84 for line in output.splitlines():
85 if self.rx_status1.exactMatch(line):
86 flags = self.rx_status1.cap(1)
87 path = self.rx_status1.cap(3).strip()
88 elif self.rx_status2.exactMatch(line):
89 flags = self.rx_status2.cap(1)
90 path = self.rx_status2.cap(5).strip()
91 else:
92 continue
93 if flags[0] in "ACDMR" or \
94 (flags[0] == " " and flags[-1] == "*"):
95 if flags[-1] == "*":
96 status = "U"
97 else:
98 status = flags[0]
99 if status == "C":
100 status = "Z" # give it highest priority
101 elif status == "D":
102 status = "O"
103 if status == "U":
104 self.shouldUpdate = True
105 name = path
106 states[name] = status
107 try:
108 if self.reportedStates[name] != status:
109 self.statusList.append(
110 "{0} {1}".format(status, name))
111 except KeyError:
112 self.statusList.append(
113 "{0} {1}".format(status, name))
114 for name in list(self.reportedStates.keys()):
115 if name not in states:
116 self.statusList.append(" {0}".format(name))
117 self.reportedStates = states
118 return True, self.tr(
119 "Subversion status checked successfully (using svn)")
120 else:
121 process.kill()
122 process.waitForFinished()
123 return False, \
124 str(process.readAllStandardError(),
125 Preferences.getSystem("IOEncoding"),
126 'replace')
127 else:
128 process.kill()
129 process.waitForFinished()
130 return False, self.tr(
131 "Could not start the Subversion process.")

eric ide

mercurial