|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2010 - 2021 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module to read the plug-in repository contents file. |
|
8 """ |
|
9 |
|
10 from .Config import pluginRepositoryFileFormatVersion |
|
11 from .XMLStreamReaderBase import XMLStreamReaderBase |
|
12 |
|
13 import Preferences |
|
14 |
|
15 |
|
16 class PluginRepositoryReader(XMLStreamReaderBase): |
|
17 """ |
|
18 Class to read the plug-in repository contents file. |
|
19 """ |
|
20 supportedVersions = ["4.1", "4.2"] |
|
21 |
|
22 def __init__(self, device, entryCallback): |
|
23 """ |
|
24 Constructor |
|
25 |
|
26 @param device reference to the I/O device to read from (QIODevice) |
|
27 @param entryCallback reference to a function to be called once the |
|
28 data for a plug-in has been read (function) |
|
29 """ |
|
30 XMLStreamReaderBase.__init__(self, device) |
|
31 |
|
32 self.__entryCallback = entryCallback |
|
33 |
|
34 self.version = "" |
|
35 |
|
36 def readXML(self): |
|
37 """ |
|
38 Public method to read and parse the XML document. |
|
39 """ |
|
40 while not self.atEnd(): |
|
41 self.readNext() |
|
42 if self.isStartElement(): |
|
43 if self.name() == "Plugins": |
|
44 self.version = self.attribute( |
|
45 "version", |
|
46 pluginRepositoryFileFormatVersion) |
|
47 if self.version not in self.supportedVersions: |
|
48 self.raiseUnsupportedFormatVersion(self.version) |
|
49 elif self.name() == "RepositoryUrl": |
|
50 url = self.readElementText() |
|
51 Preferences.setUI("PluginRepositoryUrl6", url) |
|
52 elif self.name() == "Plugin": |
|
53 self.__readPlugin() |
|
54 else: |
|
55 self._skipUnknownElement() |
|
56 |
|
57 self.showErrorMessage() |
|
58 |
|
59 def __readPlugin(self): |
|
60 """ |
|
61 Private method to read the plug-in info. |
|
62 """ |
|
63 pluginInfo = {"name": "", |
|
64 "short": "", |
|
65 "description": "", |
|
66 "url": "", |
|
67 "author": "", |
|
68 "version": "", |
|
69 "filename": "", |
|
70 } |
|
71 pluginInfo["status"] = self.attribute("status", "unknown") |
|
72 |
|
73 while not self.atEnd(): |
|
74 self.readNext() |
|
75 if self.isEndElement() and self.name() == "Plugin": |
|
76 self.__entryCallback( |
|
77 pluginInfo["name"], pluginInfo["short"], |
|
78 pluginInfo["description"], pluginInfo["url"], |
|
79 pluginInfo["author"], pluginInfo["version"], |
|
80 pluginInfo["filename"], pluginInfo["status"]) |
|
81 break |
|
82 |
|
83 if self.isStartElement(): |
|
84 if self.name() == "Name": |
|
85 pluginInfo["name"] = self.readElementText() |
|
86 elif self.name() == "Short": |
|
87 pluginInfo["short"] = self.readElementText() |
|
88 elif self.name() == "Description": |
|
89 txt = self.readElementText() |
|
90 pluginInfo["description"] = [ |
|
91 line.strip() for line in txt.splitlines() |
|
92 ] |
|
93 elif self.name() == "Url": |
|
94 pluginInfo["url"] = self.readElementText() |
|
95 elif self.name() == "Author": |
|
96 pluginInfo["author"] = self.readElementText() |
|
97 elif self.name() == "Version": |
|
98 pluginInfo["version"] = self.readElementText() |
|
99 elif self.name() == "Filename": |
|
100 pluginInfo["filename"] = self.readElementText() |
|
101 else: |
|
102 self.raiseUnexpectedStartTag(self.name()) |