eric7/Plugins/PluginVcsSubversion.py

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

eric ide

mercurial