Blame createdb.py

Pierre-Yves Chibon 346fa0
#!/usr/bin/env python2
Pierre-Yves Chibon 066e85
Aurélien Bompard dcf6f6
from __future__ import print_function, unicode_literals
Pierre-Yves Chibon a9064a
Pierre-Yves Chibon 50adc2
# These two lines are needed to run on EL6
Pierre-Yves Chibon ee9b42
__requires__ = ['SQLAlchemy >= 0.8', 'jinja2 >= 2.4']
Pierre-Yves Chibon 89bddf
import pkg_resources  # noqa
Pierre-Yves Chibon e307d7
Pierre-Yves Chibon e307d7
import argparse
Pierre-Yves Chibon e307d7
import sys
Pierre-Yves Chibon e307d7
import os
Pierre-Yves Chibon e307d7
Pierre-Yves Chibon e307d7
Pierre-Yves Chibon e307d7
parser = argparse.ArgumentParser(
Pierre-Yves Chibon e307d7
    description='Create/Update the Pagure database')
Pierre-Yves Chibon e307d7
parser.add_argument(
Pierre-Yves Chibon e307d7
    '--config', '-c', dest='config',
Pierre-Yves Chibon e307d7
    help='Configuration file to use for pagure.')
Pierre-Yves Chibon e307d7
parser.add_argument(
Pierre-Yves Chibon e307d7
    '--initial', '-i', dest='alembic_cfg',
Pierre-Yves Chibon e307d7
    help='With this option, the database will be automatically stamped to '
Pierre-Yves Chibon e307d7
         'the latest version according to alembic. Point to the alembic.ini '
Pierre-Yves Chibon e307d7
         'file to use.')
Pierre-Yves Chibon e307d7
Pierre-Yves Chibon e307d7
Pierre-Yves Chibon e307d7
args = parser.parse_args()
Pierre-Yves Chibon e307d7
Pierre-Yves Chibon e307d7
if args.config:
Pierre-Yves Chibon e307d7
    config = args.config
Pierre-Yves Chibon e307d7
    if not config.startswith('/'):
Pierre-Yves Chibon e307d7
        here = os.path.join(os.path.dirname(os.path.abspath(__file__)))
Pierre-Yves Chibon e307d7
        config = os.path.join(here, config)
Pierre-Yves Chibon e307d7
    os.environ['PAGURE_CONFIG'] = config
Pierre-Yves Chibon e307d7
Pierre-Yves Chibon e307d7
Pierre-Yves Chibon e307d7
if args.alembic_cfg:
Pierre-Yves Chibon e307d7
    if not args.alembic_cfg.endswith('alembic.ini'):
Pierre-Yves Chibon e307d7
        print('--initial should point to the alembic.ini file to use.')
Pierre-Yves Chibon e307d7
        sys.exit(1)
Pierre-Yves Chibon e307d7
    if not os.path.exists(args.alembic_cfg):
Pierre-Yves Chibon e307d7
        print('The file `{0}` could not be found'.format(args.alembic_cfg))
Pierre-Yves Chibon e307d7
        sys.exit(2)
Pierre-Yves Chibon e307d7
Pierre-Yves Chibon 066e85
Pierre-Yves Chibon b130e5
import pagure
Pierre-Yves Chibon fe5017
from pagure.lib import model
Pierre-Yves Chibon 066e85
Pierre-Yves Chibon 066e85
model.create_tables(
Pierre-Yves Chibon b130e5
    pagure.config.config['DB_URL'],
Pierre-Yves Chibon b130e5
    pagure.config.config.get('PATH_ALEMBIC_INI', args.alembic_cfg),
Pierre-Yves Chibon b130e5
    acls=pagure.config.config.get('ACLS', {}),
Pierre-Yves Chibon b130e5
    debug=True)