|
1 | 1 | """Mixins for entities that can have their storage location and project settings configured.""" |
2 | 2 |
|
3 | 3 | import asyncio |
4 | | -from typing import TYPE_CHECKING, Any, List, Optional, Union |
| 4 | +from typing import Any, List, Optional, Union |
5 | 5 |
|
6 | 6 | from synapseclient import Synapse |
7 | 7 | from synapseclient.core.async_utils import async_to_sync, otel_trace_method |
| 8 | +from synapseclient.models.project_setting import ProjectSetting |
8 | 9 | from synapseclient.models.protocols.storage_location_mixin_protocol import ( |
9 | 10 | StorageLocationConfigurableSynchronousProtocol, |
10 | 11 | ) |
|
16 | 17 | ) |
17 | 18 | from synapseclient.models.services.migration_types import MigrationResult |
18 | 19 |
|
19 | | -if TYPE_CHECKING: |
20 | | - from synapseclient.models.project_setting import ProjectSetting |
21 | | - |
22 | 20 | # Default storage location ID used by Synapse |
23 | 21 | DEFAULT_STORAGE_LOCATION_ID = 1 |
24 | 22 |
|
@@ -200,22 +198,31 @@ async def migrate_indexed_files_async( |
200 | 198 | This is the second step in migrating files to a new storage location. |
201 | 199 | Files must first be indexed using `index_files_for_migration`. |
202 | 200 |
|
| 201 | + **Interactive confirmation:** When called from an interactive shell and |
| 202 | + ``force=False`` (the default), this method will print the number of items |
| 203 | + queued for migration and prompt for confirmation before proceeding. If |
| 204 | + standard output is not connected to an interactive terminal (e.g. a script |
| 205 | + or CI environment), migration is aborted unless ``force=True`` is set. |
| 206 | +
|
203 | 207 | Arguments: |
204 | 208 | db_path: Path to the SQLite database file created by |
205 | 209 | `index_files_for_migration`. You can get this from the |
206 | 210 | MigrationResult.db_path returned by index_files_for_migration. |
207 | 211 | create_table_snapshots: Whether to create table snapshots before |
208 | 212 | migrating table files. |
209 | 213 | continue_on_error: Whether to continue migration if an error occurs. |
210 | | - force: Whether to force migration of files that have already been |
211 | | - migrated. Also bypasses interactive confirmation. |
| 214 | + force: Skip the interactive confirmation prompt and proceed with |
| 215 | + migration automatically. Set to ``True`` when running |
| 216 | + non-interactively (scripts, CI, automated pipelines). |
| 217 | + Defaults to False. |
212 | 218 | synapse_client: If not passed in and caching was not disabled by |
213 | 219 | `Synapse.allow_client_caching(False)` this will use the last created |
214 | 220 | instance from the Synapse class constructor. |
215 | 221 |
|
216 | 222 | Returns: |
217 | 223 | A MigrationResult object containing migration statistics, or None |
218 | | - if the user declined the confirmation prompt. |
| 224 | + if migration was aborted (user declined the confirmation prompt, or |
| 225 | + the session is non-interactive and force=False). |
219 | 226 |
|
220 | 227 | Example: Migrating indexed files |
221 | 228 | Migrate previously indexed files: |
@@ -338,8 +345,6 @@ async def main(): |
338 | 345 |
|
339 | 346 | asyncio.run(main()) |
340 | 347 | """ |
341 | | - from synapseclient.models.project_setting import ProjectSetting |
342 | | - |
343 | 348 | if not self.id: |
344 | 349 | raise ValueError("The entity must have an id set.") |
345 | 350 |
|
@@ -404,8 +409,6 @@ async def main(): |
404 | 409 |
|
405 | 410 | asyncio.run(main()) |
406 | 411 | """ |
407 | | - from synapseclient.models.project_setting import ProjectSetting |
408 | | - |
409 | 412 | if not self.id: |
410 | 413 | raise ValueError("The entity must have an id set.") |
411 | 414 |
|
@@ -452,4 +455,6 @@ async def main(): |
452 | 455 |
|
453 | 456 | asyncio.run(main()) |
454 | 457 | """ |
| 458 | + if not setting_id: |
| 459 | + raise ValueError("The id is required to delete a project setting.") |
455 | 460 | await ProjectSetting(id=setting_id).delete_async(synapse_client=synapse_client) |
0 commit comments