1
0

createdb.py 1.5 KB

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