208 sessionData["CurrentWindowIndex"] = ( |
208 sessionData["CurrentWindowIndex"] = ( |
209 len(sessionData["Windows"]) - 1 |
209 len(sessionData["Windows"]) - 1 |
210 ) |
210 ) |
211 |
211 |
212 if sessionData["Windows"]: |
212 if sessionData["Windows"]: |
213 sessionFile = open(sessionFileName, "w") |
213 with open(sessionFileName, "w") as sessionFile: |
214 json.dump(sessionData, sessionFile, indent=2) |
214 json.dump(sessionData, sessionFile, indent=2) |
215 sessionFile.close() |
|
216 |
215 |
217 @classmethod |
216 @classmethod |
218 def readSessionFromFile(cls, sessionFileName): |
217 def readSessionFromFile(cls, sessionFileName): |
219 """ |
218 """ |
220 Class method to read the session data from a file. |
219 Class method to read the session data from a file. |
223 @type str |
222 @type str |
224 @return dictionary containing the session data |
223 @return dictionary containing the session data |
225 @rtype dict |
224 @rtype dict |
226 """ |
225 """ |
227 try: |
226 try: |
228 sessionFile = open(sessionFileName, "r") |
227 with open(sessionFileName, "r") as sessionFile: |
229 sessionData = json.load(sessionFile) |
228 sessionData = json.load(sessionFile) |
230 sessionFile.close() |
|
231 if not cls.isValidSession(sessionData): |
229 if not cls.isValidSession(sessionData): |
232 sessionData = {} |
230 sessionData = {} |
233 except (IOError, OSError): |
231 except (IOError, OSError): |
234 sessionData = {} |
232 sessionData = {} |
235 |
233 |