# Path: voeventdb/server/database/db_utils.py
# def check_database_exists(db_url):
# def create_empty_database(admin_db_url, new_db_name):
# def delete_database(admin_db_url, drop_db_name):
# def load_q3c(connection):
# def create_tables_and_indexes(connection):


import sys
import os
import argparse
import logging
import voeventdb.server.database.config as dbconfig
from sqlalchemy.engine.url import make_url
from sqlalchemy import create_engine
from voeventdb.server.database import db_utils

logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger("create_db")


def database_url(s):
    return make_url(s)


def handle_args():
    """
    Default values are defined here.
    """
    default_database_name = dbconfig.testdb_corpus_url.database
    parser = argparse.ArgumentParser(
        prog=os.path.basename(__file__),
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument('dbname',
                        nargs='?',
                        default=str(default_database_name),
                        help='Database name',
                        )
    return parser.parse_args()


def main():
    args = handle_args()
    dburl = dbconfig.make_db_url(dbconfig.default_admin_db_params, args.dbname)
    if not db_utils.check_database_exists(dburl):

# Path: voeventdb/server/database/db_utils.py
# def check_database_exists(db_url):
# def create_empty_database(admin_db_url, new_db_name):
# def delete_database(admin_db_url, drop_db_name):
# def load_q3c(connection):
# def create_tables_and_indexes(connection):


# Path: voeventdb/server/bin/voeventdb_create.py
import sys
import os
import argparse
import logging
import voeventdb.server.database.config as dbconfig
from sqlalchemy.engine.url import make_url
from sqlalchemy import create_engine
from voeventdb.server.database import db_utils


logging.basicConfig(level=logging.DEBUG)
logger = logging.getLogger("create_db")


def database_url(s):
    return make_url(s)


def handle_args():
    """
    Default values are defined here.
    """
    default_database_name = dbconfig.testdb_corpus_url.database
    parser = argparse.ArgumentParser(
        prog=os.path.basename(__file__),
        formatter_class=argparse.ArgumentDefaultsHelpFormatter)

    parser.add_argument('dbname',
                        nargs='?',
                        default=str(default_database_name),
                        help='Database name',
                        )
    return parser.parse_args()


def main():
    args = handle_args()
    dburl = dbconfig.make_db_url(dbconfig.default_admin_db_params, args.dbname)
    if not db_utils.check_database_exists(dburl):

        db_utils.create_empty_database(dbconfig.default_admin_db_url,