Skip to content

Commit 20c679a

Browse files
committed
add function that creates neccessary "mountpoints"
1 parent fdad618 commit 20c679a

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

qiita_db/environment_manager.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
# -----------------------------------------------------------------------------
88

99
from os.path import abspath, dirname, join, exists, basename, splitext
10+
from shutil import copytree
1011
from functools import partial
1112
from os import mkdir
1213
import gzip
@@ -126,6 +127,34 @@ def _download_reference_files():
126127

127128
_insert_processed_params(ref)
128129

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)))
129158

130159
def make_environment(load_ontologies, download_reference, add_demo_user):
131160
r"""Creates the new environment specified in the configuration
@@ -397,6 +426,9 @@ def patch(patches_dir=PATCHES_DIR, verbose=False, test=False):
397426
with qdb.sql_connection.TRN:
398427
_populate_test_db()
399428

429+
# create mountpoints as subdirectories in BASE_DATA_DIR
430+
create_mountpoints()
431+
400432
patch_update_sql = "UPDATE settings SET current_patch = %s"
401433
for sql_patch_fp in sql_patch_files[next_patch_index:]:
402434
sql_patch_filename = basename(sql_patch_fp)

0 commit comments

Comments
 (0)