|
a |
|
b/scripts/qiita-env |
|
|
1 |
#!/usr/bin/env python |
|
|
2 |
|
|
|
3 |
# ----------------------------------------------------------------------------- |
|
|
4 |
# Copyright (c) 2014--, The Qiita Development Team. |
|
|
5 |
# |
|
|
6 |
# Distributed under the terms of the BSD 3-clause License. |
|
|
7 |
# |
|
|
8 |
# The full license is in the file LICENSE, distributed with this software. |
|
|
9 |
# ----------------------------------------------------------------------------- |
|
|
10 |
|
|
|
11 |
import click |
|
|
12 |
|
|
|
13 |
import qiita_db as qdb |
|
|
14 |
from qiita_core.environment_manager import test as _test, TEST_RUNNERS |
|
|
15 |
from qiita_core.configuration_manager import ConfigurationManager |
|
|
16 |
|
|
|
17 |
_CONFIG = ConfigurationManager() |
|
|
18 |
|
|
|
19 |
|
|
|
20 |
@click.group() |
|
|
21 |
def env(): |
|
|
22 |
pass |
|
|
23 |
|
|
|
24 |
|
|
|
25 |
@env.command() |
|
|
26 |
@click.option('--load-ontologies/--no-load-ontologies', |
|
|
27 |
default=True, help='If True, ontologies will be loaded. ' |
|
|
28 |
'Cannot be True if this is a test environment.') |
|
|
29 |
@click.option('--download-reference/--no-download-reference', |
|
|
30 |
default=False, help='If True, greengenes reference files will ' |
|
|
31 |
'be downloaded') |
|
|
32 |
@click.option('--add-demo-user/--no-add-demo-user', |
|
|
33 |
default=False, help='If True, then demo@microbio.me will be ' |
|
|
34 |
'added to the database with password ' |
|
|
35 |
'"password"') |
|
|
36 |
def make(load_ontologies, download_reference, add_demo_user): |
|
|
37 |
"""Creates the database specified in config""" |
|
|
38 |
try: |
|
|
39 |
qdb.environment_manager.make_environment( |
|
|
40 |
load_ontologies, download_reference, add_demo_user) |
|
|
41 |
except Exception as e: |
|
|
42 |
if "Database qiita_test already present on the system." not in str(e): |
|
|
43 |
# this will clean our environment so we can try again without |
|
|
44 |
# having to have an other window open to remove the current |
|
|
45 |
# environment. This is fine as we are actually creating a new |
|
|
46 |
# environment. |
|
|
47 |
qdb.environment_manager.drop_environment(False) |
|
|
48 |
raise e |
|
|
49 |
|
|
|
50 |
|
|
|
51 |
@env.command() |
|
|
52 |
@click.option('--ask-for-confirmation/--no-ask-for-confirmation', |
|
|
53 |
default=True, help='If True, will ask for confirmation before ' |
|
|
54 |
'dropping the production environment.') |
|
|
55 |
def drop(ask_for_confirmation): |
|
|
56 |
"""Drops the database specified in config""" |
|
|
57 |
try: |
|
|
58 |
qdb.environment_manager.drop_environment(ask_for_confirmation) |
|
|
59 |
except RuntimeError as e: |
|
|
60 |
raise click.ClickException(str(e)) |
|
|
61 |
|
|
|
62 |
|
|
|
63 |
@env.command() |
|
|
64 |
def clean_test(): |
|
|
65 |
"""Cleans the test database environment. |
|
|
66 |
|
|
|
67 |
In case that the test database is dirty (i.e. the 'qiita' schema is |
|
|
68 |
present), this cleans it up by dropping the 'qiita' schema and rebuilding |
|
|
69 |
the test database. |
|
|
70 |
""" |
|
|
71 |
qdb.environment_manager.clean_test_environment() |
|
|
72 |
|
|
|
73 |
|
|
|
74 |
@env.command() |
|
|
75 |
def patch(): |
|
|
76 |
"""Patches the database schema based on the SETTINGS table |
|
|
77 |
|
|
|
78 |
Pulls the current patch from the settings table and applies all subsequent |
|
|
79 |
patches found in the patches directory. |
|
|
80 |
""" |
|
|
81 |
qdb.environment_manager.patch() |
|
|
82 |
|
|
|
83 |
|
|
|
84 |
@env.command() |
|
|
85 |
@click.option('--runner', required=False, type=click.Choice(TEST_RUNNERS), |
|
|
86 |
default='all', help='Test runner to use') |
|
|
87 |
def test(runner): |
|
|
88 |
"""Test the environment |
|
|
89 |
|
|
|
90 |
Check to make sure that basic services are up and working. These include |
|
|
91 |
connectivity to postgres, and redis. |
|
|
92 |
|
|
|
93 |
Tests are performed both on localhost and ipengines. |
|
|
94 |
""" |
|
|
95 |
_test(runner) |
|
|
96 |
|
|
|
97 |
|
|
|
98 |
@env.command(name="create-portal") |
|
|
99 |
@click.argument('portal', required=True, type=str) |
|
|
100 |
@click.argument('description', required=True, type=str) |
|
|
101 |
def add_portal(portal, description): |
|
|
102 |
"""Creates a new portal on the database""" |
|
|
103 |
try: |
|
|
104 |
qdb.portal.Portal.create(portal, description) |
|
|
105 |
except qdb.exceptions.QiitaDBDuplicateError: |
|
|
106 |
raise click.BadParameter("Portal name already exists!") |
|
|
107 |
|
|
|
108 |
|
|
|
109 |
@env.command(name="remove-portal") |
|
|
110 |
@click.argument('portal', required=True, type=str) |
|
|
111 |
def rem_portal(portal): |
|
|
112 |
"""Removes a portal from the database""" |
|
|
113 |
try: |
|
|
114 |
qdb.portal.Portal.delete(portal) |
|
|
115 |
except qdb.exceptions.QiitaDBError as e: |
|
|
116 |
raise click.BadParameter(str(e)) |
|
|
117 |
except qdb.exceptions.QiitaDBLookupError: |
|
|
118 |
raise click.BadParameter("Portal name does not exist!") |
|
|
119 |
|
|
|
120 |
|
|
|
121 |
if __name__ == '__main__': |
|
|
122 |
env() |