Skip to content

Commit 0a29ac2

Browse files
authored
create neccessary "mountpoints" (#3462)
* add function that creates neccessary "mountpoints" * code style * addressing Antonio's suggestion to use get_mountpoint * raise error if src dir is not present at expected location * adding mountpoint directory FASTQ
1 parent fdad618 commit 0a29ac2

File tree

2 files changed

+35
-0
lines changed

2 files changed

+35
-0
lines changed

qiita_db/environment_manager.py

+34
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
@@ -127,6 +128,36 @@ def _download_reference_files():
127128
_insert_processed_params(ref)
128129

129130

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+
130161
def make_environment(load_ontologies, download_reference, add_demo_user):
131162
r"""Creates the new environment specified in the configuration
132163
@@ -397,6 +428,9 @@ def patch(patches_dir=PATCHES_DIR, verbose=False, test=False):
397428
with qdb.sql_connection.TRN:
398429
_populate_test_db()
399430

431+
# create mountpoints as subdirectories in BASE_DATA_DIR
432+
create_mountpoints()
433+
400434
patch_update_sql = "UPDATE settings SET current_patch = %s"
401435
for sql_patch_fp in sql_patch_files[next_patch_index:]:
402436
sql_patch_filename = basename(sql_patch_fp)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+

0 commit comments

Comments
 (0)