E5XML/PluginRepositoryReader.py

Sat, 05 Jul 2014 11:41:14 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sat, 05 Jul 2014 11:41:14 +0200
changeset 3669
ac84ac3c0f05
parent 3178
f25fc1364c88
child 3676
2f62b060a931
permissions
-rw-r--r--

Continued renaming eric5 for PyQt5 to eric6.

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
3160
209a07d7e401 Updated copyright for 2014.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3113
diff changeset
3 # Copyright (c) 2010 - 2014 Detlev Offenbach <detlev@die-offenbachs.de>
580
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
3145
a9de05d4a22f # __IGNORE_WARNING__ added/ removed.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 3142
diff changeset
10 from __future__ import unicode_literals
2525
8b507a9a2d40 Script changes: Future import added, super calls modified and unicode behavior for str.
T.Rzepka <Tobias.Rzepka@gmail.com>
parents: 2302
diff changeset
11
580
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
12 from .Config import pluginRepositoryFileFormatVersion
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
13 from .XMLStreamReaderBase import XMLStreamReaderBase
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 import Preferences
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
16
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
17
580
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
18 class PluginRepositoryReader(XMLStreamReaderBase):
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
19 """
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
20 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
21 """
590
beb60b9b3d8d Added code to handle unsupported versions to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 589
diff changeset
22 supportedVersions = ["4.1", "4.2"]
beb60b9b3d8d Added code to handle unsupported versions to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 589
diff changeset
23
3113
2780e230f129 Continued implementing the automatic plug-in update check in the plug-in manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3035
diff changeset
24 def __init__(self, device, entryCallback):
580
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 Constructor
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 @param device reference to the I/O device to read from (QIODevice)
3113
2780e230f129 Continued implementing the automatic plug-in update check in the plug-in manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3035
diff changeset
29 @param entryCallback reference to a function to be called once the
2780e230f129 Continued implementing the automatic plug-in update check in the plug-in manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3035
diff changeset
30 data for a plug-in has been read (function)
580
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 XMLStreamReaderBase.__init__(self, device)
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
33
3113
2780e230f129 Continued implementing the automatic plug-in update check in the plug-in manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3035
diff changeset
34 self.__entryCallback = entryCallback
580
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 self.version = ""
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
37
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
38 def readXML(self):
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
39 """
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
40 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
41 """
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
42 while not self.atEnd():
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
43 self.readNext()
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
44 if self.isStartElement():
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
45 if self.name() == "Plugins":
3022
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
46 self.version = self.attribute(
57179e4cdadd Fixed a bunch of visible indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 2302
diff changeset
47 "version",
580
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
48 pluginRepositoryFileFormatVersion)
590
beb60b9b3d8d Added code to handle unsupported versions to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 589
diff changeset
49 if self.version not in self.supportedVersions:
beb60b9b3d8d Added code to handle unsupported versions to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 589
diff changeset
50 self.raiseUnsupportedFormatVersion(self.version)
580
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
51 elif self.name() == "RepositoryUrl":
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
52 url = self.readElementText()
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
53 Preferences.setUI("PluginRepositoryUrl5", url)
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
54 elif self.name() == "Plugin":
582
6b19bd357000 Streamlined the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 580
diff changeset
55 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
56 else:
a9a4620f6767 Added code to handle unexpected start tags to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 582
diff changeset
57 self._skipUnknownElement()
580
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
58
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
59 self.showErrorMessage()
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
60
582
6b19bd357000 Streamlined the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 580
diff changeset
61 def __readPlugin(self):
580
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
62 """
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
63 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
64 """
945
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
65 pluginInfo = {"name": "",
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
66 "short": "",
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
67 "description": "",
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
68 "url": "",
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
69 "author": "",
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
70 "version": "",
8cd4d08fa9f6 Made code mostly PEP 8 compliant (except all whitespace and line length).
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 791
diff changeset
71 "filename": "",
3035
36e9f388958b Fixed a bunch of indentation issues.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3022
diff changeset
72 }
582
6b19bd357000 Streamlined the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 580
diff changeset
73 pluginInfo["status"] = self.attribute("status", "unknown")
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 while not self.atEnd():
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
76 self.readNext()
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
77 if self.isEndElement() and self.name() == "Plugin":
3113
2780e230f129 Continued implementing the automatic plug-in update check in the plug-in manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3035
diff changeset
78 self.__entryCallback(
2780e230f129 Continued implementing the automatic plug-in update check in the plug-in manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3035
diff changeset
79 pluginInfo["name"], pluginInfo["short"],
2780e230f129 Continued implementing the automatic plug-in update check in the plug-in manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3035
diff changeset
80 pluginInfo["description"], pluginInfo["url"],
2780e230f129 Continued implementing the automatic plug-in update check in the plug-in manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3035
diff changeset
81 pluginInfo["author"], pluginInfo["version"],
2780e230f129 Continued implementing the automatic plug-in update check in the plug-in manager.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 3035
diff changeset
82 pluginInfo["filename"], pluginInfo["status"])
582
6b19bd357000 Streamlined the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 580
diff changeset
83 break
580
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
84
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
85 if self.isStartElement():
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
86 if self.name() == "Name":
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
87 pluginInfo["name"] = self.readElementText()
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
88 elif self.name() == "Short":
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
89 pluginInfo["short"] = self.readElementText()
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
90 elif self.name() == "Description":
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
91 txt = self.readElementText()
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
92 pluginInfo["description"] = \
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
93 [line.strip() for line in txt.splitlines()]
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
94 elif self.name() == "Url":
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
95 pluginInfo["url"] = self.readElementText()
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
96 elif self.name() == "Author":
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
97 pluginInfo["author"] = self.readElementText()
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
98 elif self.name() == "Version":
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
99 pluginInfo["version"] = self.readElementText()
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
100 elif self.name() == "Filename":
45c38566b001 Implemented the plug-in repository reader.
Detlev Offenbach <detlev@die-offenbachs.de>
parents:
diff changeset
101 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
102 else:
a9a4620f6767 Added code to handle unexpected start tags to the new XML readers.
Detlev Offenbach <detlev@die-offenbachs.de>
parents: 582
diff changeset
103 self.raiseUnexpectedStartTag(self.name())

eric ide

mercurial