pardit.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. """
  2. Pardit - Production automatisée de réponse aux demandes d'intention de travaux
  3. Pour traiter automatiquement un fichier XML, utilisez l'argument optionnel '-file=<filename>'.
  4. ex: pardit.py -file c:\...\fichier.xml
  5. @author: olivier.massot, 2017
  6. """
  7. import re
  8. import sys
  9. from PyQt5.Qt import QApplication
  10. from PyQt5.QtWidgets import QMessageBox
  11. from core import constants, config
  12. from ui.window import MainWindow
  13. import updater
  14. try:
  15. import ipdb # @UnusedImport Necessaire à l'affichage des stack traces
  16. except:
  17. pass
  18. # Look for a -file=<filename> argument
  19. args = sys.argv
  20. regex = re.compile(r"""^-file="?(.*)"?$""")
  21. filename = ""
  22. for arg in args:
  23. match = regex.match(arg)
  24. if match != None:
  25. filename = match.group(1)
  26. app = QApplication(sys.argv)
  27. mainw = MainWindow()
  28. sys_err = sys.excepthook
  29. def gestionnaire_erreurs(typ, value, traceback):
  30. QApplication.restoreOverrideCursor()
  31. sys_err(typ, value, traceback)
  32. QMessageBox.critical(mainw, "Erreur: {}".format(typ.__name__), """{}""".format(value))
  33. mainw.cancel()
  34. sys.excepthook = gestionnaire_erreurs
  35. try:
  36. if updater.update_needed():
  37. QMessageBox.information(mainw,
  38. "Mise à jour requise",
  39. """Une nouvelle version de Pardit est disponible,
  40. veuillez patienter pendant la mise à jour.
  41. Pardit sera relancé automatiqement une fois l'installation terminée.""",
  42. QMessageBox.Ok)
  43. updater.update()
  44. sys.exit(0)
  45. except updater.Unavailable:
  46. print("Request error: unable to fetch last version")
  47. # Charge la configuration
  48. config.load()
  49. mainw.show()
  50. if filename:
  51. mainw.process(filename)
  52. r = app.exec_()
  53. # Nettoyage
  54. constants.TMPDIR.rmdir_p()