|
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 |
|
12 import os |
|
13 |
|
14 import pysvn |
|
15 |
|
16 from VCS.StatusMonitorThread import VcsStatusMonitorThread |
|
17 |
|
18 import Preferences |
|
19 |
|
20 |
|
21 class SvnStatusMonitorThread(VcsStatusMonitorThread): |
|
22 """ |
|
23 Class implementing the VCS status monitor thread class for Subversion. |
|
24 """ |
|
25 def __init__(self, interval, project, vcs, parent=None): |
|
26 """ |
|
27 Constructor |
|
28 |
|
29 @param interval new interval in seconds (integer) |
|
30 @param project reference to the project object (Project) |
|
31 @param vcs reference to the version control object |
|
32 @param parent reference to the parent object (QObject) |
|
33 """ |
|
34 VcsStatusMonitorThread.__init__(self, interval, project, vcs, parent) |
|
35 |
|
36 def _performMonitor(self): |
|
37 """ |
|
38 Protected method implementing the monitoring action. |
|
39 |
|
40 This method populates the statusList member variable |
|
41 with a list of strings giving the status in the first column and the |
|
42 path relative to the project directory starting with the third column. |
|
43 The allowed status flags are: |
|
44 <ul> |
|
45 <li>"A" path was added but not yet comitted</li> |
|
46 <li>"M" path has local changes</li> |
|
47 <li>"O" path was removed</li> |
|
48 <li>"R" path was deleted and then re-added</li> |
|
49 <li>"U" path needs an update</li> |
|
50 <li>"Z" path contains a conflict</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 = \ |
|
62 self.__clientLoginCallback |
|
63 client.callback_ssl_server_trust_prompt = \ |
|
64 self.__clientSslServerTrustPromptCallback |
|
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 = uptodate and \ |
|
77 file.repos_text_status != pysvn.wc_status_kind.modified |
|
78 if file.repos_prop_status != pysvn.wc_status_kind.none: |
|
79 uptodate = uptodate and \ |
|
80 file.repos_prop_status != pysvn.wc_status_kind.modified |
|
81 |
|
82 status = "" |
|
83 if not uptodate: |
|
84 status = "U" |
|
85 self.shouldUpdate = True |
|
86 elif file.text_status == pysvn.wc_status_kind.conflicted or \ |
|
87 file.prop_status == pysvn.wc_status_kind.conflicted: |
|
88 status = "Z" |
|
89 elif file.text_status == pysvn.wc_status_kind.deleted or \ |
|
90 file.prop_status == pysvn.wc_status_kind.deleted: |
|
91 status = "O" |
|
92 elif file.text_status == pysvn.wc_status_kind.modified or \ |
|
93 file.prop_status == pysvn.wc_status_kind.modified: |
|
94 status = "M" |
|
95 elif file.text_status == pysvn.wc_status_kind.added or \ |
|
96 file.prop_status == pysvn.wc_status_kind.added: |
|
97 status = "A" |
|
98 elif file.text_status == pysvn.wc_status_kind.replaced or \ |
|
99 file.prop_status == pysvn.wc_status_kind.replaced: |
|
100 status = "R" |
|
101 if status: |
|
102 states[file.path] = status |
|
103 try: |
|
104 if self.reportedStates[file.path] != status: |
|
105 self.statusList.append( |
|
106 "{0} {1}".format(status, file.path)) |
|
107 except KeyError: |
|
108 self.statusList.append( |
|
109 "{0} {1}".format(status, file.path)) |
|
110 for name in list(self.reportedStates.keys()): |
|
111 if name not in states: |
|
112 self.statusList.append(" {0}".format(name)) |
|
113 self.reportedStates = states |
|
114 res = True |
|
115 statusStr = self.tr( |
|
116 "Subversion status checked successfully (using pysvn)") |
|
117 except pysvn.ClientError as e: |
|
118 res = False |
|
119 statusStr = e.args[0] |
|
120 os.chdir(cwd) |
|
121 return res, statusStr |
|
122 |
|
123 def __clientLoginCallback(self, realm, username, may_save): |
|
124 """ |
|
125 Private method called by the client to get login information. |
|
126 |
|
127 @param realm name of the realm of the requested credentials (string) |
|
128 @param username username as supplied by subversion (string) |
|
129 @param may_save flag indicating, that subversion is willing to save |
|
130 the answers returned (boolean) |
|
131 @return tuple of four values (retcode, username, password, save). |
|
132 Retcode should be True, if username and password should be used |
|
133 by subversion, username and password contain the relevant data |
|
134 as strings and save is a flag indicating, that username and |
|
135 password should be saved. Always returns (False, "", "", False). |
|
136 """ |
|
137 return (False, "", "", False) |
|
138 |
|
139 def __clientSslServerTrustPromptCallback(self, trust_dict): |
|
140 """ |
|
141 Private method called by the client to request acceptance for a |
|
142 ssl server certificate. |
|
143 |
|
144 @param trust_dict dictionary containing the trust data |
|
145 @return tuple of three values (retcode, acceptedFailures, save). |
|
146 Retcode should be true, if the certificate should be accepted, |
|
147 acceptedFailures should indicate the accepted certificate failures |
|
148 and save should be True, if subversion should save the certificate. |
|
149 Always returns (False, 0, False). |
|
150 """ |
|
151 return (False, 0, False) |