'''
    Copyright (c) 2012 Alexander Abbott

    This file is part of the Cheshire Cyber Defense Scoring Engine (henceforth
    referred to as Cheshire).

    Cheshire is free software: you can redistribute it and/or modify it under
    the terms of the GNU Affero General Public License as published by the
    Free Software Foundation, either version 3 of the License, or (at your
    option) any later version.

    Cheshire is distributed in the hope that it will be useful, but WITHOUT ANY
    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for
    more details.

    You should have received a copy of the GNU Affero General Public License
    along with Cheshire.  If not, see <http://www.gnu.org/licenses/>.
'''

import sys
from CheshireCat import create_app, run_app

if __name__ == "__main__":
    if len(sys.argv) > 1:
        create_app(sys.argv[1])
    else:
        create_app()
    run_app()
    Cheshire is distributed in the hope that it will be useful, but WITHOUT ANY
    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for
    more details.

    You should have received a copy of the GNU Affero General Public License
    along with Cheshire.  If not, see <http://www.gnu.org/licenses/>.
'''

from copy import deepcopy
import pymongo, os
from CheshireCat import create_app

config_path = os.path.join(os.getcwd(), 'testing.cfg')
create_app(config_path)

from tests.db_data import generate_db_data

class DBTestCaseMixin(object):
    def init_db_data(self, db_host, db_port, db_name):
        self.db = pymongo.Connection(db_host, int(db_port), safe=True)[db_name]
        if db_name in self.db.connection.database_names():
            #teardown wasn't run last time, so lets run it now.
            self.drop_db_data()
        self.data = generate_db_data()
        for key in self.data:
            mongodb_data = deepcopy(self.data[key])
            self.db[key].insert(mongodb_data)

    def drop_db_data(self):
    Free Software Foundation, either version 3 of the License, or (at your
    option) any later version.

    Cheshire is distributed in the hope that it will be useful, but WITHOUT ANY
    WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
    FOR A PARTICULAR PURPOSE.  See the GNU Affero General Public License for
    more details.

    You should have received a copy of the GNU Affero General Public License
    along with Cheshire.  If not, see <http://www.gnu.org/licenses/>.
"""

import sys, argparse
from CheshireCat import create_app, run_app

if __name__ == "__main__":
    parser = argparse.ArgumentParser()
    parser.add_argument("-d", "--config-dir", help="The directory in which the config is located")
    parser.add_argument("-c", "--config-file", help="The filename of the config file (without the directory name)")
    parser.add_argument("-s", "--configspec-file", help="The filename of the configspec file (without the directory name)")
    args = parser.parse_args()
    kwargs = {}
    if args.config_dir is not None:
        kwargs['_config_dir'] = args.config_dir
    if args.config_file is not None:
        kwargs['_config_filename'] = args.config_file
    if args.configspec_file is not None:
        kwargs['_configspec_filename'] = args.configspec_file
    create_app(**kwargs)
    run_app()