67 # modify paths to contain universal separators |
68 # modify paths to contain universal separators |
68 for key in ( |
69 for key in ( |
69 "SOURCES", "FORMS", "TRANSLATIONS", "TRANSLATIONEXCEPTIONS", |
70 "SOURCES", "FORMS", "TRANSLATIONS", "TRANSLATIONEXCEPTIONS", |
70 "RESOURCES", "INTERFACES", "PROTOCOLS", "OTHERS" |
71 "RESOURCES", "INTERFACES", "PROTOCOLS", "OTHERS" |
71 ): |
72 ): |
72 try: |
73 with contextlib.suppress(KeyError): |
73 projectDict["project"][key] = [ |
74 projectDict["project"][key] = [ |
74 Utilities.fromNativeSeparators(f) |
75 Utilities.fromNativeSeparators(f) |
75 for f in projectDict["project"][key] |
76 for f in projectDict["project"][key] |
76 ] |
77 ] |
77 except KeyError: |
|
78 # ignore non-existent elements |
|
79 pass |
|
80 for key in ( |
78 for key in ( |
81 "SPELLWORDS", "SPELLEXCLUDES", "TRANSLATIONPATTERN", |
79 "SPELLWORDS", "SPELLEXCLUDES", "TRANSLATIONPATTERN", |
82 "TRANSLATIONSBINPATH", "MAINSCRIPT" |
80 "TRANSLATIONSBINPATH", "MAINSCRIPT" |
83 ): |
81 ): |
84 try: |
82 with contextlib.suppress(KeyError): |
85 projectDict["project"][key] = Utilities.fromNativeSeparators( |
83 projectDict["project"][key] = Utilities.fromNativeSeparators( |
86 projectDict["project"][key]) |
84 projectDict["project"][key]) |
87 except KeyError: |
|
88 # ignore non-existent elements |
|
89 pass |
|
90 |
85 |
91 try: |
86 try: |
92 jsonString = json.dumps(projectDict, indent=2, sort_keys=True) |
87 jsonString = json.dumps(projectDict, indent=2, sort_keys=True) |
93 with open(filename, "w", newline="") as f: |
88 with open(filename, "w", newline="") as f: |
94 f.write(jsonString) |
89 f.write(jsonString) |
95 except (TypeError, EnvironmentError) as err: |
90 except (TypeError, OSError) as err: |
96 with E5OverridenCursor(): |
91 with E5OverridenCursor(): |
97 E5MessageBox.critical( |
92 E5MessageBox.critical( |
98 None, |
93 None, |
99 self.tr("Save Project File"), |
94 self.tr("Save Project File"), |
100 self.tr( |
95 self.tr( |
117 """ |
112 """ |
118 try: |
113 try: |
119 with open(filename, "r") as f: |
114 with open(filename, "r") as f: |
120 jsonString = f.read() |
115 jsonString = f.read() |
121 projectDict = json.loads(jsonString) |
116 projectDict = json.loads(jsonString) |
122 except (EnvironmentError, json.JSONDecodeError) as err: |
117 except (OSError, json.JSONDecodeError) as err: |
123 E5MessageBox.critical( |
118 E5MessageBox.critical( |
124 None, |
119 None, |
125 self.tr("Read Project File"), |
120 self.tr("Read Project File"), |
126 self.tr( |
121 self.tr( |
127 "<p>The project file <b>{0}</b> could not be " |
122 "<p>The project file <b>{0}</b> could not be " |
133 # modify paths to contain native separators |
128 # modify paths to contain native separators |
134 for key in ( |
129 for key in ( |
135 "SOURCES", "FORMS", "TRANSLATIONS", "TRANSLATIONEXCEPTIONS", |
130 "SOURCES", "FORMS", "TRANSLATIONS", "TRANSLATIONEXCEPTIONS", |
136 "RESOURCES", "INTERFACES", "PROTOCOLS", "OTHERS" |
131 "RESOURCES", "INTERFACES", "PROTOCOLS", "OTHERS" |
137 ): |
132 ): |
138 try: |
133 with contextlib.suppress(KeyError): |
139 projectDict["project"][key] = [ |
134 projectDict["project"][key] = [ |
140 Utilities.toNativeSeparators(f) |
135 Utilities.toNativeSeparators(f) |
141 for f in projectDict["project"][key] |
136 for f in projectDict["project"][key] |
142 ] |
137 ] |
143 except KeyError: |
|
144 # ignore non-existent elements |
|
145 pass |
|
146 for key in ( |
138 for key in ( |
147 "SPELLWORDS", "SPELLEXCLUDES", "TRANSLATIONPATTERN", |
139 "SPELLWORDS", "SPELLEXCLUDES", "TRANSLATIONPATTERN", |
148 "TRANSLATIONSBINPATH", "MAINSCRIPT" |
140 "TRANSLATIONSBINPATH", "MAINSCRIPT" |
149 ): |
141 ): |
150 try: |
142 with contextlib.suppress(KeyError): |
151 projectDict["project"][key] = Utilities.toNativeSeparators( |
143 projectDict["project"][key] = Utilities.toNativeSeparators( |
152 projectDict["project"][key]) |
144 projectDict["project"][key]) |
153 except KeyError: |
|
154 # ignore non-existent elements |
|
155 pass |
|
156 |
145 |
157 self.__project.pdata = projectDict["project"] |
146 self.__project.pdata = projectDict["project"] |
158 |
147 |
159 return True |
148 return True |