1
|
#! /usr/bin/python
|
2
|
# -*- coding: utf-8 -*-
|
3
|
|
4
|
""" Script to administrate mandaye server
|
5
|
"""
|
6
|
|
7
|
import os
|
8
|
|
9
|
from optparse import OptionParser
|
10
|
from {project_name} import default_config
|
11
|
|
12
|
def get_cmd_options():
|
13
|
usage = "usage: %prog --config=/path/to/config.ini --createdb|--upgradedb"
|
14
|
parser = OptionParser(usage=usage)
|
15
|
parser.add_option("--config",
|
16
|
dest="config",
|
17
|
type="string",
|
18
|
help="Path of the configuration file"
|
19
|
)
|
20
|
parser.add_option("--createdb",
|
21
|
dest="createdb",
|
22
|
default=False,
|
23
|
action="store_true",
|
24
|
help="Create Mandaye database"
|
25
|
)
|
26
|
parser.add_option("--upgradedb",
|
27
|
dest="upgradedb",
|
28
|
default=False,
|
29
|
action="store_true",
|
30
|
help="Upgrade Mandaye database"
|
31
|
)
|
32
|
(options, args) = parser.parse_args()
|
33
|
return options
|
34
|
|
35
|
def main():
|
36
|
options = get_cmd_options()
|
37
|
|
38
|
config_files = [default_config]
|
39
|
if options.config:
|
40
|
config_files.append(options.config)
|
41
|
os.environ['MANDAYE_CONFIG_FILES'] = ' '.join(config_files)
|
42
|
|
43
|
from mandaye import config
|
44
|
from mandaye.log import logger
|
45
|
if options.createdb or options.upgradedb:
|
46
|
logger.info("Creating or upgrading database...")
|
47
|
from alembic.config import Config
|
48
|
from alembic import command
|
49
|
alembic_cfg = Config(config.alembic_cfg)
|
50
|
alembic_cfg.set_main_option("script_location", config.alembic_script_path)
|
51
|
command.upgrade(alembic_cfg, "head")
|
52
|
logger.info("Database upgraded")
|
53
|
|
54
|
if __name__ == "__main__":
|
55
|
main()
|
56
|
|