|
Neal Gompa |
55fa35 |
#!/usr/bin/env python
|
|
Pierre-Yves Chibon |
066e85 |
|
|
Pierre-Yves Chibon |
67d1cc |
from __future__ import print_function, unicode_literals, absolute_import
|
|
Pierre-Yves Chibon |
a9064a |
|
|
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 |
83686d |
import pagure.config
|
|
Pierre-Yves Chibon |
fe5017 |
from pagure.lib import model
|
|
Pierre-Yves Chibon |
066e85 |
|
|
Pierre-Yves Chibon |
83686d |
_config = pagure.config.reload_config()
|
|
Pierre-Yves Chibon |
83686d |
|
|
Pierre-Yves Chibon |
066e85 |
model.create_tables(
|
|
Pierre-Yves Chibon |
83686d |
_config['DB_URL'],
|
|
Pierre-Yves Chibon |
83686d |
_config.get('PATH_ALEMBIC_INI', args.alembic_cfg),
|
|
Pierre-Yves Chibon |
83686d |
acls=_config.get('ACLS', {}),
|
|
Pierre-Yves Chibon |
b130e5 |
debug=True)
|