|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2010 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 class PluginRepositoryReader(XMLStreamReaderBase): |
|
16 """ |
|
17 Class to read the plug-in repository contents file. |
|
18 """ |
|
19 def __init__(self, device, dlg): |
|
20 """ |
|
21 Constructor |
|
22 |
|
23 @param device reference to the I/O device to read from (QIODevice) |
|
24 @param dlg reference to the plug-in repository dialog |
|
25 """ |
|
26 XMLStreamReaderBase.__init__(self, device) |
|
27 |
|
28 self.dlg = dlg |
|
29 |
|
30 self.version = "" |
|
31 |
|
32 def readXML(self): |
|
33 """ |
|
34 Public method to read and parse the XML document. |
|
35 """ |
|
36 while not self.atEnd(): |
|
37 self.readNext() |
|
38 if self.isStartElement(): |
|
39 if self.name() == "Plugins": |
|
40 self.version = self.attribute("version", |
|
41 pluginRepositoryFileFormatVersion) |
|
42 elif self.name() == "RepositoryUrl": |
|
43 url = self.readElementText() |
|
44 Preferences.setUI("PluginRepositoryUrl5", url) |
|
45 elif self.name() == "Plugin": |
|
46 info = {"name" : "", |
|
47 "short" : "", |
|
48 "description" : "", |
|
49 "url" : "", |
|
50 "author" : "", |
|
51 "version" : "", |
|
52 "filename" : "", |
|
53 } |
|
54 info["status"] = self.attribute("status", "unknown") |
|
55 self.__readPlugin(info) |
|
56 self.dlg.addEntry(info["name"], info["short"], |
|
57 info["description"], info["url"], |
|
58 info["author"], info["version"], |
|
59 info["filename"], info["status"]) |
|
60 |
|
61 self.showErrorMessage() |
|
62 |
|
63 def __readPlugin(self, pluginInfo): |
|
64 """ |
|
65 Private method to read the plug-in info. |
|
66 |
|
67 @param pluginInfo reference to the dictionary to hold the result |
|
68 @return reference to the populated dictionary |
|
69 """ |
|
70 while not self.atEnd(): |
|
71 self.readNext() |
|
72 if self.isEndElement() and self.name() == "Plugin": |
|
73 return pluginInfo |
|
74 |
|
75 if self.isStartElement(): |
|
76 if self.name() == "Name": |
|
77 pluginInfo["name"] = self.readElementText() |
|
78 elif self.name() == "Short": |
|
79 pluginInfo["short"] = self.readElementText() |
|
80 elif self.name() == "Description": |
|
81 txt = self.readElementText() |
|
82 pluginInfo["description"] = \ |
|
83 [line.strip() for line in txt.splitlines()] |
|
84 elif self.name() == "Url": |
|
85 pluginInfo["url"] = self.readElementText() |
|
86 elif self.name() == "Author": |
|
87 pluginInfo["author"] = self.readElementText() |
|
88 elif self.name() == "Version": |
|
89 pluginInfo["version"] = self.readElementText() |
|
90 elif self.name() == "Filename": |
|
91 pluginInfo["filename"] = self.readElementText() |