main.py 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import time
  2. stime = time.time()
  3. import argparse
  4. import os
  5. import sys
  6. from colorama import init
  7. from api import create_app
  8. from chimera.interface import ChimeraInterface
  9. from config import log
  10. from db import cc
  11. # colorama
  12. init(autoreset=True)
  13. # refactored, imports still fucked
  14. # this is so it will always return the same
  15. # chimera interface, because it get's imported
  16. # from other files
  17. ci = ChimeraInterface.grab_or_create(0)
  18. def arg_parse():
  19. parser = argparse.ArgumentParser(description='Chimera')
  20. parser.add_argument('-a', '--api', action='store_true', help='start chimera in api mode')
  21. parser.add_argument('-na', '--noautologin', action='store_true', help='disable auto login')
  22. parser.add_argument('--debug', action='store_true', help='enable debug logs')
  23. parser.add_argument('-url', action='store')
  24. parser.add_argument('-u', action='store')
  25. parser.add_argument('-p', action='store')
  26. parser.add_argument('-sync', action='store_true')
  27. args = parser.parse_args()
  28. return args
  29. if __name__ == '__main__':
  30. import cli.main_cli
  31. # create download workers
  32. ci.add_workers()
  33. args = arg_parse()
  34. if args.api:
  35. cc.cli = False
  36. if cc.cli:
  37. log.info('chimera started')
  38. if cc.first_run:
  39. cc.first_run = False
  40. cc.save()
  41. cli.main_cli.setup_chimera()
  42. try:
  43. cli.main_cli.main(args, stime)
  44. except (KeyboardInterrupt, SystemExit):
  45. print('\nExiting...')
  46. if cc.prod:
  47. sys.exit()
  48. else:
  49. os._exit(1)
  50. else:
  51. # set logging to true
  52. import logging
  53. app = create_app()
  54. log = logging.getLogger('werkzeug')
  55. log.disabled = False
  56. # from gevent.pywsgi import WSGIServer
  57. # print('Started API SERVER')
  58. # http_server = WSGIServer(('0.0.0.0', 5000), app)
  59. # http_server.serve_forever()
  60. app.run(host='0.0.0.0', port=5000)