E5XML/SessionWriter.py

changeset 50
a36eecf45b2e
parent 15
f6ccc31d6e72
child 53
c3eb7cc1ff8b
equal deleted inserted replaced
49:f991944e859c 50:a36eecf45b2e
1 # -*- coding: utf-8 -*-
2
3 # Copyright (c) 2004 - 2010 Detlev Offenbach <detlev@die-offenbachs.de>
4 #
5
6 """
7 Module implementing the writer class for writing an XML project session file.
8 """
9
10 import os
11 import time
12
13 from E4Gui.E4Application import e4App
14
15 from .XMLWriterBase import XMLWriterBase
16 from .Config import sessionFileFormatVersion
17
18 import Preferences
19
20 class SessionWriter(XMLWriterBase):
21 """
22 Class implementing the writer class for writing an XML project session file.
23 """
24 def __init__(self, file, projectName):
25 """
26 Constructor
27
28 @param file open file (like) object for writing
29 @param projectName name of the project (string) or None for the
30 global session
31 """
32 XMLWriterBase.__init__(self, file)
33
34 self.name = projectName
35 self.project = e4App().getObject("Project")
36 self.multiProject = e4App().getObject("MultiProject")
37 self.vm = e4App().getObject("ViewManager")
38 self.dbg = e4App().getObject("DebugUI")
39 self.dbs = e4App().getObject("DebugServer")
40
41 def writeXML(self):
42 """
43 Public method to write the XML to the file.
44 """
45 isGlobal = self.name is None
46
47 XMLWriterBase.writeXML(self)
48
49 self._write('<!DOCTYPE Session SYSTEM "Session-%s.dtd">' % \
50 sessionFileFormatVersion)
51
52 # add some generation comments
53 if not isGlobal:
54 self._write("<!-- eric5 session file for project %s -->" % self.name)
55 self._write("<!-- This file was generated automatically, do not edit. -->")
56 if Preferences.getProject("XMLTimestamp") or isGlobal:
57 self._write("<!-- Saved: %s -->" % time.strftime('%Y-%m-%d, %H:%M:%S'))
58
59 # add the main tag
60 self._write('<Session version="%s">' % sessionFileFormatVersion)
61
62 # step 0: save open multi project and project for the global session
63 if isGlobal:
64 if self.multiProject.isOpen():
65 self._write(' <MultiProject>%s</MultiProject>' % \
66 self.multiProject.getMultiProjectFile())
67 if self.project.isOpen():
68 self._write(' <Project>%s</Project>' % \
69 self.project.getProjectFile())
70
71 # step 1: save all open (project) filenames and the active window
72 allOpenFiles = self.vm.getOpenFilenames()
73 self._write(" <Filenames>")
74 for of in allOpenFiles:
75 if isGlobal or of.startswith(self.project.ppath):
76 ed = self.vm.getOpenEditor(of)
77 if ed is not None:
78 line, index = ed.getCursorPosition()
79 folds = ','.join([str(i + 1) for i in ed.getFolds()])
80 else:
81 line, index = 0, 0
82 folds = ''
83 self._write(' <Filename cline="%d" cindex="%d" folds="%s">%s</Filename>' % \
84 (line, index, folds, of))
85 self._write(" </Filenames>")
86
87 aw = self.vm.getActiveName()
88 if aw and aw.startswith(self.project.ppath):
89 ed = self.vm.getOpenEditor(aw)
90 if ed is not None:
91 line, index = ed.getCursorPosition()
92 else:
93 line, index = 0, 0
94 self._write(' <ActiveWindow cline="%d" cindex="%d">%s</ActiveWindow>' % \
95 (line, index, aw))
96
97 # step 2a: save all breakpoints
98 allBreaks = Preferences.getProject("SessionAllBreakpoints")
99 projectFiles = self.project.getSources(True)
100 bpModel = self.dbs.getBreakPointModel()
101 self._write(" <Breakpoints>")
102 for row in range(bpModel.rowCount()):
103 index = bpModel.index(row, 0)
104 fname, lineno, cond, temp, enabled, count = \
105 bpModel.getBreakPointByIndex(index)[:6]
106 if isGlobal or allBreaks or fname in projectFiles:
107 self._write(" <Breakpoint>")
108 self._write(" <BpFilename>%s</BpFilename>" % fname)
109 self._write(' <Linenumber value="%d" />' % lineno)
110 self._write(" <Condition>%s</Condition>" % self.escape(str(cond)))
111 self._write(' <Temporary value="%s" />' % temp)
112 self._write(' <Enabled value="%s" />' % enabled)
113 self._write(' <Count value="%d" />' % count)
114 self._write(" </Breakpoint>")
115 self._write(" </Breakpoints>")
116
117 # step 2b: save all watch expressions
118 self._write(" <Watchexpressions>")
119 wpModel = self.dbs.getWatchPointModel()
120 for row in range(wpModel.rowCount()):
121 index = wpModel.index(row, 0)
122 cond, temp, enabled, count, special = wpModel.getWatchPointByIndex(index)[:5]
123 self._write(' <Watchexpression>')
124 self._write(" <Condition>%s</Condition>" % self.escape(str(cond)))
125 self._write(' <Temporary value="%s" />' % temp)
126 self._write(' <Enabled value="%s" />' % enabled)
127 self._write(' <Count value="%d" />' % count)
128 self._write(' <Special>%s</Special>' % special)
129 self._write(' </Watchexpression>')
130 self._write(' </Watchexpressions>')
131
132 # step 3: save the debug info
133 self._write(" <DebugInfo>")
134 if isGlobal:
135 if len(self.dbg.argvHistory):
136 dbgCmdline = str(self.dbg.argvHistory[0])
137 else:
138 dbgCmdline = ""
139 if len(self.dbg.wdHistory):
140 dbgWd = self.dbg.wdHistory[0]
141 else:
142 dbgWd = ""
143 if len(self.dbg.envHistory):
144 dbgEnv = self.dbg.envHistory[0]
145 else:
146 dbgEnv = ""
147 self._write(" <CommandLine>%s</CommandLine>" % self.escape(dbgCmdline))
148 self._write(" <WorkingDirectory>%s</WorkingDirectory>" % dbgWd)
149 self._write(" <Environment>%s</Environment>" % dbgEnv)
150 self._write(' <ReportExceptions value="%s" />' % self.dbg.exceptions)
151 self._write(" <Exceptions>")
152 for exc in self.dbg.excList:
153 self._write(" <Exception>%s</Exception>" % exc)
154 self._write(" </Exceptions>")
155 self._write(" <IgnoredExceptions>")
156 for iexc in self.dbg.excIgnoreList:
157 self._write(" <IgnoredException>%s</IgnoredException>" % iexc)
158 self._write(" </IgnoredExceptions>")
159 self._write(' <AutoClearShell value="%s" />' % self.dbg.autoClearShell)
160 self._write(' <TracePython value="%s" />' % self.dbg.tracePython)
161 self._write(' <AutoContinue value="%s" />' % self.dbg.autoContinue)
162 self._write(" <CovexcPattern></CovexcPattern>") # kept for compatibility
163 else:
164 self._write(" <CommandLine>%s</CommandLine>" % \
165 self.escape(str(self.project.dbgCmdline)))
166 self._write(" <WorkingDirectory>%s</WorkingDirectory>" % \
167 self.project.dbgWd)
168 self._write(" <Environment>%s</Environment>" % \
169 self.project.dbgEnv)
170 self._write(' <ReportExceptions value="%s" />' % \
171 self.project.dbgReportExceptions)
172 self._write(" <Exceptions>")
173 for exc in self.project.dbgExcList:
174 self._write(" <Exception>%s</Exception>" % exc)
175 self._write(" </Exceptions>")
176 self._write(" <IgnoredExceptions>")
177 for iexc in self.project.dbgExcIgnoreList:
178 self._write(" <IgnoredException>%s</IgnoredException>" % iexc)
179 self._write(" </IgnoredExceptions>")
180 self._write(' <AutoClearShell value="%s" />' % \
181 self.project.dbgAutoClearShell)
182 self._write(' <TracePython value="%s" />' % \
183 self.project.dbgTracePython)
184 self._write(' <AutoContinue value="%s" />' % \
185 self.project.dbgAutoContinue)
186 self._write(" <CovexcPattern></CovexcPattern>") # kept for compatibility
187 self._write(" </DebugInfo>")
188
189 # step 4: save bookmarks of all open (project) files
190 self._write(" <Bookmarks>")
191 for of in allOpenFiles:
192 if isGlobal or of.startswith(self.project.ppath):
193 editor = self.vm.getOpenEditor(of)
194 for bookmark in editor.getBookmarks():
195 self._write(" <Bookmark>")
196 self._write(" <BmFilename>%s</BmFilename>" % of)
197 self._write(' <Linenumber value="%d" />' % bookmark)
198 self._write(" </Bookmark>")
199 self._write(" </Bookmarks>")
200
201 self._write("</Session>", newline = False)

eric ide

mercurial