|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2007 - 2019 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the PySvn version control plugin. |
|
8 """ |
|
9 |
|
10 from __future__ import unicode_literals |
|
11 |
|
12 import os |
|
13 |
|
14 from PyQt5.QtCore import QObject, QCoreApplication |
|
15 |
|
16 from E5Gui.E5Application import e5App |
|
17 |
|
18 import Preferences |
|
19 from Preferences.Shortcuts import readShortcuts |
|
20 import UI.Info |
|
21 |
|
22 from VcsPlugins.vcsPySvn.SvnUtilities import getConfigPath, getServersPath |
|
23 |
|
24 # Start-Of-Header |
|
25 name = "PySvn Plugin" |
|
26 author = "Detlev Offenbach <detlev@die-offenbachs.de>" |
|
27 autoactivate = False |
|
28 deactivateable = True |
|
29 version = UI.Info.VersionOnly |
|
30 pluginType = "version_control" |
|
31 pluginTypename = "PySvn" |
|
32 className = "VcsPySvnPlugin" |
|
33 packageName = "__core__" |
|
34 shortDescription = "Implements the PySvn version control interface." |
|
35 longDescription = \ |
|
36 """This plugin provides the PySvn version control interface.""" |
|
37 pyqtApi = 2 |
|
38 python2Compatible = True |
|
39 # End-Of-Header |
|
40 |
|
41 error = "" |
|
42 |
|
43 |
|
44 def exeDisplayData(): |
|
45 """ |
|
46 Public method to support the display of some executable info. |
|
47 |
|
48 @return dictionary containing the data to be shown |
|
49 """ |
|
50 try: |
|
51 import pysvn |
|
52 try: |
|
53 text = os.path.dirname(pysvn.__file__) |
|
54 except AttributeError: |
|
55 text = "PySvn" |
|
56 version = ".".join([str(v) for v in pysvn.version]) |
|
57 except ImportError: |
|
58 text = "PySvn" |
|
59 version = "" |
|
60 |
|
61 data = { |
|
62 "programEntry": False, |
|
63 "header": QCoreApplication.translate( |
|
64 "VcsPySvnPlugin", "Version Control - Subversion (pysvn)"), |
|
65 "text": text, |
|
66 "version": version, |
|
67 } |
|
68 |
|
69 return data |
|
70 |
|
71 |
|
72 def getVcsSystemIndicator(): |
|
73 """ |
|
74 Public function to get the indicators for this version control system. |
|
75 |
|
76 @return dictionary with indicator as key and a tuple with the vcs name |
|
77 (string) and vcs display string (string) |
|
78 """ |
|
79 global pluginTypename |
|
80 data = {} |
|
81 data[".svn"] = (pluginTypename, displayString()) |
|
82 data["_svn"] = (pluginTypename, displayString()) |
|
83 return data |
|
84 |
|
85 |
|
86 def displayString(): |
|
87 """ |
|
88 Public function to get the display string. |
|
89 |
|
90 @return display string (string) |
|
91 """ |
|
92 try: |
|
93 import pysvn # __IGNORE_WARNING__ |
|
94 return QCoreApplication.translate('VcsPySvnPlugin', |
|
95 'Subversion (pysvn)') |
|
96 except ImportError: |
|
97 return "" |
|
98 |
|
99 subversionCfgPluginObject = None |
|
100 |
|
101 |
|
102 def createConfigurationPage(configDlg): |
|
103 """ |
|
104 Module function to create the configuration page. |
|
105 |
|
106 @param configDlg reference to the configuration dialog (QDialog) |
|
107 @return reference to the configuration page |
|
108 """ |
|
109 global subversionCfgPluginObject |
|
110 from VcsPlugins.vcsPySvn.ConfigurationPage.SubversionPage import \ |
|
111 SubversionPage |
|
112 if subversionCfgPluginObject is None: |
|
113 subversionCfgPluginObject = VcsPySvnPlugin(None) |
|
114 page = SubversionPage(subversionCfgPluginObject) |
|
115 return page |
|
116 |
|
117 |
|
118 def getConfigData(): |
|
119 """ |
|
120 Module function returning data as required by the configuration dialog. |
|
121 |
|
122 @return dictionary with key "zzz_subversionPage" containing the relevant |
|
123 data |
|
124 """ |
|
125 return { |
|
126 "zzz_subversionPage": |
|
127 [QCoreApplication.translate("VcsPySvnPlugin", "Subversion"), |
|
128 os.path.join("VcsPlugins", "vcsPySvn", "icons", |
|
129 "preferences-subversion.png"), |
|
130 createConfigurationPage, "vcsPage", None], |
|
131 } |
|
132 |
|
133 |
|
134 def prepareUninstall(): |
|
135 """ |
|
136 Module function to prepare for an uninstallation. |
|
137 """ |
|
138 if not e5App().getObject("PluginManager").isPluginLoaded( |
|
139 "PluginVcsSubversion"): |
|
140 Preferences.Prefs.settings.remove("Subversion") |
|
141 |
|
142 |
|
143 class VcsPySvnPlugin(QObject): |
|
144 """ |
|
145 Class implementing the PySvn version control plugin. |
|
146 """ |
|
147 def __init__(self, ui): |
|
148 """ |
|
149 Constructor |
|
150 |
|
151 @param ui reference to the user interface object (UI.UserInterface) |
|
152 """ |
|
153 super(VcsPySvnPlugin, self).__init__(ui) |
|
154 self.__ui = ui |
|
155 |
|
156 self.__subversionDefaults = { |
|
157 "StopLogOnCopy": 1, |
|
158 "LogLimit": 20, |
|
159 "CommitMessages": 20, |
|
160 } |
|
161 |
|
162 from VcsPlugins.vcsPySvn.ProjectHelper import PySvnProjectHelper |
|
163 self.__projectHelperObject = PySvnProjectHelper(None, None) |
|
164 try: |
|
165 e5App().registerPluginObject( |
|
166 pluginTypename, self.__projectHelperObject, pluginType) |
|
167 except KeyError: |
|
168 pass # ignore duplicate registration |
|
169 readShortcuts(pluginName=pluginTypename) |
|
170 |
|
171 def getProjectHelper(self): |
|
172 """ |
|
173 Public method to get a reference to the project helper object. |
|
174 |
|
175 @return reference to the project helper object |
|
176 """ |
|
177 return self.__projectHelperObject |
|
178 |
|
179 def initToolbar(self, ui, toolbarManager): |
|
180 """ |
|
181 Public slot to initialize the VCS toolbar. |
|
182 |
|
183 @param ui reference to the main window (UserInterface) |
|
184 @param toolbarManager reference to a toolbar manager object |
|
185 (E5ToolBarManager) |
|
186 """ |
|
187 if self.__projectHelperObject: |
|
188 self.__projectHelperObject.initToolbar(ui, toolbarManager) |
|
189 |
|
190 def activate(self): |
|
191 """ |
|
192 Public method to activate this plugin. |
|
193 |
|
194 @return tuple of reference to instantiated viewmanager and |
|
195 activation status (boolean) |
|
196 """ |
|
197 from VcsPlugins.vcsPySvn.subversion import Subversion |
|
198 self.__object = Subversion(self, self.__ui) |
|
199 |
|
200 tb = self.__ui.getToolbar("vcs")[1] |
|
201 tb.setVisible(False) |
|
202 tb.setEnabled(False) |
|
203 |
|
204 tb = self.__ui.getToolbar("pysvn")[1] |
|
205 tb.setVisible(True) |
|
206 tb.setEnabled(True) |
|
207 |
|
208 return self.__object, True |
|
209 |
|
210 def deactivate(self): |
|
211 """ |
|
212 Public method to deactivate this plugin. |
|
213 """ |
|
214 self.__object = None |
|
215 |
|
216 tb = self.__ui.getToolbar("pysvn")[1] |
|
217 tb.setVisible(False) |
|
218 tb.setEnabled(False) |
|
219 |
|
220 tb = self.__ui.getToolbar("vcs")[1] |
|
221 tb.setVisible(True) |
|
222 tb.setEnabled(True) |
|
223 |
|
224 def getPreferences(self, key): |
|
225 """ |
|
226 Public method to retrieve the various settings. |
|
227 |
|
228 @param key the key of the value to get |
|
229 @return the requested refactoring setting |
|
230 """ |
|
231 if key in ["StopLogOnCopy"]: |
|
232 return Preferences.toBool(Preferences.Prefs.settings.value( |
|
233 "Subversion/" + key, self.__subversionDefaults[key])) |
|
234 elif key in ["LogLimit", "CommitMessages"]: |
|
235 return int(Preferences.Prefs.settings.value( |
|
236 "Subversion/" + key, |
|
237 self.__subversionDefaults[key])) |
|
238 elif key in ["Commits"]: |
|
239 return Preferences.toList(Preferences.Prefs.settings.value( |
|
240 "Subversion/" + key)) |
|
241 else: |
|
242 return Preferences.Prefs.settings.value("Subversion/" + key) |
|
243 |
|
244 def setPreferences(self, key, value): |
|
245 """ |
|
246 Public method to store the various settings. |
|
247 |
|
248 @param key the key of the setting to be set |
|
249 @param value the value to be set |
|
250 """ |
|
251 Preferences.Prefs.settings.setValue("Subversion/" + key, value) |
|
252 |
|
253 def getServersPath(self): |
|
254 """ |
|
255 Public method to get the filename of the servers file. |
|
256 |
|
257 @return filename of the servers file (string) |
|
258 """ |
|
259 return getServersPath() |
|
260 |
|
261 def getConfigPath(self): |
|
262 """ |
|
263 Public method to get the filename of the config file. |
|
264 |
|
265 @return filename of the config file (string) |
|
266 """ |
|
267 return getConfigPath() |
|
268 |
|
269 def prepareUninstall(self): |
|
270 """ |
|
271 Public method to prepare for an uninstallation. |
|
272 """ |
|
273 e5App().unregisterPluginObject(pluginTypename) |
|
274 |
|
275 def prepareUnload(self): |
|
276 """ |
|
277 Public method to prepare for an unload. |
|
278 """ |
|
279 if self.__projectHelperObject: |
|
280 self.__projectHelperObject.removeToolbar( |
|
281 self.__ui, e5App().getObject("ToolbarManager")) |
|
282 e5App().unregisterPluginObject(pluginTypename) |