diff --git a/.travis.yml b/.travis.yml index ce01bdbb2..db008baa2 100644 --- a/.travis.yml +++ b/.travis.yml @@ -16,7 +16,7 @@ install: - pip install coveralls - pip install . script: - - qiita_db make_test_env + - qiita_env make_test_env - nosetests --with-doctest - pep8 qiita_db qiita_core qiita_pet setup.py # we need to run the test suite from setup.py for coveralls to grab the info diff --git a/INSTALL.md b/INSTALL.md index 5436a0080..54b5ddd03 100644 --- a/INSTALL.md +++ b/INSTALL.md @@ -35,7 +35,7 @@ Once you have [PostgresSQL](http://www.postgresql.org/download/) and [redis](htt echo "export QIITA_CONFIG_FP=$QIITA_DIR/qiita_core/support_files/config_demo.txt" >> ~/.bashrc source ~/.bashrc pip install https://github.com/biocore/qiita/archive/master.zip -qiita_db make_demo_env +qiita_env make_demo_env ``` ## If using other operating systems that are not Ubuntu @@ -48,4 +48,4 @@ createuser -s postgres -d If you receive the following error, you can ignore this step and continue with the qiita installation: ```bash createuser: creation of new role failed: ERROR: role "postgres" already exists -``` \ No newline at end of file +``` diff --git a/scripts/qiita_db b/scripts/qiita_db index 5cc25499e..6cabd06d9 100755 --- a/scripts/qiita_db +++ b/scripts/qiita_db @@ -10,14 +10,6 @@ import click -from qiita_db.environment_manager import (make_test_environment, - make_production_environment, - drop_test_environment, - clean_test_environment, - make_demo_environment, - drop_demo_environment, - DFLT_BASE_DATA_FOLDER, - DFLT_BASE_WORK_FOLDER) from qiita_db.commands import make_study_from_cmd @@ -26,67 +18,7 @@ def qiita_db(): pass -@click.command() -@click.option('--base_data_folder', default=DFLT_BASE_DATA_FOLDER, - help="The folder where the test data files are stored") -@click.option('--base_work_folder', default=DFLT_BASE_WORK_FOLDER, - help="The folder where the actively worked on files are stored") -@click.option('--user', default='postgres', - help="The database user to connect to the database") -@click.option('--host', default='localhost', - help='The host where the database lives') -def make_test_env(base_data_folder, base_work_folder, user, host): - """Creates a test database environment. - - Creates a new database called `qiita_test` tailored for testing purposes - and initializes the `settings` table of such database - """ - make_test_environment(base_data_folder, base_work_folder, user, None, host) - - -@click.command() -@click.option('--user', default='postgres', - help="The database user to connect to the database") -@click.option('--host', default='localhost', - help='The host where the database lives') -def clean_test_env(user, host): - """Cleans the test database environment. - - In case that the test database is dirty (i.e. the 'qiita' schema is - present), this cleans it up by dropping the 'qiita' schema. - """ - clean_test_environment(user, None, host) - - -@click.command() -@click.option('--user', default='postgres', - help="The database user to connect to the database") -@click.option('--host', default='localhost', - help='The host where the database lives') -def drop_test_env(user, host): - """Drops the test database environment. - - If the `settings` table is modified, the test database environment should - be rebuilt. This command allows to drop the old one. - """ - drop_test_environment(user, None, host) - - -@click.command() -@click.option('--base_data_folder', default=DFLT_BASE_DATA_FOLDER, - help="The folder where the demo data files are stored") -@click.option('--base_work_folder', default=DFLT_BASE_WORK_FOLDER, - help="The folder where the actively worked on files are stored") -@click.option('--user', default='postgres', - help="The database user to connect to the database") -@click.option('--host', default='localhost', - help='The host where the database lives') -def make_production_env(): - """TODO: Not implemented""" - make_production_environment() - - -@click.command() +@qiita_db.command() @click.option('--owner', help="The email address of the owner of the study") @click.option('--title', help="The title of the study") @click.option('--info', type=click.File(mode='r'), @@ -96,36 +28,5 @@ def insert_study_to_db(owner, title, info): make_study_from_cmd(owner, title, info) -@click.command() -@click.option('--base_data_folder', default=DFLT_BASE_DATA_FOLDER, - help="The folder where the test data files are stored") -@click.option('--base_work_folder', default=DFLT_BASE_WORK_FOLDER, - help="The folder where the jobs perform the I/O") -@click.option('--user', default='postgres', - help="The database user to connect to the database") -@click.option('--host', default='localhost', - help='The host where the database lives') -def make_demo_env(base_data_folder, base_work_folder, user, host): - """Creates a demo database environment""" - make_demo_environment(base_data_folder, base_work_folder, user, None, host) - - -@click.command() -@click.option('--user', default='postgres', - help="The database user to connect to the database") -@click.option('--host', default='localhost', - help='The host where the database lives') -def drop_demo_env(user, host): - """Drops the demo database environment.""" - drop_demo_environment(user, None, host) - -qiita_db.add_command(make_test_env) -qiita_db.add_command(clean_test_env) -qiita_db.add_command(drop_test_env) -qiita_db.add_command(make_production_env) -qiita_db.add_command(make_demo_env) -qiita_db.add_command(drop_demo_env) -qiita_db.add_command(insert_study_to_db) - if __name__ == '__main__': qiita_db() diff --git a/scripts/qiita_env b/scripts/qiita_env new file mode 100755 index 000000000..1e7663f4e --- /dev/null +++ b/scripts/qiita_env @@ -0,0 +1,113 @@ +#!/usr/bin/env python + +# ----------------------------------------------------------------------------- +# Copyright (c) 2014--, The Qiita Development Team. +# +# Distributed under the terms of the BSD 3-clause License. +# +# The full license is in the file LICENSE, distributed with this software. +# ----------------------------------------------------------------------------- + +import click + +from qiita_db.environment_manager import (make_test_environment, + make_production_environment, + drop_test_environment, + clean_test_environment, + make_demo_environment, + drop_demo_environment, + DFLT_BASE_DATA_FOLDER, + DFLT_BASE_WORK_FOLDER) + + +@click.group() +def qiita_env(): + pass + + +@qiita_env.command() +@click.option('--base_data_folder', default=DFLT_BASE_DATA_FOLDER, + help="The folder where the test data files are stored") +@click.option('--base_work_folder', default=DFLT_BASE_WORK_FOLDER, + help="The folder where the actively worked on files are stored") +@click.option('--user', default='postgres', + help="The database user to connect to the database") +@click.option('--host', default='localhost', + help='The host where the database lives') +def make_test_env(base_data_folder, base_work_folder, user, host): + """Creates a test database environment. + + Creates a new database called `qiita_test` tailored for testing purposes + and initializes the `settings` table of such database + """ + make_test_environment(base_data_folder, base_work_folder, user, None, host) + + +@qiita_env.command() +@click.option('--user', default='postgres', + help="The database user to connect to the database") +@click.option('--host', default='localhost', + help='The host where the database lives') +def clean_test_env(user, host): + """Cleans the test database environment. + + In case that the test database is dirty (i.e. the 'qiita' schema is + present), this cleans it up by dropping the 'qiita' schema. + """ + clean_test_environment(user, None, host) + + +@qiita_env.command() +@click.option('--user', default='postgres', + help="The database user to connect to the database") +@click.option('--host', default='localhost', + help='The host where the database lives') +def drop_test_env(user, host): + """Drops the test database environment. + + If the `settings` table is modified, the test database environment should + be rebuilt. This command allows to drop the old one. + """ + drop_test_environment(user, None, host) + + +@qiita_env.command() +@click.option('--base_data_folder', default=DFLT_BASE_DATA_FOLDER, + help="The folder where the demo data files are stored") +@click.option('--base_work_folder', default=DFLT_BASE_WORK_FOLDER, + help="The folder where the actively worked on files are stored") +@click.option('--user', default='postgres', + help="The database user to connect to the database") +@click.option('--host', default='localhost', + help='The host where the database lives') +def make_production_env(): + """TODO: Not implemented""" + make_production_environment() + + +@qiita_env.command() +@click.option('--base_data_folder', default=DFLT_BASE_DATA_FOLDER, + help="The folder where the test data files are stored") +@click.option('--base_work_folder', default=DFLT_BASE_WORK_FOLDER, + help="The folder where the jobs perform the I/O") +@click.option('--user', default='postgres', + help="The database user to connect to the database") +@click.option('--host', default='localhost', + help='The host where the database lives') +def make_demo_env(base_data_folder, base_work_folder, user, host): + """Creates a demo database environment""" + make_demo_environment(base_data_folder, base_work_folder, user, None, host) + + +@qiita_env.command() +@click.option('--user', default='postgres', + help="The database user to connect to the database") +@click.option('--host', default='localhost', + help='The host where the database lives') +def drop_demo_env(user, host): + """Drops the demo database environment.""" + drop_demo_environment(user, None, host) + + +if __name__ == '__main__': + qiita_env()