1
0

createdb.py 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. parser.add_argument(
  9. '--config', '-c', dest='config',
  10. help='Configuration file to use for pagure.')
  11. parser.add_argument(
  12. '--initial', '-i', dest='alembic_cfg',
  13. help='With this option, the database will be automatically stamped to '
  14. 'the latest version according to alembic. Point to the alembic.ini '
  15. 'file to use.')
  16. args = parser.parse_args()
  17. if args.config:
  18. config = args.config
  19. if not config.startswith('/'):
  20. here = os.path.join(os.path.dirname(os.path.abspath(__file__)))
  21. config = os.path.join(here, config)
  22. os.environ['PAGURE_CONFIG'] = config
  23. if args.alembic_cfg:
  24. if not args.alembic_cfg.endswith('alembic.ini'):
  25. print('--initial should point to the alembic.ini file to use.')
  26. sys.exit(1)
  27. if not os.path.exists(args.alembic_cfg):
  28. print('The file `{0}` could not be found'.format(args.alembic_cfg))
  29. sys.exit(2)
  30. import pagure.config
  31. from pagure.lib import model
  32. _config = pagure.config.reload_config()
  33. model.create_tables(
  34. _config['DB_URL'],
  35. _config.get('PATH_ALEMBIC_INI', args.alembic_cfg),
  36. acls=_config.get('ACLS', {}),
  37. debug=True)