1
0

createdb.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. #!/usr/bin/env python
  2. from __future__ import print_function, unicode_literals, absolute_import
  3. import argparse
  4. import sys
  5. import os
  6. parser = argparse.ArgumentParser(
  7. description="Create/Update the Pagure database"
  8. )
  9. parser.add_argument(
  10. "--config",
  11. "-c",
  12. dest="config",
  13. help="Configuration file to use for pagure.",
  14. )
  15. parser.add_argument(
  16. "--initial",
  17. "-i",
  18. dest="alembic_cfg",
  19. help="With this option, the database will be automatically stamped to "
  20. "the latest version according to alembic. Point to the alembic.ini "
  21. "file to use.",
  22. )
  23. args = parser.parse_args()
  24. if args.config:
  25. config = args.config
  26. if not config.startswith("/"):
  27. here = os.path.join(os.path.dirname(os.path.abspath(__file__)))
  28. config = os.path.join(here, config)
  29. os.environ["PAGURE_CONFIG"] = config
  30. if args.alembic_cfg:
  31. if not args.alembic_cfg.endswith("alembic.ini"):
  32. print("--initial should point to the alembic.ini file to use.")
  33. sys.exit(1)
  34. if not os.path.exists(args.alembic_cfg):
  35. print("The file `{0}` could not be found".format(args.alembic_cfg))
  36. sys.exit(2)
  37. import pagure.config
  38. from pagure.lib import model
  39. _config = pagure.config.reload_config()
  40. model.create_tables(
  41. _config["DB_URL"],
  42. _config.get("PATH_ALEMBIC_INI", args.alembic_cfg),
  43. acls=_config.get("ACLS", {}),
  44. debug=True,
  45. )