|
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 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 comitted</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 back at normal</li> |
|
50 </ul> |
|
51 |
|
52 @return tuple of flag indicating successful operation (boolean) and |
|
53 a status message in case of non successful operation (string) |
|
54 """ |
|
55 self.shouldUpdate = False |
|
56 |
|
57 client = pysvn.Client() |
|
58 client.exception_style = 1 |
|
59 client.callback_get_login = self.__clientLoginCallback |
|
60 client.callback_ssl_server_trust_prompt = ( |
|
61 self.__clientSslServerTrustPromptCallback |
|
62 ) |
|
63 |
|
64 cwd = os.getcwd() |
|
65 os.chdir(self.projectDir) |
|
66 try: |
|
67 allFiles = client.status( |
|
68 '.', recurse=True, get_all=True, ignore=True, |
|
69 update=not Preferences.getVCS("MonitorLocalStatus")) |
|
70 states = {} |
|
71 for file in allFiles: |
|
72 uptodate = True |
|
73 if file.repos_text_status != pysvn.wc_status_kind.none: |
|
74 uptodate = ( |
|
75 uptodate and |
|
76 file.repos_text_status != pysvn.wc_status_kind.modified |
|
77 ) |
|
78 if file.repos_prop_status != pysvn.wc_status_kind.none: |
|
79 uptodate = ( |
|
80 uptodate and |
|
81 file.repos_prop_status != pysvn.wc_status_kind.modified |
|
82 ) |
|
83 |
|
84 status = "" |
|
85 if not uptodate: |
|
86 status = "U" |
|
87 self.shouldUpdate = True |
|
88 elif ( |
|
89 file.text_status == pysvn.wc_status_kind.conflicted or |
|
90 file.prop_status == pysvn.wc_status_kind.conflicted |
|
91 ): |
|
92 status = "Z" |
|
93 elif ( |
|
94 file.text_status == pysvn.wc_status_kind.deleted or |
|
95 file.prop_status == pysvn.wc_status_kind.deleted |
|
96 ): |
|
97 status = "O" |
|
98 elif ( |
|
99 file.text_status == pysvn.wc_status_kind.modified or |
|
100 file.prop_status == pysvn.wc_status_kind.modified |
|
101 ): |
|
102 status = "M" |
|
103 elif ( |
|
104 file.text_status == pysvn.wc_status_kind.added or |
|
105 file.prop_status == pysvn.wc_status_kind.added |
|
106 ): |
|
107 status = "A" |
|
108 elif ( |
|
109 file.text_status == pysvn.wc_status_kind.replaced or |
|
110 file.prop_status == pysvn.wc_status_kind.replaced |
|
111 ): |
|
112 status = "R" |
|
113 if status: |
|
114 states[file.path] = status |
|
115 try: |
|
116 if self.reportedStates[file.path] != status: |
|
117 self.statusList.append( |
|
118 "{0} {1}".format(status, file.path)) |
|
119 except KeyError: |
|
120 self.statusList.append( |
|
121 "{0} {1}".format(status, file.path)) |
|
122 for name in list(self.reportedStates.keys()): |
|
123 if name not in states: |
|
124 self.statusList.append(" {0}".format(name)) |
|
125 self.reportedStates = states |
|
126 res = True |
|
127 statusStr = self.tr( |
|
128 "Subversion status checked successfully (using pysvn)") |
|
129 except pysvn.ClientError as e: |
|
130 res = False |
|
131 statusStr = e.args[0] |
|
132 os.chdir(cwd) |
|
133 return res, statusStr |
|
134 |
|
135 def __clientLoginCallback(self, realm, username, may_save): |
|
136 """ |
|
137 Private method called by the client to get login information. |
|
138 |
|
139 @param realm name of the realm of the requested credentials (string) |
|
140 @param username username as supplied by subversion (string) |
|
141 @param may_save flag indicating, that subversion is willing to save |
|
142 the answers returned (boolean) |
|
143 @return tuple of four values (retcode, username, password, save). |
|
144 Retcode should be True, if username and password should be used |
|
145 by subversion, username and password contain the relevant data |
|
146 as strings and save is a flag indicating, that username and |
|
147 password should be saved. Always returns (False, "", "", False). |
|
148 """ |
|
149 return (False, "", "", False) |
|
150 |
|
151 def __clientSslServerTrustPromptCallback(self, trust_dict): |
|
152 """ |
|
153 Private method called by the client to request acceptance for a |
|
154 ssl server certificate. |
|
155 |
|
156 @param trust_dict dictionary containing the trust data |
|
157 @return tuple of three values (retcode, acceptedFailures, save). |
|
158 Retcode should be true, if the certificate should be accepted, |
|
159 acceptedFailures should indicate the accepted certificate failures |
|
160 and save should be True, if subversion should save the certificate. |
|
161 Always returns (False, 0, False). |
|
162 """ |
|
163 return (False, 0, False) |