divbase-cli 0.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,161 @@
1
+ """
2
+ config subcommand for the divbase-cli package.
3
+
4
+ Controls the user config file stored at "~/.config/.divbase_tools.yaml" (unless specified otherwise).
5
+ """
6
+
7
+ import typer
8
+ from rich import print
9
+ from rich.console import Console
10
+ from rich.table import Table
11
+
12
+ from divbase_cli.cli_commands.shared_args_options import FORMAT_AS_TSV_OPTION
13
+ from divbase_cli.cli_config import cli_settings
14
+ from divbase_cli.user_config import (
15
+ load_user_config,
16
+ )
17
+ from divbase_cli.utils import print_rich_table_as_tsv
18
+
19
+ config_app = typer.Typer(help="Manage your user configuration file for the DivBase CLI.", no_args_is_help=True)
20
+
21
+
22
+ @config_app.command("add")
23
+ def add_project_command(
24
+ name: str = typer.Argument(..., help="Name of the project to add to your config file."),
25
+ divbase_url: str = typer.Option(
26
+ cli_settings.DIVBASE_API_URL,
27
+ "--divbase-url",
28
+ "-u",
29
+ help="DivBase API URL associated with this project.",
30
+ ),
31
+ make_default: bool = typer.Option(
32
+ False,
33
+ "--default",
34
+ "-d",
35
+ help="Set this project as the default project in your config file.",
36
+ ),
37
+ ):
38
+ """Add a new project to your user configuration file."""
39
+ config = load_user_config()
40
+ project = config.add_project(
41
+ name=name,
42
+ divbase_url=divbase_url,
43
+ is_default=make_default,
44
+ )
45
+
46
+ print(f"Project: '{project.name}' added to your config.")
47
+ print(f"The URL: {project.divbase_url} was set as the DivBase API URL for this project.")
48
+
49
+ if make_default:
50
+ print(f"Project '{project.name}' is now set as your default project")
51
+ else:
52
+ print(f"To make '{project.name}' your default project you can run: 'divbase config set-default {project.name}'")
53
+
54
+
55
+ @config_app.command("rm")
56
+ def remove_project_command(
57
+ name: str = typer.Argument(..., help="Name of the project to remove from your user configuration file."),
58
+ ):
59
+ """Remove a project from your user configuration file."""
60
+ config = load_user_config()
61
+ removed_project = config.remove_project(name)
62
+
63
+ if not removed_project:
64
+ print(f"Nothing to do, the project '{name}' was not found in your user config")
65
+ else:
66
+ print(f"The project '{removed_project}' was removed from your config.")
67
+
68
+
69
+ @config_app.command("set-default")
70
+ def set_default_project_command(
71
+ name: str = typer.Argument(..., help="Name of the project to set as the default."),
72
+ ):
73
+ """
74
+ Set the default project to use in all divbase-cli commands.
75
+
76
+ The project must already be added to your config file using the 'add' command.
77
+ """
78
+ config = load_user_config()
79
+ default_project_name = config.set_default_project(name=name)
80
+ print(f"Default project is now set to '{default_project_name}'.")
81
+
82
+
83
+ @config_app.command("show-default")
84
+ def show_default_project_command() -> None:
85
+ """Print the currently set default project to the console."""
86
+ config = load_user_config()
87
+
88
+ if config.default_project:
89
+ print(config.default_project)
90
+ else:
91
+ print("No default project is set in the user configuration file.")
92
+
93
+
94
+ @config_app.command("set-dload-dir")
95
+ def set_default_dload_dir_command(
96
+ download_dir: str = typer.Argument(
97
+ ...,
98
+ help="Set the default directory to download files to. "
99
+ "By default files are downloaded to the current working directory. "
100
+ "Do not use a relative path. To use the current working directory (where each command is run from), use '.' as the argument.",
101
+ ),
102
+ ):
103
+ """
104
+ Set the default download directory in your user configuration file.
105
+
106
+ This is by default unset, meaning files will be downloaded to the current working directory.
107
+ """
108
+ config = load_user_config()
109
+ dload_dir = config.set_default_download_dir(download_dir=download_dir)
110
+ if dload_dir == ".":
111
+ print("The default download directory will be whereever you run the command from.")
112
+ else:
113
+ print(f"The default download directory is now set to: {dload_dir}.")
114
+
115
+
116
+ @config_app.command("show")
117
+ def show_user_config(format_output_as_tsv: bool = FORMAT_AS_TSV_OPTION):
118
+ """Pretty print the contents of your current config file."""
119
+ config = load_user_config()
120
+ table = Table(title="\nProjects in your DivBase CLI user config file")
121
+ table.add_column("Project Name", style="cyan", no_wrap=False)
122
+ table.add_column("DivBase URL", style="green", no_wrap=True)
123
+ table.add_column("Is default", style="yellow", no_wrap=False)
124
+
125
+ for project in config.projects:
126
+ is_default = "Yes" if project.name == config.default_project else ""
127
+ table.add_row(project.name, project.divbase_url, is_default)
128
+
129
+ if format_output_as_tsv:
130
+ print_rich_table_as_tsv(table=table)
131
+ return
132
+
133
+ console = Console()
134
+
135
+ console.print(
136
+ f"[bold]Your DivBase user configuration file's contents located at:[/bold] '{cli_settings.CONFIG_PATH.resolve()}'\n"
137
+ )
138
+
139
+ if not config.default_download_dir:
140
+ dload_dir_info = "Not specified, meaning the working directory of wherever you run the download command from."
141
+ elif config.default_download_dir == ".":
142
+ dload_dir_info = "Working directory of wherever you run the download command from."
143
+ else:
144
+ dload_dir_info = config.default_download_dir
145
+ console.print(f"[bold]Default Download Directory:[/bold] '{dload_dir_info}'")
146
+
147
+ if config.logged_in_url and config.logged_in_email:
148
+ console.print(f"[bold]You're logged into a DivBase server at URL:[/bold] '{config.logged_in_url}'")
149
+ console.print(f"[bold]Logged in with email:[/bold] '{config.logged_in_email}'")
150
+ else:
151
+ console.print(
152
+ "[bold]No login session.[/bold] If you've set up a personal access token, that will be used instead. "
153
+ f"See: {cli_settings.DIVBASE_DOCS_URL}/user-guides/account-management/#personal-access-tokens"
154
+ )
155
+
156
+ if not config.projects:
157
+ console.print("[bold]No projects defined in your user config file.[/bold]")
158
+ console.print("You can add a project using the command: 'divbase-cli config add <project_name>'")
159
+ return
160
+
161
+ console.print(table)
@@ -0,0 +1,202 @@
1
+ """CLI commands for managing project versions in DivBase."""
2
+
3
+ import typer
4
+ from rich import print
5
+ from rich.table import Table
6
+
7
+ from divbase_cli.cli_commands.shared_args_options import FORMAT_AS_TSV_OPTION, PROJECT_NAME_OPTION
8
+ from divbase_cli.config_resolver import resolve_and_authenticate_project
9
+ from divbase_cli.services.project_versions import (
10
+ add_version_command,
11
+ delete_version_command,
12
+ get_version_details_command,
13
+ list_versions_command,
14
+ update_version_command,
15
+ )
16
+ from divbase_cli.utils import print_rich_table_as_tsv
17
+ from divbase_lib.utils import format_datetime_for_cli, format_file_size
18
+
19
+ version_app = typer.Typer(
20
+ no_args_is_help=True,
21
+ help="Add, view and remove versions representing the state of all files in the entire project at the current timestamp.",
22
+ )
23
+
24
+
25
+ @version_app.command("add")
26
+ def add_version(
27
+ name: str = typer.Argument(help="Name of the version (e.g., semantic version).", show_default=False),
28
+ description: str = typer.Option("", help="Optional description of the version."),
29
+ project: str | None = PROJECT_NAME_OPTION,
30
+ ):
31
+ """Add a new project version entry which specifies the current state of all files in the project at the current timestamp."""
32
+ project_config = resolve_and_authenticate_project(project_name=project)
33
+ add_version_response = add_version_command(
34
+ name=name,
35
+ description=description,
36
+ project_name=project_config.name,
37
+ divbase_base_url=project_config.divbase_url,
38
+ )
39
+ print(f"New version: '{add_version_response.name}' added to the project: '{project_config.name}'")
40
+
41
+
42
+ @version_app.command("update")
43
+ def update_version(
44
+ version_name: str = typer.Argument(help="Name of the existing version you want to modify", show_default=False),
45
+ new_name: str | None = typer.Option(
46
+ None, "--new-name", "-n", help="New name for the version. If not specified, the name will remain unchanged."
47
+ ),
48
+ new_description: str | None = typer.Option(
49
+ None,
50
+ "--new-description",
51
+ "-d",
52
+ help="Optional new description of the version. If not specified, the description will remain unchanged.",
53
+ ),
54
+ project: str | None = PROJECT_NAME_OPTION,
55
+ ):
56
+ """
57
+ Update an existing project version entry's name and/or description.
58
+
59
+ The files and timestamp associated with a version entry are immutable and cannot be changed.
60
+ This is by design to ensure version entries are representations of the project's state at the timepoint they were created at.
61
+ You can create a new version entry to capture the current state of the project instead.
62
+
63
+ To see your current version entries run: `divbase-cli version ls`
64
+ """
65
+ if not new_name and not new_description:
66
+ raise typer.BadParameter(
67
+ "No updates specified. Please provide a new name (--new-name) and/or description (--new-description) to update for this entry."
68
+ )
69
+
70
+ project_config = resolve_and_authenticate_project(project_name=project)
71
+ updated_version = update_version_command(
72
+ project_name=project_config.name,
73
+ divbase_base_url=project_config.divbase_url,
74
+ version_name=version_name,
75
+ new_name=new_name,
76
+ new_description=new_description,
77
+ )
78
+ if new_name and new_name != version_name:
79
+ print(f"Version '{version_name}' renamed to '{updated_version.name}' in project: '{project_config.name}'")
80
+ else:
81
+ print(f"Version '{updated_version.name}' updated in project: '{project_config.name}'")
82
+ if new_description:
83
+ print(f"New description: '{updated_version.description}'")
84
+
85
+
86
+ @version_app.command("ls")
87
+ def list_versions(
88
+ project: str | None = PROJECT_NAME_OPTION,
89
+ include_deleted: bool = typer.Option(False, help="Include soft-deleted versions in the listing."),
90
+ format_output_as_tsv: bool = FORMAT_AS_TSV_OPTION,
91
+ ):
92
+ """
93
+ List all entries in the project versioning file.
94
+
95
+ Displays version name, creation timestamp, and description for each project version.
96
+ If you specify --include-deleted, soft-deleted versions will also be shown.
97
+ Soft-deleted versions can be restored by a DivBase admin within 30 days of deletion.
98
+ """
99
+ project_config = resolve_and_authenticate_project(project_name=project)
100
+ versions_info = list_versions_command(
101
+ project_name=project_config.name,
102
+ include_deleted=include_deleted,
103
+ divbase_base_url=project_config.divbase_url,
104
+ )
105
+
106
+ if not versions_info:
107
+ print(f"No versions found for project: {project_config.name}.")
108
+ return
109
+
110
+ table = Table(title=f"Versions for {project_config.name}")
111
+ table.add_column("Version", style="cyan", no_wrap=True)
112
+ table.add_column("Created ", style="magenta", no_wrap=False)
113
+ table.add_column("Last Updated", style="blue", no_wrap=False)
114
+ table.add_column("Description", style="green", no_wrap=False)
115
+ if include_deleted:
116
+ table.add_column("Soft Deleted", style="red", no_wrap=True)
117
+
118
+ for version in versions_info:
119
+ name = version.name
120
+ desc = version.description or "No description provided"
121
+ created_at = format_datetime_for_cli(dt=version.created_at)
122
+ updated_at = format_datetime_for_cli(dt=version.updated_at)
123
+ if include_deleted:
124
+ soft_deleted = "Yes" if version.is_deleted else "No"
125
+ table.add_row(name, created_at, updated_at, desc, soft_deleted)
126
+ else:
127
+ table.add_row(name, created_at, updated_at, desc)
128
+
129
+ if not format_output_as_tsv:
130
+ print(table)
131
+ else:
132
+ print_rich_table_as_tsv(table=table)
133
+
134
+
135
+ @version_app.command("info")
136
+ def get_version_info(
137
+ version: str = typer.Argument(help="Specific version to retrieve information for"),
138
+ project: str | None = PROJECT_NAME_OPTION,
139
+ format_output_as_tsv: bool = FORMAT_AS_TSV_OPTION,
140
+ ):
141
+ """
142
+ Provide detailed information about a user specified project version, including all files present and their unique hashes.
143
+ """
144
+ project_config = resolve_and_authenticate_project(project_name=project)
145
+ version_details = get_version_details_command(
146
+ project_name=project_config.name,
147
+ divbase_base_url=project_config.divbase_url,
148
+ version_name=version,
149
+ )
150
+
151
+ table = Table(title=f"Project version files for {project_config.name}")
152
+ table.add_column("Name", style="cyan", no_wrap=True)
153
+ table.add_column("Version ID", style="magenta", no_wrap=True)
154
+ table.add_column("MD5 Checksum", style="green", no_wrap=True)
155
+ table.add_column("Size", style="yellow", no_wrap=False)
156
+ for object_name, file_details in version_details.files.items():
157
+ file_size = format_file_size(file_details["size"])
158
+
159
+ table.add_row(
160
+ object_name,
161
+ file_details["version_id"],
162
+ file_details["etag"],
163
+ file_size,
164
+ )
165
+
166
+ if not format_output_as_tsv:
167
+ print(f"Project version entry for project: '{project_config.name}' with name: '{version_details.name}'")
168
+ print(f"Entry created at: {format_datetime_for_cli(dt=version_details.created_at)}")
169
+ print(f"Entry last updated at: {format_datetime_for_cli(dt=version_details.updated_at)}")
170
+ if version_details.description:
171
+ print(f"Description: {version_details.description}")
172
+ if version_details.is_deleted:
173
+ print(
174
+ "[red]WARNING: This version has been soft-deleted and will soon be permanently deleted unless restored - Contact a DivBase admin to prevent this.[/red]"
175
+ )
176
+ print(table)
177
+ else:
178
+ print_rich_table_as_tsv(table=table)
179
+
180
+
181
+ @version_app.command("rm")
182
+ def delete_version(
183
+ name: str = typer.Argument(help="Name of the version (e.g., semantic version).", show_default=False),
184
+ project: str | None = PROJECT_NAME_OPTION,
185
+ ):
186
+ """
187
+ Delete a version entry in the project versioning table. This does not delete the files themselves.
188
+
189
+ Deleted version entries older than 30 days will be permanently deleted.
190
+ You can ask a DivBase admin to restore a deleted version within that time period.
191
+ """
192
+ project_config = resolve_and_authenticate_project(project_name=project)
193
+ deleted_version = delete_version_command(
194
+ project_name=project_config.name,
195
+ divbase_base_url=project_config.divbase_url,
196
+ version_name=name,
197
+ )
198
+ if deleted_version.already_deleted:
199
+ date_deleted = format_datetime_for_cli(dt=deleted_version.date_deleted)
200
+ print(f"The version: '{deleted_version.name}' has already been soft-deleted on {date_deleted}.")
201
+ else:
202
+ print(f"The version: '{deleted_version.name}' was deleted from the project: '{project_config.name}'")
@@ -0,0 +1,80 @@
1
+ """
2
+ Settings for DivBase CLI.
3
+
4
+ This class creates a single 'settings' object at module load time that can be imported and used throughout the entire package.
5
+
6
+ The user config and tokens are stored in the users local app dir:
7
+ https://typer.tiangolo.com/tutorial/app-dir/
8
+ """
9
+
10
+ import os
11
+ from dataclasses import dataclass, field
12
+ from pathlib import Path
13
+
14
+ import typer
15
+ from pydantic import SecretStr
16
+
17
+ APP_NAME = "divbase-cli"
18
+ APP_DIR = Path(typer.get_app_dir(APP_NAME))
19
+ DEFAULT_METADATA_TSV_NAME = "sample_metadata.tsv"
20
+ DEFAULT_LOG_LEVEL = "INFO"
21
+ DEV_MODE = os.getenv("DIVBASE_DEV", "0") == "1"
22
+ DEFAULT_CONFIG_PATH = APP_DIR / "config.yaml"
23
+ DEFAULT_TOKENS_PATH = APP_DIR / ".secrets"
24
+ DEFAULT_PATS_PATH = APP_DIR / ".pat" # no plural because only 1 stored.
25
+
26
+ if DEV_MODE:
27
+ DEFAULT_DIVBASE_API_URL = "http://localhost:8000/api"
28
+ DEFAULT_LOGGING_ON = "1"
29
+ DEFAULT_TRACEBACKS_ON = "1"
30
+ DEFAULT_DIVBASE_DOCS_URL = "http://localhost:8008/divbase"
31
+ else:
32
+ DEFAULT_DIVBASE_API_URL = "https://divbase.scilifelab-2-prod.sys.kth.se/api"
33
+ DEFAULT_LOGGING_ON = "0"
34
+ DEFAULT_TRACEBACKS_ON = "0"
35
+ DEFAULT_DIVBASE_DOCS_URL = "https://scilifelabdatacentre.github.io/divbase"
36
+
37
+
38
+ @dataclass
39
+ class DivBaseCLISettings:
40
+ """
41
+ Settings for DivBase CLI.
42
+
43
+ You do not need to create an instance of this class yourself,
44
+ instead, import the 'cli_settings' instance created at this module's load time.
45
+ """
46
+
47
+ CONFIG_PATH: Path = Path(os.getenv("DIVBASE_CLI_CONFIG_PATH", DEFAULT_CONFIG_PATH))
48
+
49
+ # for tokens stored via OS keyring, we use these to define a unique lookup key.
50
+ KEYRING_SERVICE: str = os.getenv("DIVBASE_KEYRING_SERVICE", "divbase-cli")
51
+ KEYRING_TOKENS_USERNAME: str = "tokens"
52
+ KEYRING_PATS_USERNAME: str = "pat"
53
+ # Fallback paths for tokens (JWTs) and PATs storage if keyring cannot be used on the device.
54
+ TOKENS_FALLBACK_PATH: Path = Path(os.getenv("DIVBASE_CLI_TOKENS_PATH", DEFAULT_TOKENS_PATH))
55
+ PATS_FALLBACK_PATH: Path = Path(os.getenv("DIVBASE_CLI_PATS_PATH", DEFAULT_PATS_PATH))
56
+
57
+ DIVBASE_DOCS_URL: str = os.getenv("DIVBASE_DOCS_URL", DEFAULT_DIVBASE_DOCS_URL)
58
+ DIVBASE_API_URL: str = os.getenv("DIVBASE_API_URL", DEFAULT_DIVBASE_API_URL)
59
+ METADATA_TSV_NAME: str = os.getenv("DIVBASE_METADATA_TSV_NAME", DEFAULT_METADATA_TSV_NAME)
60
+ TRACEBACKS_ON: bool = os.getenv("DIVBASE_TRACEBACKS_ON", DEFAULT_TRACEBACKS_ON) == "1"
61
+ LOGGING_ON: bool = os.getenv("DIVBASE_LOGGING_ON", DEFAULT_LOGGING_ON) == "1"
62
+ LOG_LEVEL: str = os.getenv("DIVBASE_LOG_LEVEL", DEFAULT_LOG_LEVEL).upper()
63
+
64
+ DIVBASE_API_PAT: SecretStr | None = field(init=False)
65
+
66
+ def __post_init__(self):
67
+ if os.getenv("DIVBASE_API_PAT"):
68
+ self.DIVBASE_API_PAT = SecretStr(os.environ["DIVBASE_API_PAT"])
69
+ else:
70
+ self.DIVBASE_API_PAT = None
71
+
72
+ valid_levels = ["CRITICAL", "ERROR", "WARNING", "INFO", "DEBUG", "NOTSET"]
73
+ if self.LOG_LEVEL not in valid_levels:
74
+ raise ValueError(f"Invalid LOG_LEVEL: {self.LOG_LEVEL}. Must be one of {valid_levels}.")
75
+
76
+ if self.DIVBASE_API_URL.endswith("/"):
77
+ self.DIVBASE_API_URL = self.DIVBASE_API_URL[:-1]
78
+
79
+
80
+ cli_settings = DivBaseCLISettings()
@@ -0,0 +1,209 @@
1
+ """
2
+ Custom exceptions for the divbase CLI.
3
+ """
4
+
5
+
6
+ class DivBaseCLIError(Exception):
7
+ """Base exception for all divbase CLI errors."""
8
+
9
+ pass
10
+
11
+
12
+ class AuthenticationError(DivBaseCLIError):
13
+ """Raised for user authentication errors when using CLI tool."""
14
+
15
+ def __init__(self, error_message: str = "Authentication required, make sure you're logged in."):
16
+ super().__init__(error_message)
17
+
18
+
19
+ class PersonalAccessTokenAlreadyExistsError(DivBaseCLIError):
20
+ """Raised when a user tries to store a new personal access token while one is already stored."""
21
+
22
+ def __init__(self, error_message: str = "A personal access token is already stored on this device."):
23
+ super().__init__(error_message)
24
+
25
+
26
+ class InvalidPersonalAccessTokenError(DivBaseCLIError):
27
+ """Raised when a personal access token provided by the user is invalid."""
28
+
29
+ def __init__(self, error_message: str = "The personal access token provided is invalid."):
30
+ super().__init__(error_message)
31
+
32
+
33
+ class DivBaseAPIConnectionError(DivBaseCLIError):
34
+ """Raised when CLI tool can't connect to the provided DivBase API URL."""
35
+
36
+ def __init__(
37
+ self,
38
+ error_message: str = "Unable to connect to the DivBase API. Check the API URL and your network connection. Perhaps the server is down?",
39
+ ):
40
+ super().__init__(error_message)
41
+
42
+
43
+ class DivBaseAPIError(DivBaseCLIError):
44
+ """
45
+ Used by CLI tool when making requests to DivBase API.
46
+ Raised when the DivBase API/server responds with an error status code.
47
+ Provides a helpful and easy-to-read error message for the user.
48
+ """
49
+
50
+ def __init__(
51
+ self,
52
+ error_details: str = "Not Provided",
53
+ error_type: str = "unknown",
54
+ status_code: int = 500,
55
+ http_method: str = "unknown",
56
+ url: str = "unknown",
57
+ request_id: str = "unknown",
58
+ ):
59
+ self.status_code = status_code
60
+ self.error_type = error_type
61
+ self.error_details = error_details
62
+ self.http_method = http_method
63
+ self.url = url
64
+ self.request_id = request_id
65
+ error_message = (
66
+ f"DivBase Server returned an error response:\n"
67
+ f"HTTP Status code: {status_code}\n"
68
+ f"HTTP method: {http_method}\n"
69
+ f"URL: {url}\n"
70
+ f"Request ID: {request_id}\n"
71
+ f"Error type: {error_type}\n"
72
+ f"Details: {error_details}\n"
73
+ )
74
+ self.error_message = error_message
75
+ super().__init__(error_message)
76
+
77
+
78
+ class InvalidInputError(DivBaseCLIError):
79
+ """
80
+ Raised when invalid input is provided to a CLI command.
81
+
82
+ Use this when the issue in the input is only discovered in e.g. service layer, and therefore using typer.BadParameter is not recommended.
83
+ """
84
+
85
+ def __init__(self, error_message: str):
86
+ super().__init__(error_message)
87
+
88
+
89
+ class FileDoesNotExistInSpecifiedVersionError(DivBaseCLIError):
90
+ """Raised when a file does not exist in the project at the specified project version"""
91
+
92
+ def __init__(self, project_name: str, project_version: str, missing_files: list[str]):
93
+ missing_files_str = "\n".join(f"- '{name}'" for name in missing_files)
94
+ self.project_name = project_name
95
+ self.project_version = project_version
96
+ self.missing_files = missing_files
97
+
98
+ error_message = (
99
+ f"For the project: '{project_name}'\n"
100
+ f"And project version you specified: '{project_version}':\n"
101
+ "The following file(s) could not be found:\n"
102
+ f"{missing_files_str}"
103
+ "\n Maybe they only existed in a later version of the project?"
104
+ )
105
+ super().__init__(error_message)
106
+
107
+
108
+ class FileNotFoundInProjectError(DivBaseCLIError):
109
+ """Raised when a file (or the specified version of it) does not exist in the project's store on DivBase."""
110
+
111
+ def __init__(self, project_name: str, file_name: str, version_id: str | None = None):
112
+ self.project_name = project_name
113
+ self.file_name = file_name
114
+ self.version_id = version_id
115
+
116
+ error_message = f"File '{file_name}'"
117
+ error_message += f" (version_id: '{version_id}') " if version_id else " "
118
+ error_message += f"was not found in the project '{project_name}'."
119
+ super().__init__(error_message)
120
+
121
+
122
+ class FileAlreadyUploadedError(DivBaseCLIError):
123
+ """Raised when one or more files being uploaded already exist in the project's store on DivBase."""
124
+
125
+ def __init__(self, error_message: str):
126
+ super().__init__(error_message)
127
+
128
+
129
+ class NotEmptyDirectoryError(DivBaseCLIError):
130
+ """Raised when trying to remove a directory from the project's store that still contains files."""
131
+
132
+ def __init__(self, error_message: str):
133
+ super().__init__(error_message)
134
+
135
+
136
+ class NoFilesSpecifiedError(DivBaseCLIError):
137
+ """Raised when no files were specified or resolved for a command that requires at least one."""
138
+
139
+ def __init__(self, error_message: str):
140
+ super().__init__(error_message)
141
+
142
+
143
+ class UnsupportedCharactersError(DivBaseCLIError):
144
+ """Raised when a user-provided file or directory name contains characters that DivBase does not support."""
145
+
146
+ def __init__(self, error_message: str):
147
+ super().__init__(error_message)
148
+
149
+
150
+ class ShellExpandedGlobError(DivBaseCLIError):
151
+ """Raised when --recursive is passed but the shell has already expanded the glob pattern into file paths."""
152
+
153
+ def __init__(self, error_message: str):
154
+ super().__init__(error_message)
155
+
156
+
157
+ class DuplicateFileNamesError(DivBaseCLIError):
158
+ """Raised when two or more files would resolve to the same destination name."""
159
+
160
+ def __init__(self, error_message: str):
161
+ super().__init__(error_message)
162
+
163
+
164
+ class ProjectNameNotSpecifiedError(DivBaseCLIError):
165
+ """
166
+ Raised when the project name is not specified in the command line arguments, and
167
+ no default project is set in the user config file.
168
+ """
169
+
170
+ def __init__(self):
171
+ error_message = (
172
+ "No project name provided.\n"
173
+ "Please either set a default project in your user configuration file.\n"
174
+ "or pass the flag '--project <project_name>' to this command.\n"
175
+ "To set a default project, you can run 'divbase-cli config set-default <project_name>'.\n"
176
+ )
177
+ super().__init__(error_message)
178
+
179
+
180
+ class ProjectNotInConfigError(DivBaseCLIError):
181
+ """
182
+ Raised when the project name was
183
+ 1. specified in the command line arguments OR
184
+ 2. set as the default project in the user config file.
185
+ But info about the project could not be obtained from the user config file.
186
+ """
187
+
188
+ def __init__(self, project_name: str):
189
+ self.project_name = project_name
190
+ error_message = (
191
+ f"Couldn't get information about the project named: '{project_name}' \n"
192
+ f"Use the command 'divbase-cli config add <project_name>' to add the project to your config.\n"
193
+ f"You can run 'divbase-cli config show' to view the contents of your config file.\n"
194
+ )
195
+ super().__init__(error_message)
196
+
197
+
198
+ class PolledTaskNotFinalError(DivBaseCLIError):
199
+ """Raised when a polled DivBase task is not in a final state."""
200
+
201
+ def __init__(self, error_message: str = "The polled task is still running."):
202
+ super().__init__(error_message)
203
+
204
+
205
+ class QueryTaskFailedError(DivBaseCLIError):
206
+ """Raised when a submitted query task did not complete successfully."""
207
+
208
+ def __init__(self, error_message: str = "The query task failed."):
209
+ super().__init__(error_message)