main.py 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. from pyexpat import model
  2. from time import sleep
  3. from sqlalchemy import false
  4. import Model.model_manager as model_manager
  5. import persistence
  6. from utility.app_logging import logger_name, init as init_logging
  7. import logging
  8. import View.view_manager as view
  9. logger = logging.getLogger(logger_name)
  10. __is_running__ = False
  11. __stop_app__ = False
  12. def init() :
  13. init_logging()
  14. logger.debug(__name__)
  15. logger.info("")
  16. logger.info("")
  17. logger.info("")
  18. logger.info("------- welcome to Open Internet Service Provider -------")
  19. logger.info("")
  20. logger.info("")
  21. logger.info("")
  22. logger.info(" ██████  ██████  ███████ ███  ██  ██ ███████ ██████  ")
  23. logger.info(" ██    ██ ██   ██ ██      ████  ██  ██ ██      ██   ██  ")
  24. logger.info(" ██  ██ ██████  █████  ██ ██  ██  ██ ███████ ██████   ")
  25. logger.info(" ██  ██ ██      ██     ██  ██ ██  ██      ██ ██      ")
  26. logger.info("  ██████  ██  ███████ ██   ████  ██ ███████ ██  ")
  27. logger.info("")
  28. logger.info("")
  29. logger.info(" --- INITIALIZATION PHASE ---")
  30. logger.info("initializing Persistence Engine (Database)...")
  31. persistence.init()
  32. model_manager.init()
  33. logger.info("Persistence Engine initialization Done ")
  34. logger.info("initializing View Engine - Rest API")
  35. view.init()
  36. logger.info("View Engine - Rest API initialization Done ")
  37. logger.info(" --- END OF INITIALIZATION PHASE ---")
  38. import signal
  39. def keyboardInterruptHandler(signal, frame):
  40. logger.info("KeyboardInterrupt (ID: {}) has been caught. Cleaning up...".format(signal))
  41. stop()
  42. signal.signal(signal.SIGINT, keyboardInterruptHandler)
  43. def main() :
  44. logger.info("Running View Engine - Rest API...")
  45. view.run()
  46. global __is_running__
  47. global __stop_app__
  48. __is_running__ = True
  49. logger.info("Open ISP is now Running ! ")
  50. while(not __stop_app__) :
  51. sleep(0.5)
  52. logger.debug("exiting main loop")
  53. __is_running__ = False
  54. def stop() :
  55. view.stop()
  56. global __stop_app__
  57. global __is_running__
  58. __stop_app__ = True
  59. logger.info("Application Stopped, now exiting...")
  60. def isRunning() :
  61. global __is_running__
  62. return __is_running__