|
12 | 12 | from one.converters import ConversionMixin |
13 | 13 | import one.alf.exceptions as alferr |
14 | 14 | from one.util import datasets2records, ensure_list |
| 15 | +from one.api import ONE |
15 | 16 |
|
16 | 17 | import ibllib |
17 | 18 | import ibllib.io.extractors.base |
@@ -78,6 +79,25 @@ def register_dataset(file_list, one=None, exists=False, versions=None, **kwargs) |
78 | 79 | assert all(Path(f).exists() for f in file_list) |
79 | 80 |
|
80 | 81 | client = IBLRegistrationClient(one) |
| 82 | + |
| 83 | + # Check for protected datasets |
| 84 | + # Account for cases where we are connected to cortex lab database |
| 85 | + if one.alyx.base_url == 'https://alyx.cortexlab.net': |
| 86 | + protected_status = IBLRegistrationClient( |
| 87 | + ONE(base_url='https://alyx.internationalbrainlab.org')).check_protected_files(file_list) |
| 88 | + else: |
| 89 | + protected_status = client.check_protected_files(file_list) |
| 90 | + |
| 91 | + if isinstance(protected_status, list): |
| 92 | + protected = any(d['status_code'] == 403 for d in protected_status) |
| 93 | + else: |
| 94 | + protected = protected_status['status_code'] == 403 |
| 95 | + |
| 96 | + # If we find a protected dataset, and we don't have a force=True flag, raise an error |
| 97 | + if protected and not kwargs.pop('force', False): |
| 98 | + raise (FileExistsError, 'Protected datasets were found in the file list. To force the registration of datasets ' |
| 99 | + 'add the force=True argument.') |
| 100 | + |
81 | 101 | # If the repository is specified then for the registration client we want server_only=True to |
82 | 102 | # make sure we don't make any other repositories for the lab |
83 | 103 | if kwargs.get('repository') and not kwargs.get('server_only', False): |
|
0 commit comments