24 |
24 |
25 class DebuggerPropertiesFile(QObject): |
25 class DebuggerPropertiesFile(QObject): |
26 """ |
26 """ |
27 Class representing the project debugger properties JSON file. |
27 Class representing the project debugger properties JSON file. |
28 """ |
28 """ |
|
29 |
29 def __init__(self, project: Project, parent: QObject = None): |
30 def __init__(self, project: Project, parent: QObject = None): |
30 """ |
31 """ |
31 Constructor |
32 Constructor |
32 |
33 |
33 @param project reference to the project object |
34 @param project reference to the project object |
34 @type Project |
35 @type Project |
35 @param parent reference to the parent object (defaults to None) |
36 @param parent reference to the parent object (defaults to None) |
36 @type QObject (optional) |
37 @type QObject (optional) |
37 """ |
38 """ |
38 super().__init__(parent) |
39 super().__init__(parent) |
39 self.__project = project |
40 self.__project = project |
40 |
41 |
41 def writeFile(self, filename: str) -> bool: |
42 def writeFile(self, filename: str) -> bool: |
42 """ |
43 """ |
43 Public method to write the project debugger properties data to a |
44 Public method to write the project debugger properties data to a |
44 project debugger properties JSON file. |
45 project debugger properties JSON file. |
45 |
46 |
46 @param filename name of the user project file |
47 @param filename name of the user project file |
47 @type str |
48 @type str |
48 @return flag indicating a successful write |
49 @return flag indicating a successful write |
49 @rtype bool |
50 @rtype bool |
50 """ |
51 """ |
51 debuggerPropertiesDict = {} |
52 debuggerPropertiesDict = {} |
52 debuggerPropertiesDict["header"] = { |
53 debuggerPropertiesDict["header"] = { |
53 "comment": "eric debugger properties file for project {0}".format( |
54 "comment": "eric debugger properties file for project {0}".format( |
54 self.__project.getProjectName()), |
55 self.__project.getProjectName() |
|
56 ), |
55 "warning": "This file was generated automatically, do not edit.", |
57 "warning": "This file was generated automatically, do not edit.", |
56 } |
58 } |
57 |
59 |
58 if Preferences.getProject("TimestampFile"): |
60 if Preferences.getProject("TimestampFile"): |
59 debuggerPropertiesDict["header"]["saved"] = ( |
61 debuggerPropertiesDict["header"]["saved"] = time.strftime( |
60 time.strftime('%Y-%m-%d, %H:%M:%S') |
62 "%Y-%m-%d, %H:%M:%S" |
61 ) |
63 ) |
62 |
64 |
63 debuggerPropertiesDict["debug_properties"] = ( |
65 debuggerPropertiesDict["debug_properties"] = self.__project.debugProperties |
64 self.__project.debugProperties |
66 |
65 ) |
|
66 |
|
67 try: |
67 try: |
68 jsonString = json.dumps(debuggerPropertiesDict, indent=2) |
68 jsonString = json.dumps(debuggerPropertiesDict, indent=2) |
69 with open(filename, "w") as f: |
69 with open(filename, "w") as f: |
70 f.write(jsonString) |
70 f.write(jsonString) |
71 except (TypeError, OSError) as err: |
71 except (TypeError, OSError) as err: |
75 self.tr("Save Debugger Properties"), |
75 self.tr("Save Debugger Properties"), |
76 self.tr( |
76 self.tr( |
77 "<p>The project debugger properties file" |
77 "<p>The project debugger properties file" |
78 " <b>{0}</b> could not be written.</p>" |
78 " <b>{0}</b> could not be written.</p>" |
79 "<p>Reason: {1}</p>" |
79 "<p>Reason: {1}</p>" |
80 ).format(filename, str(err)) |
80 ).format(filename, str(err)), |
81 ) |
81 ) |
82 return False |
82 return False |
83 |
83 |
84 return True |
84 return True |
85 |
85 |
86 def readFile(self, filename: str) -> bool: |
86 def readFile(self, filename: str) -> bool: |
87 """ |
87 """ |
88 Public method to read the project debugger properties data from a |
88 Public method to read the project debugger properties data from a |
89 project debugger properties JSON file. |
89 project debugger properties JSON file. |
90 |
90 |
91 @param filename name of the project file |
91 @param filename name of the project file |
92 @type str |
92 @type str |
93 @return flag indicating a successful read |
93 @return flag indicating a successful read |
94 @rtype bool |
94 @rtype bool |
95 """ |
95 """ |
102 None, |
102 None, |
103 self.tr("Read Debugger Properties"), |
103 self.tr("Read Debugger Properties"), |
104 self.tr( |
104 self.tr( |
105 "<p>The project debugger properties file <b>{0}</b>" |
105 "<p>The project debugger properties file <b>{0}</b>" |
106 " could not be read.</p><p>Reason: {1}</p>" |
106 " could not be read.</p><p>Reason: {1}</p>" |
107 ).format(filename, str(err)) |
107 ).format(filename, str(err)), |
108 ) |
108 ) |
109 return False |
109 return False |
110 |
110 |
111 self.__project.debugProperties = ( |
111 self.__project.debugProperties = debuggerPropertiesDict["debug_properties"] |
112 debuggerPropertiesDict["debug_properties"] |
112 |
113 ) |
|
114 |
|
115 return True |
113 return True |