138 with open(fname, "w", encoding="utf-8") as f: |
138 with open(fname, "w", encoding="utf-8") as f: |
139 try: |
139 try: |
140 f.write(txt) |
140 f.write(txt) |
141 except UnicodeError: |
141 except UnicodeError: |
142 pass |
142 pass |
143 except IOError as why: |
143 except OSError as why: |
144 E5MessageBox.critical( |
144 E5MessageBox.critical( |
145 self, self.tr('Save Diff'), |
145 self, self.tr('Save Diff'), |
146 self.tr( |
146 self.tr( |
147 '<p>The patch file <b>{0}</b> could not be saved.<br />' |
147 '<p>The patch file <b>{0}</b> could not be saved.<br />' |
148 'Reason: {1}</p>').format(fname, str(why))) |
148 'Reason: {1}</p>').format(fname, str(why))) |
153 Private slot to handle the Compare button press. |
153 Private slot to handle the Compare button press. |
154 """ |
154 """ |
155 self.filename1 = Utilities.toNativeSeparators(self.file1Picker.text()) |
155 self.filename1 = Utilities.toNativeSeparators(self.file1Picker.text()) |
156 try: |
156 try: |
157 filemtime1 = time.ctime(os.stat(self.filename1).st_mtime) |
157 filemtime1 = time.ctime(os.stat(self.filename1).st_mtime) |
158 except IOError: |
158 except OSError: |
159 filemtime1 = "" |
159 filemtime1 = "" |
160 try: |
160 try: |
161 with open(self.filename1, "r", encoding="utf-8") as f1: |
161 with open(self.filename1, "r", encoding="utf-8") as f1: |
162 lines1 = f1.readlines() |
162 lines1 = f1.readlines() |
163 except IOError: |
163 except OSError: |
164 E5MessageBox.critical( |
164 E5MessageBox.critical( |
165 self, |
165 self, |
166 self.tr("Compare Files"), |
166 self.tr("Compare Files"), |
167 self.tr( |
167 self.tr( |
168 """<p>The file <b>{0}</b> could not be read.</p>""") |
168 """<p>The file <b>{0}</b> could not be read.</p>""") |
170 return |
170 return |
171 |
171 |
172 self.filename2 = Utilities.toNativeSeparators(self.file2Picker.text()) |
172 self.filename2 = Utilities.toNativeSeparators(self.file2Picker.text()) |
173 try: |
173 try: |
174 filemtime2 = time.ctime(os.stat(self.filename2).st_mtime) |
174 filemtime2 = time.ctime(os.stat(self.filename2).st_mtime) |
175 except IOError: |
175 except OSError: |
176 filemtime2 = "" |
176 filemtime2 = "" |
177 try: |
177 try: |
178 with open(self.filename2, "r", encoding="utf-8") as f2: |
178 with open(self.filename2, "r", encoding="utf-8") as f2: |
179 lines2 = f2.readlines() |
179 lines2 = f2.readlines() |
180 except IOError: |
180 except OSError: |
181 E5MessageBox.critical( |
181 E5MessageBox.critical( |
182 self, |
182 self, |
183 self.tr("Compare Files"), |
183 self.tr("Compare Files"), |
184 self.tr( |
184 self.tr( |
185 """<p>The file <b>{0}</b> could not be read.</p>""") |
185 """<p>The file <b>{0}</b> could not be read.</p>""") |