src/eric7/Sessions/SessionFile.py

branch
server
changeset 10596
ea35c92a3c7c
parent 10459
5c5ed40d533d
child 10632
1109854f15f9
equal deleted inserted replaced
10594:6156d9675f62 10596:ea35c92a3c7c
14 14
15 from eric7 import Preferences 15 from eric7 import Preferences
16 from eric7.EricGui.EricOverrideCursor import EricOverridenCursor 16 from eric7.EricGui.EricOverrideCursor import EricOverridenCursor
17 from eric7.EricWidgets import EricMessageBox 17 from eric7.EricWidgets import EricMessageBox
18 from eric7.EricWidgets.EricApplication import ericApp 18 from eric7.EricWidgets.EricApplication import ericApp
19 from eric7.SystemUtilities import FileSystemUtilities
19 20
20 21
21 class SessionFile(QObject): 22 class SessionFile(QObject):
22 """ 23 """
23 Class representing the session JSON file. 24 Class representing the session JSON file.
44 @type str 45 @type str
45 @return flag indicating a successful write 46 @return flag indicating a successful write
46 @rtype bool 47 @rtype bool
47 """ 48 """
48 # get references to objects we need 49 # get references to objects we need
50 fsInterface = (
51 ericApp().getObject("EricServer").getServiceInterface("FileSystem")
52 )
53
49 project = ericApp().getObject("Project") 54 project = ericApp().getObject("Project")
50 projectBrowser = ericApp().getObject("ProjectBrowser") 55 projectBrowser = ericApp().getObject("ProjectBrowser")
51 multiProject = ericApp().getObject("MultiProject") 56 multiProject = ericApp().getObject("MultiProject")
52 vm = ericApp().getObject("ViewManager") 57 vm = ericApp().getObject("ViewManager")
53 dbg = ericApp().getObject("DebugUI") 58 dbg = ericApp().getObject("DebugUI")
221 ) 226 )
222 sessionDict["ProjectBrowserStates"] = browsersList 227 sessionDict["ProjectBrowserStates"] = browsersList
223 228
224 try: 229 try:
225 jsonString = json.dumps(sessionDict, indent=2) + "\n" 230 jsonString = json.dumps(sessionDict, indent=2) + "\n"
226 with open(filename, "w") as f: 231 if FileSystemUtilities.isRemoteFileName(filename):
227 f.write(jsonString) 232 title = self.tr("Save Remote Session")
233 fsInterface.writeFile(filename, jsonString.encode("utf-8"))
234 else:
235 title = self.tr("Save Session")
236 with open(filename, "w") as f:
237 f.write(jsonString)
228 except (OSError, TypeError) as err: 238 except (OSError, TypeError) as err:
229 with EricOverridenCursor(): 239 with EricOverridenCursor():
230 EricMessageBox.critical( 240 EricMessageBox.critical(
231 None, 241 None,
232 self.tr("Save Session"), 242 title,
233 self.tr( 243 self.tr(
234 "<p>The session file <b>{0}</b> could not be" 244 "<p>The session file <b>{0}</b> could not be"
235 " written.</p><p>Reason: {1}</p>" 245 " written.</p><p>Reason: {1}</p>"
236 ).format(filename, str(err)), 246 ).format(filename, str(err)),
237 ) 247 )
246 @param filename name of the project file 256 @param filename name of the project file
247 @type str 257 @type str
248 @return flag indicating a successful read 258 @return flag indicating a successful read
249 @rtype bool 259 @rtype bool
250 """ 260 """
261 fsInterface = (
262 ericApp().getObject("EricServer").getServiceInterface("FileSystem")
263 )
264
251 try: 265 try:
252 with open(filename, "r") as f: 266 if FileSystemUtilities.isRemoteFileName(filename):
253 jsonString = f.read() 267 title = self.tr("Read Remote Session")
268 jsonString = fsInterface.readFile(filename).decode("utf-8")
269 else:
270 title = self.tr("Read Session")
271 with open(filename, "r") as f:
272 jsonString = f.read()
254 sessionDict = json.loads(jsonString) 273 sessionDict = json.loads(jsonString)
255 except (OSError, json.JSONDecodeError) as err: 274 except (OSError, json.JSONDecodeError) as err:
256 EricMessageBox.critical( 275 EricMessageBox.critical(
257 None, 276 None,
258 self.tr("Read Session"), 277 title,
259 self.tr( 278 self.tr(
260 "<p>The session file <b>{0}</b> could not be read.</p>" 279 "<p>The session file <b>{0}</b> could not be read.</p>"
261 "<p>Reason: {1}</p>" 280 "<p>Reason: {1}</p>"
262 ).format(filename, str(err)), 281 ).format(filename, str(err)),
263 ) 282 )

eric ide

mercurial