Blame createdb.py

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 73d120
    description="Create/Update the Pagure database"
Pierre-Yves Chibon 73d120
)
Pierre-Yves Chibon e307d7
parser.add_argument(
Pierre-Yves Chibon 73d120
    "--config",
Pierre-Yves Chibon 73d120
    "-c",
Pierre-Yves Chibon 73d120
    dest="config",
Pierre-Yves Chibon 73d120
    help="Configuration file to use for pagure.",
Pierre-Yves Chibon 73d120
)
Pierre-Yves Chibon e307d7
parser.add_argument(
Pierre-Yves Chibon 73d120
    "--initial",
Pierre-Yves Chibon 73d120
    "-i",
Pierre-Yves Chibon 73d120
    dest="alembic_cfg",
Pierre-Yves Chibon 73d120
    help="With this option, the database will be automatically stamped to "
Pierre-Yves Chibon 73d120
    "the latest version according to alembic. Point to the alembic.ini "
Pierre-Yves Chibon 73d120
    "file to use.",
Pierre-Yves Chibon 73d120
)
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 73d120
    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 73d120
    os.environ["PAGURE_CONFIG"] = config
Pierre-Yves Chibon e307d7
Pierre-Yves Chibon e307d7
Pierre-Yves Chibon e307d7
if args.alembic_cfg:
Pierre-Yves Chibon 73d120
    if not args.alembic_cfg.endswith("alembic.ini"):
Pierre-Yves Chibon 73d120
        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 73d120
        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 73d120
    _config["DB_URL"],
Pierre-Yves Chibon 73d120
    _config.get("PATH_ALEMBIC_INI", args.alembic_cfg),
Pierre-Yves Chibon 73d120
    acls=_config.get("ACLS", {}),
Pierre-Yves Chibon 73d120
    debug=True,
Pierre-Yves Chibon 73d120
)