createdb.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  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. if not os.path.exists(config):
  30. print("The file `{0}` could not be found".format(config))
  31. sys.exit(2)
  32. os.environ["PAGURE_CONFIG"] = config
  33. if args.alembic_cfg:
  34. alembic_config = args.alembic_cfg
  35. if not alembic_config.startswith("/"):
  36. here = os.path.join(os.path.dirname(os.path.abspath(__file__)))
  37. alembic_config = os.path.join(here, alembic_config)
  38. if not alembic_config.endswith("alembic.ini"):
  39. print("--initial should point to the alembic.ini file to use.")
  40. sys.exit(1)
  41. if not os.path.exists(alembic_config):
  42. print("The file `{0}` could not be found".format(alembic_config))
  43. sys.exit(2)
  44. os.environ["ALEMBIC_CONFIG"] = alembic_config
  45. import pagure.config
  46. from pagure.lib import model
  47. _config = pagure.config.reload_config()
  48. model.create_tables(
  49. _config["DB_URL"],
  50. _config.get("PATH_ALEMBIC_INI", os.environ["ALEMBIC_CONFIG"]),
  51. acls=_config.get("ACLS", {}),
  52. debug=True,
  53. )