|
1 # -*- coding: utf-8 -*- |
|
2 |
|
3 # Copyright (c) 2008 - 2010 Detlev Offenbach <detlev@die-offenbachs.de> |
|
4 # |
|
5 |
|
6 """ |
|
7 Module implementing the handler class for reading an XML multi project file. |
|
8 """ |
|
9 |
|
10 from .Config import multiProjectFileFormatVersion |
|
11 from .XMLHandlerBase import XMLHandlerBase |
|
12 |
|
13 import Utilities |
|
14 |
|
15 class MultiProjectHandler(XMLHandlerBase): |
|
16 """ |
|
17 Class implementing a sax handler to read an XML multi project file. |
|
18 """ |
|
19 def __init__(self, multiProject): |
|
20 """ |
|
21 Constructor |
|
22 |
|
23 @param multiProject Reference to the multi project object to store the |
|
24 information into. |
|
25 """ |
|
26 XMLHandlerBase.__init__(self) |
|
27 |
|
28 self.startDocumentSpecific = self.startDocumentMultiProject |
|
29 |
|
30 self.elements.update({ |
|
31 'MultiProject' : (self.startMultiProject, self.defaultEndElement), |
|
32 'Description' : (self.defaultStartElement, self.endDescription), |
|
33 'Project' : (self.startProject, self.endProject), |
|
34 'ProjectName' : (self.defaultStartElement, self.endProjectName), |
|
35 'ProjectFile' : (self.defaultStartElement, self.endProjectFile), |
|
36 'ProjectDescription' : (self.defaultStartElement, self.endProjectDescription), |
|
37 }) |
|
38 |
|
39 self.multiProject = multiProject |
|
40 |
|
41 def startDocumentMultiProject(self): |
|
42 """ |
|
43 Handler called, when the document parsing is started. |
|
44 """ |
|
45 self.version = '' |
|
46 |
|
47 ################################################### |
|
48 ## below follow the individual handler functions |
|
49 ################################################### |
|
50 |
|
51 def startMultiProject(self, attrs): |
|
52 """ |
|
53 Handler method for the "MultiProject" start tag. |
|
54 |
|
55 @param attrs list of tag attributes |
|
56 """ |
|
57 self.version = attrs.get('version', multiProjectFileFormatVersion) |
|
58 |
|
59 def endDescription(self): |
|
60 """ |
|
61 Handler method for the "Description" end tag. |
|
62 """ |
|
63 self.buffer = self.unescape(self.buffer) |
|
64 self.multiProject.description = self.decodedNewLines(self.buffer) |
|
65 |
|
66 def startProject(self, attrs): |
|
67 """ |
|
68 Handler method for the "Project" start tag. |
|
69 |
|
70 @param attrs list of tag attributes |
|
71 """ |
|
72 self.project = {} |
|
73 isMaster = attrs.get('isMaster', "False") |
|
74 self.project["master"] = isMaster == "True" |
|
75 |
|
76 def endProject(self): |
|
77 """ |
|
78 Handler method for the "Project" end tag. |
|
79 """ |
|
80 self.multiProject.projects.append(self.project) |
|
81 |
|
82 def endProjectName(self): |
|
83 """ |
|
84 Handler method for the "ProjectName" end tag. |
|
85 """ |
|
86 self.project["name"] = self.unescape(self.buffer) |
|
87 |
|
88 def endProjectFile(self): |
|
89 """ |
|
90 Handler method for the "ProjectFile" end tag. |
|
91 """ |
|
92 filename = self.buffer |
|
93 self.project["file"] = Utilities.toNativeSeparators(filename) |
|
94 |
|
95 def endProjectDescription(self): |
|
96 """ |
|
97 Handler method for the "ProjectDescription" end tag. |
|
98 """ |
|
99 self.buffer = self.unescape(self.buffer) |
|
100 self.project["description"] = self.decodedNewLines(self.buffer) |
|
101 |
|
102 def getVersion(self): |
|
103 """ |
|
104 Public method to retrieve the version of the project. |
|
105 |
|
106 @return String containing the version number. |
|
107 """ |
|
108 return self.version |
|
109 |