MultiProject/MultiProject.py

changeset 537
72b32daeb8d6
parent 520
b0f523c3b037
child 539
87f9bce38a44
equal deleted inserted replaced
536:6d8d39753c82 537:72b32daeb8d6
18 from .PropertiesDialog import PropertiesDialog 18 from .PropertiesDialog import PropertiesDialog
19 from .AddProjectDialog import AddProjectDialog 19 from .AddProjectDialog import AddProjectDialog
20 20
21 from E5Gui.E5Action import E5Action, createActionGroup 21 from E5Gui.E5Action import E5Action, createActionGroup
22 from E5Gui import E5FileDialog 22 from E5Gui import E5FileDialog
23 from E5Gui import E5MessageBox
23 24
24 from E5XML.XMLUtilities import make_parser 25 from E5XML.XMLUtilities import make_parser
25 from E5XML.XMLErrorHandler import XMLErrorHandler, XMLFatalParseError 26 from E5XML.XMLErrorHandler import XMLErrorHandler, XMLFatalParseError
26 from E5XML.XMLEntityResolver import XMLEntityResolver 27 from E5XML.XMLEntityResolver import XMLEntityResolver
27 28
205 if fn.lower().endswith("e4mz"): 206 if fn.lower().endswith("e4mz"):
206 try: 207 try:
207 import gzip 208 import gzip
208 except ImportError: 209 except ImportError:
209 QApplication.restoreOverrideCursor() 210 QApplication.restoreOverrideCursor()
210 QMessageBox.critical(None, 211 E5MessageBox.critical(self.ui,
211 self.trUtf8("Read multiproject file"), 212 self.trUtf8("Read multiproject file"),
212 self.trUtf8("""Compressed multiproject files not supported.""" 213 self.trUtf8("""Compressed multiproject files not supported."""
213 """ The compression library is missing.""")) 214 """ The compression library is missing."""))
214 return False 215 return False
215 g = gzip.open(fn, "rb") 216 g = gzip.open(fn, "rb")
220 line = f.readline() 221 line = f.readline()
221 dtdLine = f.readline() 222 dtdLine = f.readline()
222 f.close() 223 f.close()
223 except EnvironmentError: 224 except EnvironmentError:
224 QApplication.restoreOverrideCursor() 225 QApplication.restoreOverrideCursor()
225 QMessageBox.critical(None, 226 E5MessageBox.critical(self.ui,
226 self.trUtf8("Read multiproject file"), 227 self.trUtf8("Read multiproject file"),
227 self.trUtf8("<p>The multiproject file <b>{0}</b> could not be read.</p>")\ 228 self.trUtf8("<p>The multiproject file <b>{0}</b> could not be read.</p>")\
228 .format(fn)) 229 .format(fn))
229 return False 230 return False
230 231
232 self.ppath = os.path.abspath(os.path.dirname(fn)) 233 self.ppath = os.path.abspath(os.path.dirname(fn))
233 234
234 # now read the file 235 # now read the file
235 if not line.startswith('<?xml'): 236 if not line.startswith('<?xml'):
236 QApplication.restoreOverrideCursor() 237 QApplication.restoreOverrideCursor()
237 QMessageBox.critical(None, 238 E5MessageBox.critical(self.ui,
238 self.trUtf8("Read multiproject file"), 239 self.trUtf8("Read multiproject file"),
239 self.trUtf8("<p>The multiproject file <b>{0}</b> has an unsupported" 240 self.trUtf8("<p>The multiproject file <b>{0}</b> has an unsupported"
240 " format.</p>").format(fn)) 241 " format.</p>").format(fn))
241 return False 242 return False
242 243
278 if fn.lower().endswith("e4mz"): 279 if fn.lower().endswith("e4mz"):
279 try: 280 try:
280 import gzip 281 import gzip
281 except ImportError: 282 except ImportError:
282 QApplication.restoreOverrideCursor() 283 QApplication.restoreOverrideCursor()
283 QMessageBox.critical(None, 284 E5MessageBox.critical(self.ui,
284 self.trUtf8("Read multiproject file"), 285 self.trUtf8("Read multiproject file"),
285 self.trUtf8("""Compressed multiproject files not supported.""" 286 self.trUtf8("""Compressed multiproject files not supported."""
286 """ The compression library is missing.""")) 287 """ The compression library is missing."""))
287 return False 288 return False
288 g = gzip.open(fn, "rb") 289 g = gzip.open(fn, "rb")
299 parser.parse(buf) 300 parser.parse(buf)
300 finally: 301 finally:
301 f.close() 302 f.close()
302 except IOError: 303 except IOError:
303 QApplication.restoreOverrideCursor() 304 QApplication.restoreOverrideCursor()
304 QMessageBox.critical(None, 305 E5MessageBox.critical(self.ui,
305 self.trUtf8("Read multiproject file"), 306 self.trUtf8("Read multiproject file"),
306 self.trUtf8("<p>The multiproject file <b>{0}</b> could not be read.</p>")\ 307 self.trUtf8("<p>The multiproject file <b>{0}</b> could not be read.</p>")\
307 .format(fn)) 308 .format(fn))
308 return False 309 return False
309 except XMLFatalParseError: 310 except XMLFatalParseError:
310 QApplication.restoreOverrideCursor() 311 QApplication.restoreOverrideCursor()
311 QMessageBox.critical(None, 312 E5MessageBox.critical(self.ui,
312 self.trUtf8("Read multiproject file"), 313 self.trUtf8("Read multiproject file"),
313 self.trUtf8("<p>The multiproject file <b>{0}</b> has invalid " 314 self.trUtf8("<p>The multiproject file <b>{0}</b> has invalid "
314 "contents.</p>").format(fn)) 315 "contents.</p>").format(fn))
315 eh.showParseMessages() 316 eh.showParseMessages()
316 return False 317 return False
357 try: 358 try:
358 if fn.lower().endswith("e4mz"): 359 if fn.lower().endswith("e4mz"):
359 try: 360 try:
360 import gzip 361 import gzip
361 except ImportError: 362 except ImportError:
362 QMessageBox.critical(None, 363 E5MessageBox.critical(self.ui,
363 self.trUtf8("Save multiproject file"), 364 self.trUtf8("Save multiproject file"),
364 self.trUtf8("""Compressed multiproject files not supported.""" 365 self.trUtf8("""Compressed multiproject files not supported."""
365 """ The compression library is missing.""")) 366 """ The compression library is missing."""))
366 return False 367 return False
367 f = io.StringIO() 368 f = io.StringIO()
375 g = gzip.open(fn, "wb") 376 g = gzip.open(fn, "wb")
376 g.write(f.getvalue().encode("utf-8")) 377 g.write(f.getvalue().encode("utf-8"))
377 g.close() 378 g.close()
378 f.close() 379 f.close()
379 except IOError: 380 except IOError:
380 QMessageBox.critical(None, 381 E5MessageBox.critical(self.ui,
381 self.trUtf8("Save multiproject file"), 382 self.trUtf8("Save multiproject file"),
382 self.trUtf8("<p>The multiproject file <b>{0}</b> could not be " 383 self.trUtf8("<p>The multiproject file <b>{0}</b> could not be "
383 "written.</p>").format(fn)) 384 "written.</p>").format(fn))
384 return False 385 return False
385 386

eric ide

mercurial