E5XML/SessionReader.py

changeset 599
ee87fe94bf96
child 791
9ec2ac20e54e
equal deleted inserted replaced
598:76c36b6ebbdb 599:ee87fe94bf96
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2010 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing a class for reading an XML session file.
8 """
9
10 from E5Gui.E5Application import e5App
11
12 from .Config import sessionFileFormatVersion
13 from .XMLStreamReaderBase import XMLStreamReaderBase
14
15 class SessionReader(XMLStreamReaderBase):
16 """
17 Class for reading an XML session file.
18 """
19 supportedVersions = ["4.3", "4.4"]
20
21 def __init__(self, device, isGlobal):
22 """
23 Constructor
24
25 @param device reference to the I/O device to read from (QIODevice)
26 @param isGlobal flag indicating to read the global session (boolean).
27 """
28 XMLStreamReaderBase.__init__(self, device)
29
30 self.version = ""
31 self.isGlobal = isGlobal
32
33 self.project = e5App().getObject("Project")
34 self.multiProject = e5App().getObject("MultiProject")
35 self.vm = e5App().getObject("ViewManager")
36 self.dbg = e5App().getObject("DebugUI")
37 self.dbs = e5App().getObject("DebugServer")
38
39 if not self.isGlobal:
40 # clear all breakpoints and bookmarks first
41 # (in case we are rereading a session file)
42 files = self.project.getSources(True)
43 for file in files:
44 editor = self.vm.getOpenEditor(file)
45 if editor is not None:
46 editor.clearBookmarks()
47 self.dbs.getBreakPointModel().deleteAll()
48 self.dbs.getWatchPointModel().deleteAll()
49
50 def readXML(self, quiet = False):
51 """
52 Public method to read and parse the XML document.
53
54 @param quiet flag indicating quiet operations.
55 If this flag is true, no errors are reported.
56 """
57 while not self.atEnd():
58 self.readNext()
59 if self.isStartElement():
60 if self.name() == "Session":
61 self.version = self.attribute("version", sessionFileFormatVersion)
62 if self.version not in self.supportedVersions:
63 self.raiseUnsupportedFormatVersion(self.version)
64 elif self.name() == "MultiProject":
65 self.multiProject.openMultiProject(self.readElementText(), False)
66 elif self.name() == "Project":
67 self.project.openProject(self.readElementText(), False)
68 elif self.name() == "Filenames":
69 self.__readFilenames()
70 elif self.name() == "ActiveWindow":
71 cline = int(self.attribute("cline", "0"))
72 cindex = int(self.attribute("cindex", "0"))
73 filename = self.readElementText()
74 self.vm.openFiles(filename)
75 ed = self.vm.getOpenEditor(filename)
76 if ed is not None:
77 ed.setCursorPosition(cline, cindex)
78 ed.ensureCursorVisible()
79 elif self.name() == "Breakpoints":
80 self.__readBreakpoints()
81 elif self.name() == "Watchexpressions":
82 self.__readWatchexpressions()
83 elif self.name() == "DebugInfo":
84 self.__readDebugInfo()
85 elif self.name() == "Bookmarks":
86 self.__readBookmarks()
87 else:
88 self.raiseUnexpectedStartTag(self.name())
89
90 if not quiet:
91 self.showErrorMessage()
92
93 def __readFilenames(self):
94 """
95 Private method to read the file name infos.
96 """
97 while not self.atEnd():
98 self.readNext()
99 if self.isEndElement() and self.name() == "Filenames":
100 break
101
102 if self.isStartElement():
103 if self.name() == "Filename":
104 cline = int(self.attribute("cline", "0"))
105 cindex = int(self.attribute("cindex", "0"))
106 folds = self.attribute("folds")
107 if folds:
108 folds = [int(f) for f in folds.split(',')]
109 else:
110 folds = []
111 zoom = int(self.attribute("zoom", "-9999"))
112 filename = self.readElementText()
113
114 self.vm.openFiles(filename)
115 ed = self.vm.getOpenEditor(filename)
116 if ed is not None:
117 if zoom > -9999:
118 ed.zoomTo(zoom)
119 if folds:
120 ed.recolor()
121 for line in folds:
122 ed.foldLine(line - 1)
123 ed.setCursorPosition(cline, cindex)
124 ed.ensureCursorVisible()
125 else:
126 self.raiseUnexpectedStartTag(self.name())
127
128 def __readBreakpoints(self):
129 """
130 Private method to read the break point infos.
131 """
132 while not self.atEnd():
133 self.readNext()
134 if self.isEndElement() and self.name() == "Breakpoints":
135 break
136
137 if self.isStartElement():
138 if self.name() == "Breakpoint":
139 self.__readBreakpoint()
140 else:
141 self.raiseUnexpectedStartTag(self.name())
142
143 def __readBreakpoint(self):
144 """
145 Private method to read the break point info.
146 """
147 filename = ""
148 lineno = 0
149 bpCond = ""
150 bpTemp = False
151 bpEnabled = True
152 bpCount = 0
153
154 while not self.atEnd():
155 self.readNext()
156 if self.isEndElement() and self.name() == "Breakpoint":
157 self.dbs.getBreakPointModel().addBreakPoint(filename, lineno,
158 (bpCond, bpTemp, bpEnabled, bpCount))
159 break
160
161 if self.isStartElement():
162 if self.name() == "BpFilename":
163 filename = self.readElementText()
164 elif self.name() == "Linenumber":
165 lineno = int(self.attribute("value", "0"))
166 elif self.name() == "Condition":
167 bpCond = self.readElementText()
168 if bpCond == 'None':
169 bpCond = ''
170 elif self.name() == "Temporary":
171 bpTemp = self.toBool(self.attribute("value", "False"))
172 elif self.name() == "Enabled":
173 bpEnabled = self.toBool(self.attribute("value", "True"))
174 elif self.name() == "Count":
175 bpCount = int(self.attribute("value", "0"))
176 else:
177 self.raiseUnexpectedStartTag(self.name())
178
179 def __readWatchexpressions(self):
180 """
181 Private method to read watch expression infos.
182 """
183 while not self.atEnd():
184 self.readNext()
185 if self.isEndElement() and self.name() == "Watchexpressions":
186 break
187
188 if self.isStartElement():
189 if self.name() == "Watchexpression":
190 self.__readWatchexpression()
191 else:
192 self.raiseUnexpectedStartTag(self.name())
193
194 def __readWatchexpression(self):
195 """
196 Private method to read the watch expression info.
197 """
198 weCond = ""
199 weTemp = False
200 weEnabled = True
201 weCount = 0
202 weSpecialCond = ""
203
204 while not self.atEnd():
205 self.readNext()
206 if self.isEndElement() and self.name() == "Watchexpression":
207 self.dbs.getWatchPointModel().addWatchPoint(weCond,
208 (weTemp, weEnabled, weCount, weSpecialCond))
209 break
210
211 if self.isStartElement():
212 if self.name() == "Condition":
213 weCond = self.readElementText()
214 if weCond == 'None':
215 weCond = ''
216 elif self.name() == "Temporary":
217 weTemp = self.toBool(self.attribute("value", "False"))
218 elif self.name() == "Enabled":
219 weEnabled = self.toBool(self.attribute("value", "True"))
220 elif self.name() == "Count":
221 weCount = int(self.attribute("value", "0"))
222 elif self.name() == "Special":
223 weSpecialCond = self.readElementText()
224 else:
225 self.raiseUnexpectedStartTag(self.name())
226
227 def __readDebugInfo(self):
228 """
229 Private method to read the debug infos.
230 """
231 dbgExcList = []
232 dbgExcIgnoreList = []
233
234 while not self.atEnd():
235 self.readNext()
236 if self.isEndElement():
237 if self.name() == "DebugInfo":
238 break
239 elif self.name() == "Exceptions":
240 self.dbg.setExcList(dbgExcList)
241 if not self.isGlobal:
242 self.project.dbgExcList = dbgExcList[:]
243 elif self.name() == "IgnoredExceptions":
244 self.dbg.setExcIgnoreList(dbgExcIgnoreList)
245 if not self.isGlobal:
246 self.project.dbgExcIgnoreList = dbgExcIgnoreList[:]
247
248 if self.isStartElement():
249 if self.name() == "CommandLine":
250 txt = self.readElementText()
251 self.dbg.setArgvHistory(txt)
252 if not self.isGlobal:
253 self.project.dbgCmdline = txt
254 elif self.name() == "WorkingDirectory":
255 txt = self.readElementText()
256 self.dbg.setWdHistory(txt)
257 if not self.isGlobal:
258 self.project.dbgWd = txt
259 elif self.name() == "Environment":
260 txt = self.readElementText()
261 self.dbg.setEnvHistory(txt)
262 if not self.isGlobal:
263 self.project.dbgEnv = txt
264 elif self.name() == "ReportExceptions":
265 exc = self.toBool(self.attribute("value", "True"))
266 self.dbg.setExceptionReporting(exc)
267 if not self.isGlobal:
268 self.project.dbgReportExceptions = exc
269 elif self.name() == "Exceptions":
270 pass # ignore this start tag
271 elif self.name() == "Exception":
272 dbgExcList.append(self.readElementText())
273 elif self.name() == "IgnoredExceptions":
274 pass # ignore this start tag
275 elif self.name() == "IgnoredException":
276 dbgExcIgnoreList.append(self.readElementText())
277 elif self.name() == "AutoClearShell":
278 val = self.toBool(self.attribute("value"))
279 self.dbg.setAutoClearShell(val)
280 if not self.isGlobal:
281 self.project.dbgAutoClearShell = val
282 elif self.name() == "TracePython":
283 val = self.toBool(self.attribute("value"))
284 self.dbg.setTracePython(val)
285 if not self.isGlobal:
286 self.project.dbgTracePython = val
287 elif self.name() == "AutoContinue":
288 val = self.toBool(self.attribute("value"))
289 self.dbg.setAutoContinue(val)
290 if not self.isGlobal:
291 self.project.dbgAutoContinue = val
292 elif self.name() == "CovexcPattern":
293 pass # ignore this start tag
294 else:
295 self.raiseUnexpectedStartTag(self.name())
296
297 def __readBookmarks(self):
298 """
299 Private method to read the bookmark infos.
300 """
301 while not self.atEnd():
302 self.readNext()
303 if self.isEndElement() and self.name() == "Bookmarks":
304 break
305
306 if self.isStartElement():
307 if self.name() == "Bookmark":
308 self.__readBookmark()
309 else:
310 self.raiseUnexpectedStartTag(self.name())
311
312 def __readBookmark(self):
313 """
314 Private method to read the bookmark info.
315 """
316 filename = ""
317 lineno = 0
318
319 while not self.atEnd():
320 self.readNext()
321 if self.isEndElement() and self.name() == "Bookmark":
322 editor = self.vm.getOpenEditor(filename)
323 if editor is not None:
324 editor.toggleBookmark(lineno)
325 break
326
327 if self.isStartElement():
328 if self.name() == "BmFilename":
329 filename = self.readElementText()
330 elif self.name() == "Linenumber":
331 lineno = int(self.attribute("value", "0"))
332 else:
333 self.raiseUnexpectedStartTag(self.name())

eric ide

mercurial