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