cli.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. import asyncio
  2. import os
  3. import sys
  4. import click
  5. import pkg_resources
  6. import uvicorn
  7. from loguru import logger
  8. os.chdir(os.path.join(pkg_resources.get_distribution("db0mb3r").location, "db0mb3r"))
  9. from db0mb3r.app.main import app
  10. from db0mb3r.service import prepare_services
  11. from db0mb3r.utils import open_url, check_and_upgrade
  12. @logger.catch
  13. @click.command()
  14. @click.option("--ip", default="127.0.0.1")
  15. @click.option("--port", default=8080)
  16. @click.option("--only-api", "only_api", is_flag=True, default=False)
  17. @click.option("--disable-updates", "disable_updates", is_flag=True, default=False)
  18. def main(ip: str, port: int, only_api: bool = False, disable_updates: bool = False):
  19. if sys.platform == "win32":
  20. loop = asyncio.ProactorEventLoop()
  21. asyncio.set_event_loop(loop)
  22. app.state.only_api = only_api
  23. if not disable_updates:
  24. check_and_upgrade()
  25. prepare_services()
  26. if not only_api:
  27. open_url(f"http://{ip}:{port}/")
  28. uvicorn.run(app, host=ip, port=port, log_level="error")
  29. main()