src/eric7/Plugins/PluginVcsPySvn.py

branch
eric7
changeset 9209
b99e7fd55fd3
parent 8881
54e42bc2437a
child 9221
bf71ee032bb4
equal deleted inserted replaced
9208:3fc8dfeb6ebe 9209:b99e7fd55fd3
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2007 - 2022 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the PySvn version control plugin.
8 """
9
10 import os
11 import contextlib
12
13 from PyQt6.QtCore import QObject, QCoreApplication
14
15 from EricWidgets.EricApplication import ericApp
16
17 import Preferences
18 from Preferences.Shortcuts import readShortcuts
19 import UI.Info
20
21 from VcsPlugins.vcsPySvn.SvnUtilities import getConfigPath, getServersPath
22
23 # Start-Of-Header
24 name = "PySvn Plugin"
25 author = "Detlev Offenbach <detlev@die-offenbachs.de>"
26 autoactivate = False
27 deactivateable = True
28 version = UI.Info.VersionOnly
29 pluginType = "version_control"
30 pluginTypename = "PySvn"
31 className = "VcsPySvnPlugin"
32 packageName = "__core__"
33 shortDescription = "Implements the PySvn version control interface."
34 longDescription = (
35 """This plugin provides the PySvn version control interface."""
36 )
37 pyqtApi = 2
38 # End-Of-Header
39
40 error = ""
41
42
43 def exeDisplayData():
44 """
45 Public method to support the display of some executable info.
46
47 @return dictionary containing the data to be shown
48 """
49 try:
50 import pysvn
51 try:
52 text = os.path.dirname(pysvn.__file__)
53 except AttributeError:
54 text = "PySvn"
55 version = ".".join([str(v) for v in pysvn.version])
56 except ImportError:
57 text = "PySvn"
58 version = ""
59
60 data = {
61 "programEntry": False,
62 "header": QCoreApplication.translate(
63 "VcsPySvnPlugin", "Version Control - Subversion (pysvn)"),
64 "text": text,
65 "version": version,
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 data[".svn"] = (pluginTypename, displayString())
81 data["_svn"] = (pluginTypename, displayString())
82 return data
83
84
85 def displayString():
86 """
87 Public function to get the display string.
88
89 @return display string (string)
90 """
91 try:
92 import pysvn # __IGNORE_WARNING__
93 return QCoreApplication.translate('VcsPySvnPlugin',
94 'Subversion (pysvn)')
95 except ImportError:
96 return ""
97
98 subversionCfgPluginObject = None
99
100
101 def createConfigurationPage(configDlg):
102 """
103 Module function to create the configuration page.
104
105 @param configDlg reference to the configuration dialog (QDialog)
106 @return reference to the configuration page
107 """
108 global subversionCfgPluginObject
109 from VcsPlugins.vcsPySvn.ConfigurationPage.SubversionPage import (
110 SubversionPage
111 )
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.svg"),
130 createConfigurationPage, "vcsPage", None],
131 }
132
133
134 def prepareUninstall():
135 """
136 Module function to prepare for an uninstallation.
137 """
138 if not ericApp().getObject("PluginManager").isPluginLoaded(
139 "PluginVcsSubversion"):
140 Preferences.getSettings().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().__init__(ui)
154 self.__ui = ui
155
156 self.__subversionDefaults = {
157 "StopLogOnCopy": 1,
158 "LogLimit": 20,
159 }
160
161 from VcsPlugins.vcsPySvn.ProjectHelper import PySvnProjectHelper
162 self.__projectHelperObject = PySvnProjectHelper(None, None)
163 with contextlib.suppress(KeyError):
164 ericApp().registerPluginObject(
165 pluginTypename, self.__projectHelperObject, pluginType)
166 readShortcuts(pluginName=pluginTypename)
167
168 def getProjectHelper(self):
169 """
170 Public method to get a reference to the project helper object.
171
172 @return reference to the project helper object
173 """
174 return self.__projectHelperObject
175
176 def initToolbar(self, ui, toolbarManager):
177 """
178 Public slot to initialize the VCS toolbar.
179
180 @param ui reference to the main window (UserInterface)
181 @param toolbarManager reference to a toolbar manager object
182 (EricToolBarManager)
183 """
184 if self.__projectHelperObject:
185 self.__projectHelperObject.initToolbar(ui, toolbarManager)
186
187 def activate(self):
188 """
189 Public method to activate this plugin.
190
191 @return tuple of reference to instantiated viewmanager and
192 activation status (boolean)
193 """
194 from VcsPlugins.vcsPySvn.subversion import Subversion
195 self.__object = Subversion(self, self.__ui)
196
197 tb = self.__ui.getToolbar("vcs")[1]
198 tb.setVisible(False)
199 tb.setEnabled(False)
200
201 tb = self.__ui.getToolbar("pysvn")[1]
202 tb.setVisible(Preferences.getVCS("ShowVcsToolbar"))
203 tb.setEnabled(True)
204
205 return self.__object, True
206
207 def deactivate(self):
208 """
209 Public method to deactivate this plugin.
210 """
211 self.__object = None
212
213 tb = self.__ui.getToolbar("pysvn")[1]
214 tb.setVisible(False)
215 tb.setEnabled(False)
216
217 tb = self.__ui.getToolbar("vcs")[1]
218 tb.setVisible(Preferences.getVCS("ShowVcsToolbar"))
219 tb.setEnabled(True)
220
221 def getPreferences(self, key):
222 """
223 Public method to retrieve the various settings.
224
225 @param key the key of the value to get
226 @return the requested refactoring setting
227 """
228 if key in ["StopLogOnCopy"]:
229 return Preferences.toBool(Preferences.getSettings().value(
230 "Subversion/" + key, self.__subversionDefaults[key]))
231 elif key in ["LogLimit"]:
232 return int(Preferences.getSettings().value(
233 "Subversion/" + key,
234 self.__subversionDefaults[key]))
235 elif key in ["Commits"]:
236 return Preferences.toList(Preferences.getSettings().value(
237 "Subversion/" + key))
238 else:
239 return Preferences.getSettings().value("Subversion/" + key)
240
241 def setPreferences(self, key, value):
242 """
243 Public method to store the various settings.
244
245 @param key the key of the setting to be set
246 @param value the value to be set
247 """
248 Preferences.getSettings().setValue("Subversion/" + key, value)
249
250 def getServersPath(self):
251 """
252 Public method to get the filename of the servers file.
253
254 @return filename of the servers file (string)
255 """
256 return getServersPath()
257
258 def getConfigPath(self):
259 """
260 Public method to get the filename of the config file.
261
262 @return filename of the config file (string)
263 """
264 return getConfigPath()
265
266 def prepareUninstall(self):
267 """
268 Public method to prepare for an uninstallation.
269 """
270 ericApp().unregisterPluginObject(pluginTypename)
271
272 def prepareUnload(self):
273 """
274 Public method to prepare for an unload.
275 """
276 if self.__projectHelperObject:
277 self.__projectHelperObject.removeToolbar(
278 self.__ui, ericApp().getObject("ToolbarManager"))
279 ericApp().unregisterPluginObject(pluginTypename)

eric ide

mercurial