15 from PyQt6.QtCore import QObject |
15 from PyQt6.QtCore import QObject |
16 |
16 |
17 from eric7 import Preferences |
17 from eric7 import Preferences |
18 from eric7.EricGui.EricOverrideCursor import EricOverridenCursor |
18 from eric7.EricGui.EricOverrideCursor import EricOverridenCursor |
19 from eric7.EricWidgets import EricMessageBox |
19 from eric7.EricWidgets import EricMessageBox |
|
20 from eric7.EricWidgets.EricApplication import ericApp |
|
21 from eric7.SystemUtilities import FileSystemUtilities |
20 |
22 |
21 Project = typing.TypeVar("Project") |
23 Project = typing.TypeVar("Project") |
22 |
24 |
23 |
25 |
24 class DebuggerPropertiesFile(QObject): |
26 class DebuggerPropertiesFile(QObject): |
46 @param filename name of the user project file |
48 @param filename name of the user project file |
47 @type str |
49 @type str |
48 @return flag indicating a successful write |
50 @return flag indicating a successful write |
49 @rtype bool |
51 @rtype bool |
50 """ |
52 """ |
|
53 fsInterface = ( |
|
54 ericApp().getObject("EricServer").getServiceInterface("FileSystem") |
|
55 ) |
|
56 |
51 debuggerPropertiesDict = { |
57 debuggerPropertiesDict = { |
52 "header": { |
58 "header": { |
53 "comment": "eric debugger properties file for project {0}".format( |
59 "comment": "eric debugger properties file for project {0}".format( |
54 self.__project.getProjectName() |
60 self.__project.getProjectName() |
55 ), |
61 ), |
64 |
70 |
65 debuggerPropertiesDict["debug_properties"] = self.__project.debugProperties |
71 debuggerPropertiesDict["debug_properties"] = self.__project.debugProperties |
66 |
72 |
67 try: |
73 try: |
68 jsonString = json.dumps(debuggerPropertiesDict, indent=2) + "\n" |
74 jsonString = json.dumps(debuggerPropertiesDict, indent=2) + "\n" |
69 with open(filename, "w") as f: |
75 if FileSystemUtilities.isRemoteFileName(filename): |
70 f.write(jsonString) |
76 title = self.tr("Save Remote Debugger Properties") |
|
77 fsInterface.writeFile(filename, jsonString.encode("utf-8")) |
|
78 else: |
|
79 title = self.tr("Save Debugger Properties") |
|
80 with open(filename, "w") as f: |
|
81 f.write(jsonString) |
71 except (OSError, TypeError) as err: |
82 except (OSError, TypeError) as err: |
72 with EricOverridenCursor(): |
83 with EricOverridenCursor(): |
73 EricMessageBox.critical( |
84 EricMessageBox.critical( |
74 None, |
85 None, |
75 self.tr("Save Debugger Properties"), |
86 title, |
76 self.tr( |
87 self.tr( |
77 "<p>The project debugger properties file" |
88 "<p>The project debugger properties file" |
78 " <b>{0}</b> could not be written.</p>" |
89 " <b>{0}</b> could not be written.</p>" |
79 "<p>Reason: {1}</p>" |
90 "<p>Reason: {1}</p>" |
80 ).format(filename, str(err)), |
91 ).format(filename, str(err)), |
91 @param filename name of the project file |
102 @param filename name of the project file |
92 @type str |
103 @type str |
93 @return flag indicating a successful read |
104 @return flag indicating a successful read |
94 @rtype bool |
105 @rtype bool |
95 """ |
106 """ |
|
107 fsInterface = ( |
|
108 ericApp().getObject("EricServer").getServiceInterface("FileSystem") |
|
109 ) |
|
110 |
96 try: |
111 try: |
97 with open(filename, "r") as f: |
112 if FileSystemUtilities.isRemoteFileName(filename): |
98 jsonString = f.read() |
113 title = self.tr("Read Remote Debugger Properties") |
|
114 jsonString = fsInterface.readFile(filename).decode("utf-8") |
|
115 else: |
|
116 title = self.tr("Read Debugger Properties") |
|
117 with open(filename, "r") as f: |
|
118 jsonString = f.read() |
99 debuggerPropertiesDict = json.loads(jsonString) |
119 debuggerPropertiesDict = json.loads(jsonString) |
100 except (OSError, json.JSONDecodeError) as err: |
120 except (OSError, json.JSONDecodeError) as err: |
101 EricMessageBox.critical( |
121 EricMessageBox.critical( |
102 None, |
122 None, |
103 self.tr("Read Debugger Properties"), |
123 title, |
104 self.tr( |
124 self.tr( |
105 "<p>The project debugger properties file <b>{0}</b>" |
125 "<p>The project debugger properties file <b>{0}</b>" |
106 " could not be read.</p><p>Reason: {1}</p>" |
126 " could not be read.</p><p>Reason: {1}</p>" |
107 ).format(filename, str(err)), |
127 ).format(filename, str(err)), |
108 ) |
128 ) |