E5XML/SessionWriter.py

changeset 411
99409cddaaa9
parent 229
fa7024a3cd58
child 599
ee87fe94bf96
equal deleted inserted replaced
410:e5d1addeb90c 411:99409cddaaa9
43 """ 43 """
44 isGlobal = self.name is None 44 isGlobal = self.name is None
45 45
46 XMLWriterBase.writeXML(self) 46 XMLWriterBase.writeXML(self)
47 47
48 self._write('<!DOCTYPE Session SYSTEM "Session-%s.dtd">' % \ 48 self._write('<!DOCTYPE Session SYSTEM "Session-{0}.dtd">'.format(
49 sessionFileFormatVersion) 49 sessionFileFormatVersion))
50 50
51 # add some generation comments 51 # add some generation comments
52 if not isGlobal: 52 if not isGlobal:
53 self._write("<!-- eric5 session file for project %s -->" % self.name) 53 self._write("<!-- eric5 session file for project {0} -->".format(self.name))
54 self._write("<!-- This file was generated automatically, do not edit. -->") 54 self._write("<!-- This file was generated automatically, do not edit. -->")
55 if Preferences.getProject("XMLTimestamp") or isGlobal: 55 if Preferences.getProject("XMLTimestamp") or isGlobal:
56 self._write("<!-- Saved: %s -->" % time.strftime('%Y-%m-%d, %H:%M:%S')) 56 self._write("<!-- Saved: {0} -->".format(time.strftime('%Y-%m-%d, %H:%M:%S')))
57 57
58 # add the main tag 58 # add the main tag
59 self._write('<Session version="%s">' % sessionFileFormatVersion) 59 self._write('<Session version="{0}">'.format(sessionFileFormatVersion))
60 60
61 # step 0: save open multi project and project for the global session 61 # step 0: save open multi project and project for the global session
62 if isGlobal: 62 if isGlobal:
63 if self.multiProject.isOpen(): 63 if self.multiProject.isOpen():
64 self._write(' <MultiProject>%s</MultiProject>' % \ 64 self._write(' <MultiProject>{0}</MultiProject>'.format(
65 self.multiProject.getMultiProjectFile()) 65 self.multiProject.getMultiProjectFile()))
66 if self.project.isOpen(): 66 if self.project.isOpen():
67 self._write(' <Project>%s</Project>' % \ 67 self._write(' <Project>{0}</Project>'.format(
68 self.project.getProjectFile()) 68 self.project.getProjectFile()))
69 69
70 # step 1: save all open (project) filenames and the active window 70 # step 1: save all open (project) filenames and the active window
71 allOpenFiles = self.vm.getOpenFilenames() 71 allOpenFiles = self.vm.getOpenFilenames()
72 self._write(" <Filenames>") 72 self._write(" <Filenames>")
73 for of in allOpenFiles: 73 for of in allOpenFiles:
79 zoom = ed.getZoom() 79 zoom = ed.getZoom()
80 else: 80 else:
81 line, index = 0, 0 81 line, index = 0, 0
82 folds = '' 82 folds = ''
83 zoom = -9999 83 zoom = -9999
84 self._write(' <Filename cline="%d" cindex="%d" folds="%s" zoom="%d">' 84 self._write(
85 '%s</Filename>' % \ 85 ' <Filename cline="{0:d}" cindex="{1:d}" folds="{2}" zoom="{3:d}">'
86 (line, index, folds, zoom, of)) 86 '{4}</Filename>'.format(line, index, folds, zoom, of))
87 self._write(" </Filenames>") 87 self._write(" </Filenames>")
88 88
89 aw = self.vm.getActiveName() 89 aw = self.vm.getActiveName()
90 if aw and aw.startswith(self.project.ppath): 90 if aw and aw.startswith(self.project.ppath):
91 ed = self.vm.getOpenEditor(aw) 91 ed = self.vm.getOpenEditor(aw)
92 if ed is not None: 92 if ed is not None:
93 line, index = ed.getCursorPosition() 93 line, index = ed.getCursorPosition()
94 else: 94 else:
95 line, index = 0, 0 95 line, index = 0, 0
96 self._write(' <ActiveWindow cline="%d" cindex="%d">%s</ActiveWindow>' % \ 96 self._write(' <ActiveWindow cline="{0:d}" cindex="{1:d}">{2}</ActiveWindow>'\
97 (line, index, aw)) 97 .format(line, index, aw))
98 98
99 # step 2a: save all breakpoints 99 # step 2a: save all breakpoints
100 allBreaks = Preferences.getProject("SessionAllBreakpoints") 100 allBreaks = Preferences.getProject("SessionAllBreakpoints")
101 projectFiles = self.project.getSources(True) 101 projectFiles = self.project.getSources(True)
102 bpModel = self.dbs.getBreakPointModel() 102 bpModel = self.dbs.getBreakPointModel()
105 index = bpModel.index(row, 0) 105 index = bpModel.index(row, 0)
106 fname, lineno, cond, temp, enabled, count = \ 106 fname, lineno, cond, temp, enabled, count = \
107 bpModel.getBreakPointByIndex(index)[:6] 107 bpModel.getBreakPointByIndex(index)[:6]
108 if isGlobal or allBreaks or fname in projectFiles: 108 if isGlobal or allBreaks or fname in projectFiles:
109 self._write(" <Breakpoint>") 109 self._write(" <Breakpoint>")
110 self._write(" <BpFilename>%s</BpFilename>" % fname) 110 self._write(" <BpFilename>{0}</BpFilename>".format(fname))
111 self._write(' <Linenumber value="%d" />' % lineno) 111 self._write(' <Linenumber value="{0:d}" />'.format(lineno))
112 self._write(" <Condition>%s</Condition>" % self.escape(str(cond))) 112 self._write(" <Condition>{0}</Condition>".format(
113 self._write(' <Temporary value="%s" />' % temp) 113 self.escape(str(cond))))
114 self._write(' <Enabled value="%s" />' % enabled) 114 self._write(' <Temporary value="{0}" />'.format(temp))
115 self._write(' <Count value="%d" />' % count) 115 self._write(' <Enabled value="{0}" />'.format(enabled))
116 self._write(' <Count value="{0:d}" />'.format(count))
116 self._write(" </Breakpoint>") 117 self._write(" </Breakpoint>")
117 self._write(" </Breakpoints>") 118 self._write(" </Breakpoints>")
118 119
119 # step 2b: save all watch expressions 120 # step 2b: save all watch expressions
120 self._write(" <Watchexpressions>") 121 self._write(" <Watchexpressions>")
121 wpModel = self.dbs.getWatchPointModel() 122 wpModel = self.dbs.getWatchPointModel()
122 for row in range(wpModel.rowCount()): 123 for row in range(wpModel.rowCount()):
123 index = wpModel.index(row, 0) 124 index = wpModel.index(row, 0)
124 cond, temp, enabled, count, special = wpModel.getWatchPointByIndex(index)[:5] 125 cond, temp, enabled, count, special = wpModel.getWatchPointByIndex(index)[:5]
125 self._write(' <Watchexpression>') 126 self._write(' <Watchexpression>')
126 self._write(" <Condition>%s</Condition>" % self.escape(str(cond))) 127 self._write(" <Condition>{0}</Condition>".format(self.escape(str(cond))))
127 self._write(' <Temporary value="%s" />' % temp) 128 self._write(' <Temporary value="{0}" />'.format(temp))
128 self._write(' <Enabled value="%s" />' % enabled) 129 self._write(' <Enabled value="{0}" />'.format(enabled))
129 self._write(' <Count value="%d" />' % count) 130 self._write(' <Count value="{0:d}" />'.format(count))
130 self._write(' <Special>%s</Special>' % special) 131 self._write(' <Special>{0}</Special>'.format(special))
131 self._write(' </Watchexpression>') 132 self._write(' </Watchexpression>')
132 self._write(' </Watchexpressions>') 133 self._write(' </Watchexpressions>')
133 134
134 # step 3: save the debug info 135 # step 3: save the debug info
135 self._write(" <DebugInfo>") 136 self._write(" <DebugInfo>")
144 dbgWd = "" 145 dbgWd = ""
145 if len(self.dbg.envHistory): 146 if len(self.dbg.envHistory):
146 dbgEnv = self.dbg.envHistory[0] 147 dbgEnv = self.dbg.envHistory[0]
147 else: 148 else:
148 dbgEnv = "" 149 dbgEnv = ""
149 self._write(" <CommandLine>%s</CommandLine>" % self.escape(dbgCmdline)) 150 self._write(" <CommandLine>{0}</CommandLine>"\
150 self._write(" <WorkingDirectory>%s</WorkingDirectory>" % dbgWd) 151 .format(self.escape(dbgCmdline)))
151 self._write(" <Environment>%s</Environment>" % dbgEnv) 152 self._write(" <WorkingDirectory>{0}</WorkingDirectory>".format(dbgWd))
152 self._write(' <ReportExceptions value="%s" />' % self.dbg.exceptions) 153 self._write(" <Environment>{0}</Environment>".format(dbgEnv))
154 self._write(' <ReportExceptions value="{0}" />'\
155 .format(self.dbg.exceptions))
153 self._write(" <Exceptions>") 156 self._write(" <Exceptions>")
154 for exc in self.dbg.excList: 157 for exc in self.dbg.excList:
155 self._write(" <Exception>%s</Exception>" % exc) 158 self._write(" <Exception>{0}</Exception>".format(exc))
156 self._write(" </Exceptions>") 159 self._write(" </Exceptions>")
157 self._write(" <IgnoredExceptions>") 160 self._write(" <IgnoredExceptions>")
158 for iexc in self.dbg.excIgnoreList: 161 for iexc in self.dbg.excIgnoreList:
159 self._write(" <IgnoredException>%s</IgnoredException>" % iexc) 162 self._write(" <IgnoredException>{0}</IgnoredException>".format(iexc))
160 self._write(" </IgnoredExceptions>") 163 self._write(" </IgnoredExceptions>")
161 self._write(' <AutoClearShell value="%s" />' % self.dbg.autoClearShell) 164 self._write(' <AutoClearShell value="{0}" />'\
162 self._write(' <TracePython value="%s" />' % self.dbg.tracePython) 165 .format(self.dbg.autoClearShell))
163 self._write(' <AutoContinue value="%s" />' % self.dbg.autoContinue) 166 self._write(' <TracePython value="{0}" />'.format(self.dbg.tracePython))
167 self._write(' <AutoContinue value="{0}" />'.format(self.dbg.autoContinue))
164 self._write(" <CovexcPattern></CovexcPattern>") # kept for compatibility 168 self._write(" <CovexcPattern></CovexcPattern>") # kept for compatibility
165 else: 169 else:
166 self._write(" <CommandLine>%s</CommandLine>" % \ 170 self._write(" <CommandLine>{0}</CommandLine>".format(
167 self.escape(str(self.project.dbgCmdline))) 171 self.escape(str(self.project.dbgCmdline))))
168 self._write(" <WorkingDirectory>%s</WorkingDirectory>" % \ 172 self._write(" <WorkingDirectory>{0}</WorkingDirectory>".format(
169 self.project.dbgWd) 173 self.project.dbgWd))
170 self._write(" <Environment>%s</Environment>" % \ 174 self._write(" <Environment>{0}</Environment>".format(
171 self.project.dbgEnv) 175 self.project.dbgEnv))
172 self._write(' <ReportExceptions value="%s" />' % \ 176 self._write(' <ReportExceptions value="{0}" />'.format(
173 self.project.dbgReportExceptions) 177 self.project.dbgReportExceptions))
174 self._write(" <Exceptions>") 178 self._write(" <Exceptions>")
175 for exc in self.project.dbgExcList: 179 for exc in self.project.dbgExcList:
176 self._write(" <Exception>%s</Exception>" % exc) 180 self._write(" <Exception>{0}</Exception>".format(exc))
177 self._write(" </Exceptions>") 181 self._write(" </Exceptions>")
178 self._write(" <IgnoredExceptions>") 182 self._write(" <IgnoredExceptions>")
179 for iexc in self.project.dbgExcIgnoreList: 183 for iexc in self.project.dbgExcIgnoreList:
180 self._write(" <IgnoredException>%s</IgnoredException>" % iexc) 184 self._write(" <IgnoredException>{0}</IgnoredException>".format(iexc))
181 self._write(" </IgnoredExceptions>") 185 self._write(" </IgnoredExceptions>")
182 self._write(' <AutoClearShell value="%s" />' % \ 186 self._write(' <AutoClearShell value="{0}" />'.format(
183 self.project.dbgAutoClearShell) 187 self.project.dbgAutoClearShell))
184 self._write(' <TracePython value="%s" />' % \ 188 self._write(' <TracePython value="{0}" />'.format(
185 self.project.dbgTracePython) 189 self.project.dbgTracePython))
186 self._write(' <AutoContinue value="%s" />' % \ 190 self._write(' <AutoContinue value="{0}" />'.format(
187 self.project.dbgAutoContinue) 191 self.project.dbgAutoContinue))
188 self._write(" <CovexcPattern></CovexcPattern>") # kept for compatibility 192 self._write(" <CovexcPattern></CovexcPattern>") # kept for compatibility
189 self._write(" </DebugInfo>") 193 self._write(" </DebugInfo>")
190 194
191 # step 4: save bookmarks of all open (project) files 195 # step 4: save bookmarks of all open (project) files
192 self._write(" <Bookmarks>") 196 self._write(" <Bookmarks>")
193 for of in allOpenFiles: 197 for of in allOpenFiles:
194 if isGlobal or of.startswith(self.project.ppath): 198 if isGlobal or of.startswith(self.project.ppath):
195 editor = self.vm.getOpenEditor(of) 199 editor = self.vm.getOpenEditor(of)
196 for bookmark in editor.getBookmarks(): 200 for bookmark in editor.getBookmarks():
197 self._write(" <Bookmark>") 201 self._write(" <Bookmark>")
198 self._write(" <BmFilename>%s</BmFilename>" % of) 202 self._write(" <BmFilename>{0}</BmFilename>".format(of))
199 self._write(' <Linenumber value="%d" />' % bookmark) 203 self._write(' <Linenumber value="{0:d}" />'.format(bookmark))
200 self._write(" </Bookmark>") 204 self._write(" </Bookmark>")
201 self._write(" </Bookmarks>") 205 self._write(" </Bookmarks>")
202 206
203 self._write("</Session>", newline = False) 207 self._write("</Session>", newline = False)

eric ide

mercurial