77from lib .logging import log_error_exit
88
99
10+ def get_jwt_secret_key_config (env : Env ) -> str :
11+ """
12+ Get the LORIS JWT secret key from the in-database configuration.
13+ """
14+
15+ return _get_config_value (env , 'JWTKey' )
16+
17+
1018def get_patient_id_dicom_header_config (env : Env ) -> Literal ['PatientID' , 'PatientName' ]:
1119 """
1220 Get the DICOM header in which to look for the patient ID from the in-database configuration, or
@@ -34,22 +42,7 @@ def get_data_dir_path_config(env: Env) -> Path:
3442 """
3543
3644 data_dir_path = Path (_get_config_value (env , 'dataDirBasepath' ))
37-
38- if not data_dir_path .is_dir ():
39- log_error_exit (
40- env ,
41- (
42- f"The LORIS base data directory path configuration value '{ data_dir_path } ' does not refer to an"
43- " existing directory."
44- )
45- )
46-
47- if not os .access (data_dir_path , os .R_OK ) or not os .access (data_dir_path , os .W_OK ):
48- log_error_exit (
49- env ,
50- f"Missing read or write permission on the LORIS base data directory '{ data_dir_path } '." ,
51- )
52-
45+ check_loris_directory (env , data_dir_path , "data" )
5346 return data_dir_path
5447
5548
@@ -60,22 +53,7 @@ def get_dicom_archive_dir_path_config(env: Env) -> Path:
6053 """
6154
6255 dicom_archive_dir_path = Path (_get_config_value (env , 'tarchiveLibraryDir' ))
63-
64- if not dicom_archive_dir_path .is_dir ():
65- log_error_exit (
66- env ,
67- (
68- f"The LORIS DICOM archive directory path configuration value '{ dicom_archive_dir_path } ' does not refer"
69- " to an existing directory."
70- ),
71- )
72-
73- if not os .access (dicom_archive_dir_path , os .R_OK ) or not os .access (dicom_archive_dir_path , os .W_OK ):
74- log_error_exit (
75- env ,
76- f"Missing read or write permission on the LORIS DICOM archive directory '{ dicom_archive_dir_path } '." ,
77- )
78-
56+ check_loris_directory (env , dicom_archive_dir_path , "DICOM archive" )
7957 return dicom_archive_dir_path
8058
8159
@@ -87,75 +65,66 @@ def get_default_bids_visit_label_config(env: Env) -> str | None:
8765 return _try_get_config_value (env , 'default_bids_vl' )
8866
8967
90- def get_eeg_viz_enabled_config (env : Env ) -> bool :
68+ def get_ephys_visualization_enabled_config (env : Env ) -> bool :
9169 """
92- Get whether the EEG visualization is enabled from the in-database configuration.
70+ Get whether the electrophysiology visualization is enabled from the in-database configuration.
9371 """
9472
9573 eeg_viz_enabled = _try_get_config_value (env , 'useEEGBrowserVisualizationComponents' )
9674 return eeg_viz_enabled == 'true' or eeg_viz_enabled == '1'
9775
9876
99- def get_eeg_chunks_dir_path_config (env : Env ) -> Path | None :
77+ def get_ephys_chunks_dir_path_config (env : Env ) -> Path | None :
10078 """
101- Get the EEG chunks directory path configuration value from the in-database configuration.
79+ Get the electrophysiology chunks directory path configuration value from the in-database
80+ configuration.
10281 """
10382
104- eeg_chunks_path = _try_get_config_value (env , 'EEGChunksPath' )
105- if eeg_chunks_path is None :
83+ ephys_chunks_path = _try_get_config_value (env , 'EEGChunksPath' )
84+ if ephys_chunks_path is None :
10685 return None
10786
108- eeg_chunks_path = Path (eeg_chunks_path )
87+ ephys_chunks_path = Path (ephys_chunks_path )
88+ check_loris_directory (env , ephys_chunks_path , "electrophysiology chunks" )
89+ return ephys_chunks_path
10990
110- if not eeg_chunks_path .is_dir ():
111- log_error_exit (
112- env ,
113- (
114- f"The configuration value for the LORIS EEG chunks directory path '{ eeg_chunks_path } ' does not refer to"
115- " an existing directory."
116- ),
117- )
11891
119- if not os .access (eeg_chunks_path , os .R_OK ) or not os .access (eeg_chunks_path , os .W_OK ):
120- log_error_exit (
121- env ,
122- f"Missing read or write permission on the LORIS EEG chunks directory '{ eeg_chunks_path } '." ,
123- )
124-
125- return eeg_chunks_path
126-
127-
128- def get_eeg_pre_package_download_dir_path_config (env : Env ) -> Path | None :
92+ def get_ephys_archive_dir_path_config (env : Env ) -> Path | None :
12993 """
130- Get the EEG pre-packaged download path configuration value from the in-database configuration.
94+ Get the electrophysiology archive directory path configuration value from the in-database
95+ configuration.
13196 """
13297
133- eeg_pre_package_path = _try_get_config_value (env , 'prePackagedDownloadPath' )
134- if eeg_pre_package_path is None :
98+ ephys_archive_dir_path = _try_get_config_value (env , 'prePackagedDownloadPath' )
99+ if ephys_archive_dir_path is None :
135100 return None
136101
137- eeg_pre_package_path = Path (eeg_pre_package_path )
102+ ephys_archive_dir_path = Path (ephys_archive_dir_path )
103+ check_loris_directory (env , ephys_archive_dir_path , "electrophysiology archive" )
104+ return ephys_archive_dir_path
138105
139- if not eeg_pre_package_path .is_dir ():
106+
107+ def check_loris_directory (env : Env , dir_path : Path , display_name : str ):
108+ """
109+ Check that a LORIS directory exists and is readable and writable, or exit the program with an
110+ error otherwise.
111+ """
112+
113+ if not dir_path .is_dir ():
140114 log_error_exit (
141115 env ,
142116 (
143- "The configuration value for the LORIS EEG pre-packaged download directory path "
144- f" ' { eeg_pre_package_path } ' does not refer to an existing directory."
117+ f "The LORIS { display_name } directory path configuration value ' { dir_path } ' does not refer to an "
118+ " existing directory."
145119 ),
146120 )
147121
148- if not os .access (eeg_pre_package_path , os .R_OK ) or not os .access (eeg_pre_package_path , os .W_OK ):
122+ if not os .access (dir_path , os .R_OK ) or not os .access (dir_path , os .W_OK ):
149123 log_error_exit (
150124 env ,
151- (
152- "Missing read or write permission on the LORIS EEG pre-packaged download directory"
153- f" '{ eeg_pre_package_path } '."
154- ),
125+ f"Missing read or write permission on the { display_name } directory '{ dir_path } '." ,
155126 )
156127
157- return eeg_pre_package_path
158-
159128
160129def _get_config_value (env : Env , setting_name : str ) -> str :
161130 """
0 commit comments