|
7 | 7 | # -----------------------------------------------------------------------------
|
8 | 8 |
|
9 | 9 | from os.path import abspath, dirname, join, exists, basename, splitext
|
| 10 | +from shutil import copytree |
10 | 11 | from functools import partial
|
11 | 12 | from os import mkdir
|
12 | 13 | import gzip
|
@@ -126,6 +127,34 @@ def _download_reference_files():
|
126 | 127 |
|
127 | 128 | _insert_processed_params(ref)
|
128 | 129 |
|
| 130 | +def create_mountpoints(): |
| 131 | + r"""In a fresh qiita setup, sub-directories under qiita_config.base_data_dir |
| 132 | + might not yet exist. To avoid failing in later steps, they are created |
| 133 | + here. |
| 134 | + """ |
| 135 | + with qdb.sql_connection.TRN: |
| 136 | + # Insert the settings values to the database |
| 137 | + sql = """SELECT mountpoint FROM qiita.data_directory |
| 138 | + WHERE active = TRUE""" |
| 139 | + qdb.sql_connection.TRN.add(sql) |
| 140 | + created_subdirs = [] |
| 141 | + for subdir in qdb.sql_connection.TRN.execute_fetchflatten(): |
| 142 | + if not exists(join(qiita_config.base_data_dir, subdir)): |
| 143 | + if qiita_config.test_environment and \ |
| 144 | + exists(get_support_file('test_data', subdir)): |
| 145 | + # if in test mode, we want to potentially fill the |
| 146 | + # new directory with according test data |
| 147 | + copytree(get_support_file('test_data', subdir), |
| 148 | + join(qiita_config.base_data_dir, subdir)) |
| 149 | + else: |
| 150 | + # in production mode, an empty directory is created |
| 151 | + mkdir(join(qiita_config.base_data_dir, subdir)) |
| 152 | + created_subdirs.append(subdir) |
| 153 | + |
| 154 | + if len(created_subdirs) > 0: |
| 155 | + print("Created %i sub-directories as 'mount points' in '%s': %s" % ( |
| 156 | + len(created_subdirs), qiita_config.base_data_dir, |
| 157 | + ', '.join(created_subdirs))) |
129 | 158 |
|
130 | 159 | def make_environment(load_ontologies, download_reference, add_demo_user):
|
131 | 160 | r"""Creates the new environment specified in the configuration
|
@@ -397,6 +426,9 @@ def patch(patches_dir=PATCHES_DIR, verbose=False, test=False):
|
397 | 426 | with qdb.sql_connection.TRN:
|
398 | 427 | _populate_test_db()
|
399 | 428 |
|
| 429 | + # create mountpoints as subdirectories in BASE_DATA_DIR |
| 430 | + create_mountpoints() |
| 431 | + |
400 | 432 | patch_update_sql = "UPDATE settings SET current_patch = %s"
|
401 | 433 | for sql_patch_fp in sql_patch_files[next_patch_index:]:
|
402 | 434 | sql_patch_filename = basename(sql_patch_fp)
|
|
0 commit comments