51 lines
1.3 KiB
Python
Executable File
51 lines
1.3 KiB
Python
Executable File
#!/usr/bin/env python
|
|
# -*- coding: utf-8 -*-
|
|
|
|
""" Script to start and stop mandaye server
|
|
"""
|
|
|
|
import logging
|
|
|
|
from optparse import OptionParser
|
|
|
|
from mandaye import config
|
|
from mandaye import server
|
|
|
|
def get_cmd_options():
|
|
usage = "usage: %prog --start|--createdb"
|
|
parser = OptionParser(usage=usage)
|
|
parser.add_option("--start",
|
|
dest="start",
|
|
default=False,
|
|
action="store_true",
|
|
help="Start Mandaye server"
|
|
)
|
|
parser.add_option("--createdb",
|
|
dest="createdb",
|
|
default=False,
|
|
action="store_true",
|
|
help="Create the Mandaye database"
|
|
)
|
|
(options, args) = parser.parse_args()
|
|
if not options.start and not options.createdb:
|
|
parser.error("You must use option --start | --createdb")
|
|
return options
|
|
|
|
def main():
|
|
options = get_cmd_options()
|
|
if options.createdb:
|
|
logging.info("Creating database...")
|
|
if config.db_url:
|
|
from mandaye.models import Base
|
|
from sqlalchemy import create_engine
|
|
engine = create_engine(config.db_url)
|
|
Base.metadata.create_all(engine)
|
|
print "Database created"
|
|
|
|
if options.start:
|
|
print "Starting Mandaye %s:%d .." % (config.host, config.port)
|
|
server.serve()
|
|
|
|
if __name__ == "__main__":
|
|
main()
|