-
Notifications
You must be signed in to change notification settings - Fork 45
/
createdb.py
64 lines (53 loc) · 1.75 KB
/
createdb.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python
from __future__ import print_function, unicode_literals, absolute_import
import argparse
import sys
import os
parser = argparse.ArgumentParser(
description="Create/Update the Pagure database"
)
parser.add_argument(
"--config",
"-c",
dest="config",
help="Configuration file to use for pagure.",
)
parser.add_argument(
"--initial",
"-i",
dest="alembic_cfg",
help="With this option, the database will be automatically stamped to "
"the latest version according to alembic. Point to the alembic.ini "
"file to use.",
)
args = parser.parse_args()
if args.config:
config = args.config
if not config.startswith("/"):
here = os.path.join(os.path.dirname(os.path.abspath(__file__)))
config = os.path.join(here, config)
if not os.path.exists(config):
print("The file `{0}` could not be found".format(config))
sys.exit(2)
os.environ["PAGURE_CONFIG"] = config
if args.alembic_cfg:
alembic_config = args.alembic_cfg
if not alembic_config.startswith("/"):
here = os.path.join(os.path.dirname(os.path.abspath(__file__)))
alembic_config = os.path.join(here, alembic_config)
if not alembic_config.endswith("alembic.ini"):
print("--initial should point to the alembic.ini file to use.")
sys.exit(1)
if not os.path.exists(alembic_config):
print("The file `{0}` could not be found".format(alembic_config))
sys.exit(2)
os.environ["ALEMBIC_CONFIG"] = alembic_config
import pagure.config
from pagure.lib import model
_config = pagure.config.reload_config()
model.create_tables(
_config["DB_URL"],
_config.get("PATH_ALEMBIC_INI", os.environ["ALEMBIC_CONFIG"]),
acls=_config.get("ACLS", {}),
debug=True,
)