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