|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2005 - 2010 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the handler class for reading an XML tasks file. |
|
8 """ |
|
9 |
|
10 from .Config import pluginRepositoryFileFormatVersion |
|
11 from .XMLHandlerBase import XMLHandlerBase |
|
12 |
|
13 import Preferences |
|
14 |
|
15 class PluginRepositoryHandler(XMLHandlerBase): |
|
16 """ |
|
17 Class implementing a sax handler to read an XML tasks file. |
|
18 """ |
|
19 def __init__(self, parent): |
|
20 """ |
|
21 Constructor |
|
22 |
|
23 @param parent reference to the parent dialog (PluginRepositoryDialog) |
|
24 """ |
|
25 XMLHandlerBase.__init__(self) |
|
26 |
|
27 self.startDocumentSpecific = self.startDocumentPlugins |
|
28 |
|
29 self.elements.update({ |
|
30 'Plugins' : (self.startPlugins, self.defaultEndElement), |
|
31 'Plugin' : (self.startPlugin, self.endPlugin), |
|
32 'Name' : (self.defaultStartElement, self.endName), |
|
33 'Short' : (self.defaultStartElement, self.endShort), |
|
34 'Description' : (self.defaultStartElement, self.endDescription), |
|
35 'Url' : (self.defaultStartElement, self.endUrl), |
|
36 'Author' : (self.defaultStartElement, self.endAuthor), |
|
37 'Version' : (self.defaultStartElement, self.endVersion), |
|
38 'Filename' : (self.defaultStartElement, self.endFilename), |
|
39 'RepositoryUrl' : (self.defaultStartElement, self.endRepositoryUrl), |
|
40 }) |
|
41 |
|
42 self.parent = parent |
|
43 |
|
44 def startDocumentPlugins(self): |
|
45 """ |
|
46 Handler called, when the document parsing is started. |
|
47 """ |
|
48 self.version = '' |
|
49 |
|
50 ################################################### |
|
51 ## below follow the individual handler functions |
|
52 ################################################### |
|
53 |
|
54 def startPlugins(self, attrs): |
|
55 """ |
|
56 Handler method for the "Plugins" start tag. |
|
57 |
|
58 @param attrs list of tag attributes |
|
59 """ |
|
60 self.version = attrs.get('version', pluginRepositoryFileFormatVersion) |
|
61 |
|
62 def startPlugin(self, attrs): |
|
63 """ |
|
64 Handler method for the "Plugin" start tag. |
|
65 |
|
66 @param attrs list of tag attributes |
|
67 """ |
|
68 self.info = {"name" : "", |
|
69 "short" : "", |
|
70 "description" : "", |
|
71 "url" : "", |
|
72 "author" : "", |
|
73 "version" : "", |
|
74 "filename" : "", |
|
75 } |
|
76 self.info["status"] = attrs.get("status", "unknown") |
|
77 |
|
78 def endPlugin(self): |
|
79 """ |
|
80 Handler method for the "Plugin" end tag. |
|
81 """ |
|
82 self.parent.addEntry(self.info["name"], self.info["short"], |
|
83 self.info["description"], self.info["url"], |
|
84 self.info["author"], self.info["version"], |
|
85 self.info["filename"], self.info["status"]) |
|
86 |
|
87 def endName(self): |
|
88 """ |
|
89 Handler method for the "Name" end tag. |
|
90 """ |
|
91 self.info["name"] = self.unescape(self.buffer) |
|
92 |
|
93 def endShort(self): |
|
94 """ |
|
95 Handler method for the "Short" end tag. |
|
96 """ |
|
97 self.info["short"] = self.unescape(self.buffer) |
|
98 |
|
99 def endDescription(self): |
|
100 """ |
|
101 Handler method for the "Description" end tag. |
|
102 """ |
|
103 txt = self.unescape(self.buffer) |
|
104 self.info["description"] = [line.strip() for line in txt.splitlines()] |
|
105 |
|
106 def endUrl(self): |
|
107 """ |
|
108 Handler method for the "Url" end tag. |
|
109 """ |
|
110 self.info["url"] = self.unescape(self.buffer) |
|
111 |
|
112 def endAuthor(self): |
|
113 """ |
|
114 Handler method for the "Author" end tag. |
|
115 """ |
|
116 self.info["author"] = self.unescape(self.buffer) |
|
117 |
|
118 def endVersion(self): |
|
119 """ |
|
120 Handler method for the "Version" end tag. |
|
121 """ |
|
122 self.info["version"] = self.unescape(self.buffer) |
|
123 |
|
124 def endFilename(self): |
|
125 """ |
|
126 Handler method for the "Filename" end tag. |
|
127 """ |
|
128 self.info["filename"] = self.unescape(self.buffer) |
|
129 |
|
130 def endRepositoryUrl(self): |
|
131 """ |
|
132 Handler method for the "RepositoryUrl" end tag. |
|
133 """ |
|
134 url = self.unescape(self.buffer).strip() |
|
135 Preferences.setUI("PluginRepositoryUrl5", url) |
|
136 |
|
137 def getVersion(self): |
|
138 """ |
|
139 Public method to retrieve the version of the tasks file. |
|
140 |
|
141 @return String containing the version number. |
|
142 """ |
|
143 return self.version |