eric7/Plugins/VcsPlugins/vcsSubversion/SvnStatusMonitorThread.py

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

eric ide

mercurial