|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2006 - 2022 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the VCS status monitor thread class for Subversion. |
|
8 """ |
|
9 |
|
10 import os |
|
11 |
|
12 import pysvn |
|
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 def _performMonitor(self): |
|
35 """ |
|
36 Protected method implementing the monitoring action. |
|
37 |
|
38 This method populates the statusList member variable |
|
39 with a list of strings giving the status in the first column and the |
|
40 path relative to the project directory starting with the third column. |
|
41 The allowed status flags are: |
|
42 <ul> |
|
43 <li>"A" path was added but not yet committed</li> |
|
44 <li>"M" path has local changes</li> |
|
45 <li>"O" path was removed</li> |
|
46 <li>"R" path was deleted and then re-added</li> |
|
47 <li>"U" path needs an update</li> |
|
48 <li>"Z" path contains a conflict</li> |
|
49 <li>"?" path is not tracked</li> |
|
50 <li>"!" path is missing</li> |
|
51 <li>" " path is back at normal</li> |
|
52 </ul> |
|
53 |
|
54 @return tuple of flag indicating successful operation (boolean) and |
|
55 a status message in case of non successful operation (string) |
|
56 """ |
|
57 self.shouldUpdate = False |
|
58 |
|
59 client = pysvn.Client() |
|
60 client.exception_style = 1 |
|
61 client.callback_get_login = self.__clientLoginCallback |
|
62 client.callback_ssl_server_trust_prompt = ( |
|
63 self.__clientSslServerTrustPromptCallback |
|
64 ) |
|
65 |
|
66 cwd = os.getcwd() |
|
67 os.chdir(self.projectDir) |
|
68 try: |
|
69 allFiles = client.status( |
|
70 '.', recurse=True, get_all=True, ignore=True, |
|
71 update=not Preferences.getVCS("MonitorLocalStatus")) |
|
72 states = {} |
|
73 for file in allFiles: |
|
74 uptodate = True |
|
75 if file.repos_text_status != pysvn.wc_status_kind.none: |
|
76 uptodate = ( |
|
77 uptodate and |
|
78 file.repos_text_status != pysvn.wc_status_kind.modified |
|
79 ) |
|
80 if file.repos_prop_status != pysvn.wc_status_kind.none: |
|
81 uptodate = ( |
|
82 uptodate and |
|
83 file.repos_prop_status != pysvn.wc_status_kind.modified |
|
84 ) |
|
85 |
|
86 status = "" |
|
87 if not uptodate: |
|
88 status = "U" |
|
89 self.shouldUpdate = True |
|
90 elif ( |
|
91 file.text_status == pysvn.wc_status_kind.conflicted or |
|
92 file.prop_status == pysvn.wc_status_kind.conflicted |
|
93 ): |
|
94 status = "Z" |
|
95 elif ( |
|
96 file.text_status == pysvn.wc_status_kind.deleted or |
|
97 file.prop_status == pysvn.wc_status_kind.deleted |
|
98 ): |
|
99 status = "O" |
|
100 elif ( |
|
101 file.text_status == pysvn.wc_status_kind.modified or |
|
102 file.prop_status == pysvn.wc_status_kind.modified |
|
103 ): |
|
104 status = "M" |
|
105 elif ( |
|
106 file.text_status == pysvn.wc_status_kind.added or |
|
107 file.prop_status == pysvn.wc_status_kind.added |
|
108 ): |
|
109 status = "A" |
|
110 elif ( |
|
111 file.text_status == pysvn.wc_status_kind.replaced or |
|
112 file.prop_status == pysvn.wc_status_kind.replaced |
|
113 ): |
|
114 status = "R" |
|
115 elif ( |
|
116 file.text_status == pysvn.wc_status_kind.unversioned or |
|
117 file.prop_status == pysvn.wc_status_kind.unversioned |
|
118 ): |
|
119 status = "?" |
|
120 elif ( |
|
121 file.text_status == pysvn.wc_status_kind.missing or |
|
122 file.prop_status == pysvn.wc_status_kind.missing |
|
123 ): |
|
124 status = "!" |
|
125 if status: |
|
126 states[file.path] = status |
|
127 try: |
|
128 if self.reportedStates[file.path] != status: |
|
129 self.statusList.append( |
|
130 "{0} {1}".format(status, file.path)) |
|
131 except KeyError: |
|
132 self.statusList.append( |
|
133 "{0} {1}".format(status, file.path)) |
|
134 for name in list(self.reportedStates.keys()): |
|
135 if name not in states: |
|
136 self.statusList.append(" {0}".format(name)) |
|
137 self.reportedStates = states |
|
138 res = True |
|
139 statusStr = self.tr( |
|
140 "Subversion status checked successfully (using pysvn)") |
|
141 except pysvn.ClientError as e: |
|
142 res = False |
|
143 statusStr = e.args[0] |
|
144 os.chdir(cwd) |
|
145 return res, statusStr |
|
146 |
|
147 def __clientLoginCallback(self, realm, username, may_save): |
|
148 """ |
|
149 Private method called by the client to get login information. |
|
150 |
|
151 @param realm name of the realm of the requested credentials (string) |
|
152 @param username username as supplied by subversion (string) |
|
153 @param may_save flag indicating, that subversion is willing to save |
|
154 the answers returned (boolean) |
|
155 @return tuple of four values (retcode, username, password, save). |
|
156 Retcode should be True, if username and password should be used |
|
157 by subversion, username and password contain the relevant data |
|
158 as strings and save is a flag indicating, that username and |
|
159 password should be saved. Always returns (False, "", "", False). |
|
160 """ |
|
161 return (False, "", "", False) |
|
162 |
|
163 def __clientSslServerTrustPromptCallback(self, trust_dict): |
|
164 """ |
|
165 Private method called by the client to request acceptance for a |
|
166 ssl server certificate. |
|
167 |
|
168 @param trust_dict dictionary containing the trust data |
|
169 @return tuple of three values (retcode, acceptedFailures, save). |
|
170 Retcode should be true, if the certificate should be accepted, |
|
171 acceptedFailures should indicate the accepted certificate failures |
|
172 and save should be True, if subversion should save the certificate. |
|
173 Always returns (False, 0, False). |
|
174 """ |
|
175 return (False, 0, False) |