eric6/Plugins/PluginVcsSubversion.py

changeset 6942
2602857055c5
parent 6645
ad476851d7e0
child 7199
c71bd6f21748
equal deleted inserted replaced
6941:f99d60d6b59b 6942:2602857055c5
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2007 - 2019 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the Subversion 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
21 from VcsPlugins.vcsSubversion.SvnUtilities import getConfigPath, getServersPath
22
23 import Utilities
24 import UI.Info
25
26 # Start-Of-Header
27 name = "Subversion Plugin"
28 author = "Detlev Offenbach <detlev@die-offenbachs.de>"
29 autoactivate = False
30 deactivateable = True
31 version = UI.Info.VersionOnly
32 pluginType = "version_control"
33 pluginTypename = "Subversion"
34 className = "VcsSubversionPlugin"
35 packageName = "__core__"
36 shortDescription = "Implements the Subversion version control interface."
37 longDescription = \
38 """This plugin provides the Subversion version control interface."""
39 pyqtApi = 2
40 python2Compatible = True
41 # End-Of-Header
42
43 error = ""
44
45
46 def exeDisplayData():
47 """
48 Public method to support the display of some executable info.
49
50 @return dictionary containing the data to query the presence of
51 the executable
52 """
53 exe = 'svn'
54 if Utilities.isWindowsPlatform():
55 exe += '.exe'
56
57 data = {
58 "programEntry": True,
59 "header": QCoreApplication.translate(
60 "VcsSubversionPlugin", "Version Control - Subversion (svn)"),
61 "exe": exe,
62 "versionCommand": '--version',
63 "versionStartsWith": 'svn',
64 "versionPosition": 2,
65 "version": "",
66 "versionCleanup": None,
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 exe = 'svn'
82 if Utilities.isWindowsPlatform():
83 exe += '.exe'
84 if Utilities.isinpath(exe):
85 data[".svn"] = (pluginTypename, displayString())
86 data["_svn"] = (pluginTypename, displayString())
87 return data
88
89
90 def displayString():
91 """
92 Public function to get the display string.
93
94 @return display string (string)
95 """
96 exe = 'svn'
97 if Utilities.isWindowsPlatform():
98 exe += '.exe'
99 if Utilities.isinpath(exe):
100 return QCoreApplication.translate(
101 'VcsSubversionPlugin', 'Subversion (svn)')
102 else:
103 return ""
104
105 subversionCfgPluginObject = None
106
107
108 def createConfigurationPage(configDlg):
109 """
110 Module function to create the configuration page.
111
112 @param configDlg reference to the configuration dialog (QDialog)
113 @return reference to the configuration page
114 """
115 global subversionCfgPluginObject
116 from VcsPlugins.vcsSubversion.ConfigurationPage.SubversionPage import \
117 SubversionPage
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.png"),
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(VcsSubversionPlugin, self).__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 try:
171 e5App().registerPluginObject(
172 pluginTypename, self.__projectHelperObject, pluginType)
173 except KeyError:
174 pass # ignore duplicate registration
175 readShortcuts(pluginName=pluginTypename)
176
177 def getProjectHelper(self):
178 """
179 Public method to get a reference to the project helper object.
180
181 @return reference to the project helper object
182 """
183 return self.__projectHelperObject
184
185 def initToolbar(self, ui, toolbarManager):
186 """
187 Public slot to initialize the VCS toolbar.
188
189 @param ui reference to the main window (UserInterface)
190 @param toolbarManager reference to a toolbar manager object
191 (E5ToolBarManager)
192 """
193 if self.__projectHelperObject:
194 self.__projectHelperObject.initToolbar(ui, toolbarManager)
195
196 def activate(self):
197 """
198 Public method to activate this plugin.
199
200 @return tuple of reference to instantiated viewmanager and
201 activation status (boolean)
202 """
203 from VcsPlugins.vcsSubversion.subversion import Subversion
204 self.__object = Subversion(self, self.__ui)
205
206 tb = self.__ui.getToolbar("vcs")[1]
207 tb.setVisible(False)
208 tb.setEnabled(False)
209
210 tb = self.__ui.getToolbar("subversion")[1]
211 tb.setVisible(True)
212 tb.setEnabled(True)
213
214 return self.__object, True
215
216 def deactivate(self):
217 """
218 Public method to deactivate this plugin.
219 """
220 self.__object = None
221
222 tb = self.__ui.getToolbar("subversion")[1]
223 tb.setVisible(False)
224 tb.setEnabled(False)
225
226 tb = self.__ui.getToolbar("vcs")[1]
227 tb.setVisible(True)
228 tb.setEnabled(True)
229
230 def getPreferences(self, key):
231 """
232 Public method to retrieve the various settings.
233
234 @param key the key of the value to get
235 @return the requested setting
236 """
237 if key in ["StopLogOnCopy"]:
238 return Preferences.toBool(Preferences.Prefs.settings.value(
239 "Subversion/" + key, self.__subversionDefaults[key]))
240 elif key in ["LogLimit", "CommitMessages"]:
241 return int(Preferences.Prefs.settings.value(
242 "Subversion/" + key,
243 self.__subversionDefaults[key]))
244 elif key in ["Commits"]:
245 return Preferences.toList(Preferences.Prefs.settings.value(
246 "Subversion/" + key))
247 else:
248 return Preferences.Prefs.settings.value("Subversion/" + key)
249
250 def setPreferences(self, key, value):
251 """
252 Public method to store the various settings.
253
254 @param key the key of the setting to be set
255 @param value the value to be set
256 """
257 Preferences.Prefs.settings.setValue("Subversion/" + key, value)
258
259 def getServersPath(self):
260 """
261 Public method to get the filename of the servers file.
262
263 @return filename of the servers file (string)
264 """
265 return getServersPath()
266
267 def getConfigPath(self):
268 """
269 Public method to get the filename of the config file.
270
271 @return filename of the config file (string)
272 """
273 return getConfigPath()
274
275 def prepareUninstall(self):
276 """
277 Public method to prepare for an uninstallation.
278 """
279 e5App().unregisterPluginObject(pluginTypename)
280
281 def prepareUnload(self):
282 """
283 Public method to prepare for an unload.
284 """
285 if self.__projectHelperObject:
286 self.__projectHelperObject.removeToolbar(
287 self.__ui, e5App().getObject("ToolbarManager"))
288 e5App().unregisterPluginObject(pluginTypename)

eric ide

mercurial