E5XML/PluginRepositoryReader.py

Sat, 11 Sep 2010 19:00:54 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 11 Sep 2010 19:00:54 +0200
changeset 589
a9a4620f6767
parent 582
6b19bd357000
child 590
beb60b9b3d8d
permissions
-rw-r--r--

Added code to handle unexpected start tags to the new XML readers.

580
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
2
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
3 # Copyright (c) 2010 Detlev Offenbach <detlev@die-offenbachs.de>
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
4 #
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
5
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
6 """
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
7 Module to read the plug-in repository contents file.
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
8 """
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
9
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
10 from .Config import pluginRepositoryFileFormatVersion
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
11 from .XMLStreamReaderBase import XMLStreamReaderBase
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 import Preferences
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
14
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
15 class PluginRepositoryReader(XMLStreamReaderBase):
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16 """
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
17 Class to read the plug-in repository contents file.
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 """
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 def __init__(self, device, dlg):
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 """
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
21 Constructor
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
22
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
23 @param device reference to the I/O device to read from (QIODevice)
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
24 @param dlg reference to the plug-in repository dialog
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
25 """
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
26 XMLStreamReaderBase.__init__(self, device)
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
27
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
28 self.dlg = dlg
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
29
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
30 self.version = ""
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
31
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
32 def readXML(self):
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33 """
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
34 Public method to read and parse the XML document.
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
35 """
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
36 while not self.atEnd():
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37 self.readNext()
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 if self.isStartElement():
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 if self.name() == "Plugins":
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 self.version = self.attribute("version",
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
41 pluginRepositoryFileFormatVersion)
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 elif self.name() == "RepositoryUrl":
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 url = self.readElementText()
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 Preferences.setUI("PluginRepositoryUrl5", url)
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 elif self.name() == "Plugin":
582
6b19bd357000 Streamlined the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 580
diff changeset
46 self.__readPlugin()
589
a9a4620f6767 Added code to handle unexpected start tags to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 582
diff changeset
47 else:
a9a4620f6767 Added code to handle unexpected start tags to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 582
diff changeset
48 self._skipUnknownElement()
580
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
49
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
50 self.showErrorMessage()
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51
582
6b19bd357000 Streamlined the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 580
diff changeset
52 def __readPlugin(self):
580
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 """
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 Private method to read the plug-in info.
582
6b19bd357000 Streamlined the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 580
diff changeset
55 """
6b19bd357000 Streamlined the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 580
diff changeset
56 pluginInfo = {"name" : "",
6b19bd357000 Streamlined the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 580
diff changeset
57 "short" : "",
6b19bd357000 Streamlined the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 580
diff changeset
58 "description" : "",
6b19bd357000 Streamlined the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 580
diff changeset
59 "url" : "",
6b19bd357000 Streamlined the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 580
diff changeset
60 "author" : "",
6b19bd357000 Streamlined the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 580
diff changeset
61 "version" : "",
6b19bd357000 Streamlined the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 580
diff changeset
62 "filename" : "",
6b19bd357000 Streamlined the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 580
diff changeset
63 }
6b19bd357000 Streamlined the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 580
diff changeset
64 pluginInfo["status"] = self.attribute("status", "unknown")
580
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
65
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
66 while not self.atEnd():
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
67 self.readNext()
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
68 if self.isEndElement() and self.name() == "Plugin":
582
6b19bd357000 Streamlined the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 580
diff changeset
69 self.dlg.addEntry(pluginInfo["name"], pluginInfo["short"],
6b19bd357000 Streamlined the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 580
diff changeset
70 pluginInfo["description"], pluginInfo["url"],
6b19bd357000 Streamlined the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 580
diff changeset
71 pluginInfo["author"], pluginInfo["version"],
6b19bd357000 Streamlined the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 580
diff changeset
72 pluginInfo["filename"], pluginInfo["status"])
6b19bd357000 Streamlined the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 580
diff changeset
73 break
580
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
74
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
75 if self.isStartElement():
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 if self.name() == "Name":
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 pluginInfo["name"] = self.readElementText()
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
78 elif self.name() == "Short":
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
79 pluginInfo["short"] = self.readElementText()
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
80 elif self.name() == "Description":
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
81 txt = self.readElementText()
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
82 pluginInfo["description"] = \
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
83 [line.strip() for line in txt.splitlines()]
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84 elif self.name() == "Url":
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 pluginInfo["url"] = self.readElementText()
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 elif self.name() == "Author":
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 pluginInfo["author"] = self.readElementText()
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 elif self.name() == "Version":
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 pluginInfo["version"] = self.readElementText()
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 elif self.name() == "Filename":
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 pluginInfo["filename"] = self.readElementText()
589
a9a4620f6767 Added code to handle unexpected start tags to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 582
diff changeset
92 else:
a9a4620f6767 Added code to handle unexpected start tags to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 582
diff changeset
93 self.raiseUnexpectedStartTag(self.name())

eric ide

mercurial