8239:59a9a658618c | 8240:93b8a353c4bf |
---|---|
6 """ | 6 """ |
7 Module implementing the manager for GreaseMonkey scripts. | 7 Module implementing the manager for GreaseMonkey scripts. |
8 """ | 8 """ |
9 | 9 |
10 import os | 10 import os |
11 import contextlib | |
11 | 12 |
12 from PyQt5.QtCore import ( | 13 from PyQt5.QtCore import ( |
13 pyqtSignal, pyqtSlot, Qt, QObject, QTimer, QFile, QFileInfo, QDir, | 14 pyqtSignal, pyqtSlot, Qt, QObject, QTimer, QFile, QFileInfo, QDir, |
14 QSettings, QMetaObject, QUrl, Q_ARG, QCoreApplication | 15 QSettings, QMetaObject, QUrl, Q_ARG, QCoreApplication |
15 ) | 16 ) |
126 """'{0}' is already installed.""").format( | 127 """'{0}' is already installed.""").format( |
127 script.fullName()) | 128 script.fullName()) |
128 ) | 129 ) |
129 | 130 |
130 if deleteScript: | 131 if deleteScript: |
131 try: | 132 with contextlib.suppress(OSError): |
132 os.remove(fileName) | 133 os.remove(fileName) |
133 except OSError: | |
134 # ignore | |
135 pass | |
136 | 134 |
137 def scriptsDirectory(self): | 135 def scriptsDirectory(self): |
138 """ | 136 """ |
139 Public method to get the path of the scripts directory. | 137 Public method to get the path of the scripts directory. |
140 | 138 |
265 @return flag indicating success (boolean) | 263 @return flag indicating success (boolean) |
266 """ | 264 """ |
267 if not script: | 265 if not script: |
268 return False | 266 return False |
269 | 267 |
270 try: | 268 with contextlib.suppress(ValueError): |
271 self.__scripts.remove(script) | 269 self.__scripts.remove(script) |
272 except ValueError: | |
273 pass | |
274 | 270 |
275 fullName = script.fullName() | 271 fullName = script.fullName() |
276 collection = WebBrowserWindow.webProfile().scripts() | 272 collection = WebBrowserWindow.webProfile().scripts() |
277 collection.remove(collection.findScript(fullName)) | 273 collection.remove(collection.findScript(fullName)) |
278 | 274 |