src/eric7/QtHelpInterface/HelpDocsInstaller.py

branch
eric7
changeset 11217
856628e8a303
parent 11090
f5f5f5803935
equal deleted inserted replaced
11216:a1471981ef18 11217:856628e8a303
9 """ 9 """
10 10
11 import datetime 11 import datetime
12 import pathlib 12 import pathlib
13 13
14 from PyQt6.QtCore import QLibraryInfo, QMutex, QThread, pyqtSignal 14 from PyQt6.QtCore import QMutex, QThread, pyqtSignal
15 from PyQt6.QtHelp import QHelpEngineCore 15 from PyQt6.QtHelp import QHelpEngineCore
16 16
17 from eric7.Globals import getConfig 17 from eric7.Globals import getConfig
18 from eric7.SystemUtilities import QtUtilities
19 18
20 19
21 class HelpDocsInstaller(QThread): 20 class HelpDocsInstaller(QThread):
22 """ 21 """
23 Class implementing the worker thread populating and updating the QtHelp 22 Class implementing the worker thread populating and updating the QtHelp
67 Public method executed by the thread. 66 Public method executed by the thread.
68 """ 67 """
69 engine = QHelpEngineCore(self.__collection) 68 engine = QHelpEngineCore(self.__collection)
70 changes = False 69 changes = False
71 70
72 qt5Docs = [
73 "activeqt",
74 "qdoc",
75 "qmake",
76 "qt3d",
77 "qt3drenderer",
78 "qtandroidextras",
79 "qtassistant",
80 "qtbluetooth",
81 "qtcanvas3d",
82 "qtcharts",
83 "qtcmake",
84 "qtconcurrent",
85 "qtcore",
86 "qtdatavis3d",
87 "qtdatavisualization",
88 "qtdbus",
89 "qtdesigner",
90 "qtdistancefieldgenerator",
91 "qtdoc",
92 "qtenginio",
93 "qtenginiooverview",
94 "qtenginoqml",
95 "qtgamepad",
96 "qtgraphicaleffects",
97 "qtgui",
98 "qthelp",
99 "qthttpserver",
100 "qtimageformats",
101 "qtlabscalendar",
102 "qtlabsplatform",
103 "qtlabscontrols",
104 "qtlinguist",
105 "qtlocation",
106 "qtlottieanimation",
107 "qtmacextras",
108 "qtmultimedia",
109 "qtmultimediawidgets",
110 "qtnetwork",
111 "qtnetworkauth",
112 "qtnfc",
113 "qtopengl",
114 "qtpdf",
115 "qtplatformheaders",
116 "qtpositioning",
117 "qtprintsupport",
118 "qtpurchasing",
119 "qtqml",
120 "qtqmlcore",
121 "qtqmlmodels",
122 "qtqmltest",
123 "qtqmlworkerscript",
124 "qtqmlxmllistmodel",
125 "qtquick",
126 "qtquick3d",
127 "qtquick3dphysics",
128 "qtquickcontrols",
129 "qtquickcontrols1",
130 "qtquickdialogs",
131 "qtquickextras",
132 "qtquicklayouts",
133 "qtquicktimeline",
134 "qtremoteobjects",
135 "qtscript",
136 "qtscripttools",
137 "qtscxml",
138 "qtsensors",
139 "qtserialbus",
140 "qtserialport",
141 "qtshadertools",
142 "qtspatialaudio",
143 "qtspeech",
144 "qtsql",
145 "qtstatemachine",
146 "qtsvg",
147 "qttest",
148 "qttestlib",
149 "qtuitools",
150 "qtvirtualkeyboard",
151 "qtwaylandcompositor",
152 "qtwebchannel",
153 "qtwebengine",
154 "qtwebenginewidgets",
155 "qtwebkit",
156 "qtwebkitexamples",
157 "qtwebsockets",
158 "qtwebview",
159 "qtwidgets",
160 "qtwinextras",
161 "qtx11extras",
162 "qtxml",
163 "qtxmlpatterns",
164 ]
165 for qtDocs, version in [(qt5Docs, 5)]:
166 for doc in qtDocs:
167 changes |= self.__installQtDoc(doc, version, engine)
168 self.__mutex.lock()
169 if self.__abort:
170 engine = None
171 self.__mutex.unlock()
172 return
173 self.__mutex.unlock()
174
175 changes |= self.__installEric7Doc(engine) 71 changes |= self.__installEric7Doc(engine)
176 engine = None 72 engine = None
177 del engine 73 del engine
178 self.docsInstalled.emit(changes) 74 self.docsInstalled.emit(changes)
179
180 def __installQtDoc(self, name, version, engine):
181 """
182 Private method to install/update a Qt help document.
183
184 @param name name of the Qt help document
185 @type str
186 @param version Qt version of the help documents
187 @type int
188 @param engine reference to the help engine
189 @type QHelpEngineCore
190 @return flag indicating success
191 @rtype bool
192 """
193 versionKey = "qt_version_{0}@@{1}".format(version, name)
194 info = engine.customValue(versionKey, "")
195 lst = info.split("|") if info else []
196
197 dt = None
198 if len(lst) and lst[0]:
199 dt = datetime.datetime.fromisoformat(lst[0])
200
201 qchFile = ""
202 if len(lst) == 2:
203 qchFile = lst[1]
204
205 if version == 5:
206 docsPath = pathlib.Path(
207 QLibraryInfo.path(QLibraryInfo.LibraryPath.DocumentationPath)
208 )
209 if not docsPath.is_dir() or len(list(docsPath.glob("*.qch"))) == 0:
210 docsPath = (
211 docsPath.parents[2]
212 / "Docs"
213 / "Qt-{0}.{1}".format(*QtUtilities.qVersionTuple())
214 )
215 else:
216 # unsupported Qt version
217 return False
218
219 files = list(docsPath.glob("*.qch"))
220 if not files:
221 engine.setCustomValue(versionKey, "|")
222 return False
223
224 for f in files:
225 if f.stem == name:
226 namespace = QHelpEngineCore.namespaceName(str(f.resolve()))
227 if not namespace:
228 continue
229
230 if (
231 dt is not None
232 and namespace in engine.registeredDocumentations()
233 and (
234 datetime.datetime.fromtimestamp(
235 f.stat().st_mtime, tz=datetime.timezone.utc
236 )
237 == dt
238 )
239 and qchFile == str(f.resolve())
240 ):
241 return False
242
243 if namespace in engine.registeredDocumentations():
244 engine.unregisterDocumentation(namespace)
245
246 if not engine.registerDocumentation(str(f.resolve())):
247 self.errorMessage.emit(
248 self.tr(
249 """<p>The file <b>{0}</b> could not be"""
250 """ registered. <br/>Reason: {1}</p>"""
251 ).format(f, engine.error())
252 )
253 return False
254
255 engine.setCustomValue(
256 versionKey,
257 datetime.datetime.fromtimestamp(
258 f.stat().st_mtime, tz=datetime.timezone.utc
259 ).isoformat()
260 + "|"
261 + str(f.resolve()),
262 )
263 return True
264
265 return False
266 75
267 def __installEric7Doc(self, engine): 76 def __installEric7Doc(self, engine):
268 """ 77 """
269 Private method to install/update the eric help documentation. 78 Private method to install/update the eric help documentation.
270 79

eric ide

mercurial