6 """ |
6 """ |
7 Module implementing a thread class populating and updating the QtHelp |
7 Module implementing a thread class populating and updating the QtHelp |
8 documentation database. |
8 documentation database. |
9 """ |
9 """ |
10 |
10 |
11 import os |
11 import datetime |
12 |
12 import pathlib |
13 from PyQt6.QtCore import ( |
13 |
14 pyqtSignal, QThread, Qt, QMutex, QDateTime, QDir, QLibraryInfo, QFileInfo |
14 from PyQt6.QtCore import pyqtSignal, QThread, QMutex, QLibraryInfo |
15 ) |
|
16 from PyQt6.QtHelp import QHelpEngineCore |
15 from PyQt6.QtHelp import QHelpEngineCore |
17 |
16 |
18 from eric7config import getConfig |
17 from eric7config import getConfig |
19 |
18 |
20 from Globals import qVersionTuple |
19 from Globals import qVersionTuple |
123 """ |
122 """ |
124 versionKey = "qt_version_{0}@@{1}".format(version, name) |
123 versionKey = "qt_version_{0}@@{1}".format(version, name) |
125 info = engine.customValue(versionKey, "") |
124 info = engine.customValue(versionKey, "") |
126 lst = info.split('|') |
125 lst = info.split('|') |
127 |
126 |
128 dt = QDateTime() |
127 dt = None |
129 if len(lst) and lst[0]: |
128 if len(lst) and lst[0]: |
130 dt = QDateTime.fromString(lst[0], Qt.DateFormat.ISODate) |
129 dt = datetime.datetime.fromisoformat(lst[0]) |
131 |
130 |
132 qchFile = "" |
131 qchFile = "" |
133 if len(lst) == 2: |
132 if len(lst) == 2: |
134 qchFile = lst[1] |
133 qchFile = lst[1] |
135 |
134 |
136 if version == 5: |
135 if version == 5: |
137 docsPath = QLibraryInfo.path( |
136 docsPath = pathlib.Path(QLibraryInfo.path( |
138 QLibraryInfo.LibraryPath.DocumentationPath) |
137 QLibraryInfo.LibraryPath.DocumentationPath)) |
139 if ( |
138 if ( |
140 not os.path.isdir(docsPath) or |
139 not docsPath.is_dir() or |
141 len(QDir(docsPath).entryList(["*.qch"])) == 0 |
140 len(docsPath.glob("*.qch")) == 0 |
142 ): |
141 ): |
143 docsPathList = QDir.fromNativeSeparators(docsPath).split("/") |
142 docsPath = ( |
144 docsPath = os.sep.join( |
143 docsPath.parents[2] / "Docs" / |
145 docsPathList[:-3] + |
144 "Qt-{0}.{1}".format(*qVersionTuple()) |
146 ["Docs", "Qt-{0}.{1}".format(*qVersionTuple())]) |
145 ) |
147 docsPath = QDir(docsPath) |
|
148 else: |
146 else: |
149 # unsupported Qt version |
147 # unsupported Qt version |
150 return False |
148 return False |
151 |
149 |
152 files = docsPath.entryList(["*.qch"]) |
150 files = docsPath.glob("*.qch") |
153 if not files: |
151 if not files: |
154 engine.setCustomValue( |
152 engine.setCustomValue(versionKey, '|') |
155 versionKey, |
|
156 QDateTime().toString(Qt.DateFormat.ISODate) + '|') |
|
157 return False |
153 return False |
158 |
154 |
159 for f in files: |
155 for f in files: |
160 if f.startswith(name + "."): |
156 if f.stem == name: |
161 fi = QFileInfo(docsPath.absolutePath() + QDir.separator() + f) |
157 namespace = QHelpEngineCore.namespaceName(str(f.resolve())) |
162 namespace = QHelpEngineCore.namespaceName( |
|
163 fi.absoluteFilePath()) |
|
164 if not namespace: |
158 if not namespace: |
165 continue |
159 continue |
166 |
160 |
167 if ( |
161 if ( |
168 dt.isValid() and |
162 dt is not None and |
169 namespace in engine.registeredDocumentations() and |
163 namespace in engine.registeredDocumentations() and |
170 (fi.lastModified().toString(Qt.DateFormat.ISODate) == |
164 (datetime.datetime.fromtimestamp(f.stat().st_mtime) == |
171 dt.toString(Qt.DateFormat.ISODate)) and |
165 dt) and |
172 qchFile == fi.absoluteFilePath() |
166 qchFile == str(f.resolve()) |
173 ): |
167 ): |
174 return False |
168 return False |
175 |
169 |
176 if namespace in engine.registeredDocumentations(): |
170 if namespace in engine.registeredDocumentations(): |
177 engine.unregisterDocumentation(namespace) |
171 engine.unregisterDocumentation(namespace) |
178 |
172 |
179 if not engine.registerDocumentation(fi.absoluteFilePath()): |
173 if not engine.registerDocumentation(str(f.resolve())): |
180 self.errorMessage.emit( |
174 self.errorMessage.emit( |
181 self.tr( |
175 self.tr( |
182 """<p>The file <b>{0}</b> could not be""" |
176 """<p>The file <b>{0}</b> could not be""" |
183 """ registered. <br/>Reason: {1}</p>""") |
177 """ registered. <br/>Reason: {1}</p>""") |
184 .format(fi.absoluteFilePath, engine.error()) |
178 .format(f, engine.error()) |
185 ) |
179 ) |
186 return False |
180 return False |
187 |
181 |
188 engine.setCustomValue( |
182 engine.setCustomValue( |
189 versionKey, |
183 versionKey, |
190 fi.lastModified().toString(Qt.DateFormat.ISODate) + '|' + |
184 datetime.datetime.fromtimestamp(f.stat().st_mtime) |
191 fi.absoluteFilePath()) |
185 .isoformat() + '|' + str(f.resolve())) |
192 return True |
186 return True |
193 |
187 |
194 return False |
188 return False |
195 |
189 |
196 def __installEric7Doc(self, engine): |
190 def __installEric7Doc(self, engine): |
204 """ |
198 """ |
205 versionKey = "eric7_ide" |
199 versionKey = "eric7_ide" |
206 info = engine.customValue(versionKey, "") |
200 info = engine.customValue(versionKey, "") |
207 lst = info.split('|') |
201 lst = info.split('|') |
208 |
202 |
209 dt = QDateTime() |
203 dt = None |
210 if len(lst) and lst[0]: |
204 if len(lst) and lst[0]: |
211 dt = QDateTime.fromString(lst[0], Qt.DateFormat.ISODate) |
205 dt = datetime.datetime.fromisoformat(lst[0]) |
212 |
206 |
213 qchFile = "" |
207 qchFile = "" |
214 if len(lst) == 2: |
208 if len(lst) == 2: |
215 qchFile = lst[1] |
209 qchFile = lst[1] |
216 |
210 |
217 docsPath = QDir(getConfig("ericDocDir") + QDir.separator() + "Help") |
211 docsPath = pathlib.Path(getConfig("ericDocDir")) / "Help" |
218 |
212 |
219 files = docsPath.entryList(["*.qch"]) |
213 files = docsPath.glob("*.qch") |
220 if not files: |
214 if not files: |
221 engine.setCustomValue( |
215 engine.setCustomValue(versionKey, '|') |
222 versionKey, QDateTime().toString(Qt.DateFormat.ISODate) + '|') |
|
223 return False |
216 return False |
224 |
217 |
225 for f in files: |
218 for f in files: |
226 if f == "source.qch": |
219 if f.name == "source.qch": |
227 fi = QFileInfo(docsPath.absolutePath() + QDir.separator() + f) |
220 namespace = QHelpEngineCore.namespaceName(str(f.resolve())) |
228 namespace = QHelpEngineCore.namespaceName( |
|
229 fi.absoluteFilePath()) |
|
230 if not namespace: |
221 if not namespace: |
231 continue |
222 continue |
232 |
223 |
233 if ( |
224 if ( |
234 dt.isValid() and |
225 dt is not None and |
235 namespace in engine.registeredDocumentations() and |
226 namespace in engine.registeredDocumentations() and |
236 (fi.lastModified().toString(Qt.DateFormat.ISODate) == |
227 (datetime.datetime.fromtimestamp(f.stat().st_mtime) == |
237 dt.toString(Qt.DateFormat.ISODate)) and |
228 dt) and |
238 qchFile == fi.absoluteFilePath() |
229 qchFile == str(f.resolve()) |
239 ): |
230 ): |
240 return False |
231 return False |
241 |
232 |
242 if namespace in engine.registeredDocumentations(): |
233 if namespace in engine.registeredDocumentations(): |
243 engine.unregisterDocumentation(namespace) |
234 engine.unregisterDocumentation(namespace) |
244 |
235 |
245 if not engine.registerDocumentation(fi.absoluteFilePath()): |
236 if not engine.registerDocumentation(str(f.resolve())): |
246 self.errorMessage.emit( |
237 self.errorMessage.emit( |
247 self.tr( |
238 self.tr( |
248 """<p>The file <b>{0}</b> could not be""" |
239 """<p>The file <b>{0}</b> could not be""" |
249 """ registered. <br/>Reason: {1}</p>""") |
240 """ registered. <br/>Reason: {1}</p>""") |
250 .format(fi.absoluteFilePath, engine.error()) |
241 .format(f, engine.error()) |
251 ) |
242 ) |
252 return False |
243 return False |
253 |
244 |
254 engine.setCustomValue( |
245 engine.setCustomValue( |
255 versionKey, |
246 versionKey, |
256 fi.lastModified().toString(Qt.DateFormat.ISODate) + '|' + |
247 datetime.datetime.fromtimestamp(f.stat().st_mtime) |
257 fi.absoluteFilePath()) |
248 .isoformat() + '|' + str(f.resolve())) |
258 return True |
249 return True |
259 |
250 |
260 return False |
251 return False |