src/eric7/Plugins/VcsPlugins/vcsMercurial/hg.py

branch
eric7
changeset 10679
4d3e0ce54322
parent 10621
f5631f40c4d9
child 10683
779cda568acb
equal deleted inserted replaced
10678:665f1084ebf9 10679:4d3e0ce54322
10 import contextlib 10 import contextlib
11 import os 11 import os
12 import pathlib 12 import pathlib
13 import shutil 13 import shutil
14 14
15 from PyQt6.QtCore import QCoreApplication, QFileSystemWatcher, pyqtSignal 15 from PyQt6.QtCore import QCoreApplication, pyqtSignal
16 from PyQt6.QtWidgets import QApplication, QDialog, QInputDialog 16 from PyQt6.QtWidgets import QApplication, QDialog, QInputDialog
17 17
18 from eric7 import Preferences, Utilities 18 from eric7 import Preferences, Utilities
19 from eric7.EricCore import EricFileSystemWatcher
19 from eric7.EricWidgets import EricFileDialog, EricMessageBox 20 from eric7.EricWidgets import EricFileDialog, EricMessageBox
20 from eric7.EricWidgets.EricApplication import ericApp 21 from eric7.EricWidgets.EricApplication import ericApp
21 from eric7.QScintilla.MiniEditor import MiniEditor 22 from eric7.QScintilla.MiniEditor import MiniEditor
22 from eric7.SystemUtilities import FileSystemUtilities 23 from eric7.SystemUtilities import FileSystemUtilities
23 from eric7.VCS.RepositoryInfoDialog import VcsRepositoryInfoDialog 24 from eric7.VCS.RepositoryInfoDialog import VcsRepositoryInfoDialog
130 131
131 self.__forgotNames = [] 132 self.__forgotNames = []
132 133
133 self.__activeExtensions = [] 134 self.__activeExtensions = []
134 135
135 self.__iniWatcher = QFileSystemWatcher(self) 136 self.__iniFileChangedFlag = False
136 self.__iniWatcher.fileChanged.connect(self.__iniFileChanged) 137
137 cfgFile = getConfigPath() 138 watcher = EricFileSystemWatcher.instance()
138 if os.path.exists(cfgFile): 139 watcher.fileDeleted.connect(self.__iniFileChanged)
139 self.__iniWatcher.addPath(cfgFile) 140 watcher.fileModified.connect(self.__iniFileChanged)
141 self.__cfgFile = getConfigPath()
142 if os.path.exists(self.__cfgFile):
143 watcher.addPath(self.__cfgFile)
140 144
141 self.__client = None 145 self.__client = None
142 self.__createClient() 146 self.__createClient()
143 self.__projectHelper = None 147 self.__projectHelper = None
144 148
222 for extension in self.__extensions.values(): 226 for extension in self.__extensions.values():
223 extension.shutdown() 227 extension.shutdown()
224 228
225 # shut down the client 229 # shut down the client
226 self.__client and self.__client.stopServer() 230 self.__client and self.__client.stopServer()
231
232 watcher = EricFileSystemWatcher.instance()
233 watcher.fileDeleted.disconnect(self.__iniFileChanged)
234 watcher.fileModified.disconnect(self.__iniFileChanged)
235 watcher.removePath(self.__cfgFile)
236 if self.__repoIniFile:
237 watcher.removePath(self.__repoIniFile)
227 238
228 def initCommand(self, command): 239 def initCommand(self, command):
229 """ 240 """
230 Public method to initialize a command arguments list. 241 Public method to initialize a command arguments list.
231 242
3030 Private slot to handle a change of the Mercurial configuration file. 3041 Private slot to handle a change of the Mercurial configuration file.
3031 3042
3032 @param path name of the changed file 3043 @param path name of the changed file
3033 @type str 3044 @type str
3034 """ 3045 """
3035 if self.__client: 3046 if (
3036 ok, err = self.__client.restartServer() 3047 path in (self.__cfgFile, self.__repoIniFile)
3037 if not ok: 3048 and not self.__iniFileChangedFlag
3038 EricMessageBox.warning( 3049 ):
3039 None, 3050 self.__iniFileChangedFlag = True
3040 self.tr("Mercurial Command Server"), 3051 if self.__client:
3041 self.tr( 3052 ok, err = self.__client.restartServer()
3042 """<p>The Mercurial Command Server could not be""" 3053 if not ok:
3043 """ restarted.</p><p>Reason: {0}</p>""" 3054 EricMessageBox.warning(
3044 ).format(err), 3055 None,
3045 ) 3056 self.tr("Mercurial Command Server"),
3046 3057 self.tr(
3047 self.__getExtensionsInfo() 3058 """<p>The Mercurial Command Server could not be"""
3048 3059 """ restarted.</p><p>Reason: {0}</p>"""
3049 if self.__repoIniFile and path == self.__repoIniFile: 3060 ).format(err),
3050 self.__checkDefaults() 3061 )
3051 3062
3052 self.iniFileChanged.emit() 3063 self.__getExtensionsInfo()
3064
3065 if self.__repoIniFile and path == self.__repoIniFile:
3066 self.__checkDefaults()
3067
3068 self.iniFileChanged.emit()
3069
3070 self.__iniFileChangedFlag = False
3053 3071
3054 def __monitorRepoIniFile(self, repodir): 3072 def __monitorRepoIniFile(self, repodir):
3055 """ 3073 """
3056 Private slot to add a repository configuration file to the list of 3074 Private slot to add a repository configuration file to the list of
3057 monitored files. 3075 monitored files.
3059 @param repodir directory name of the repository 3077 @param repodir directory name of the repository
3060 @type str 3078 @type str
3061 """ 3079 """
3062 cfgFile = os.path.join(repodir, self.adminDir, "hgrc") 3080 cfgFile = os.path.join(repodir, self.adminDir, "hgrc")
3063 if os.path.exists(cfgFile): 3081 if os.path.exists(cfgFile):
3064 self.__iniWatcher.addPath(cfgFile) 3082 watcher = EricFileSystemWatcher.instance()
3083 watcher.addPath(cfgFile)
3065 self.__repoIniFile = cfgFile 3084 self.__repoIniFile = cfgFile
3066 self.__checkDefaults() 3085 self.__checkDefaults()
3067 3086
3068 ########################################################################### 3087 ###########################################################################
3069 ## Methods to handle extensions are below. 3088 ## Methods to handle extensions are below.

eric ide

mercurial