main.py 3.1 KB

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