cloudos_cli.utils.array_job

Functions

classify_pattern(s)

Classifies a given string pattern into one of three categories: "regex", "glob", or "exact".

extract_project(path)

Extracts the project name and the remaining path from a given file path.

generate_datasets_for_project(cloudos_url, ...)

Generate datasets for a specified project in a CloudOS workspace.

get_file_or_folder_id(cloudos_url, apikey, ...)

Retrieve the ID of a specific file or folder within a CloudOS workspace.

is_glob_pattern(s)

Check if a given string contains glob pattern characters.

is_probably_regex(s)

Determines if a given string is likely a regular expression.

is_valid_regex(s)

Validates whether the given string is a valid regular expression.

cloudos_cli.utils.array_job.classify_pattern(s)[source]

Classifies a given string pattern into one of three categories: “regex”, “glob”, or “exact”.

Parameters:

s (str) – The string pattern to classify.

Returns:

str

  • “regex” if the pattern is likely a regular expression.

  • ”glob” if the pattern matches glob-style syntax.

  • ”exact” if the pattern does not match regex or glob syntax.

Return type:

A string indicating the type of pattern:

cloudos_cli.utils.array_job.extract_project(path)[source]

Extracts the project name and the remaining path from a given file path.

The function assumes that a “project” exists if the path contains at least three parts when split by slashes. If the path has fewer than three parts, the project name is considered empty, and the entire path is returned as the remaining path.

Parameters:

path (str) – The file path to process.

Returns:

tuple

  • str: The project name (empty string if no project exists).

  • str: The remaining path after the project name.

Return type:

A tuple containing:

cloudos_cli.utils.array_job.generate_datasets_for_project(cloudos_url, apikey, workspace_id, project_name, verify_ssl)[source]

Generate datasets for a specified project in a CloudOS workspace.

This function initializes a Datasets object for the given project and handles potential errors such as missing project elements or unauthorized API calls.

Parameters:
  • cloudos_url (str) – The URL of the CloudOS instance.

  • apikey (str) – The API key for authentication.

  • workspace_id (str) – The ID of the workspace where the project resides.

  • project_name (str) – The name of the project for which datasets are generated.

  • verify_ssl (bool) – Whether to verify SSL certificates during API calls.

Returns:

An instance of the Datasets class initialized for the specified project.

Return type:

Datasets

Raises:
  • ValueError – If the specified project is not found in the workspace.

  • BadRequestException – If the API call is unauthorized or encounters other issues.

cloudos_cli.utils.array_job.get_file_or_folder_id(cloudos_url, apikey, workspace_id, project_name, verify_ssl, command_dir, command_name, is_file=True)[source]

Retrieve the ID of a specific file or folder within a CloudOS workspace.

Parameters:
  • cloudos_url (str) – The base URL of the CloudOS API.

  • apikey (str) – The API key for authenticating requests to the CloudOS API.

  • workspace_id (str) – The ID of the workspace containing the project.

  • project_name (str) – The name of the project within the workspace.

  • verify_ssl (bool) – Whether to verify SSL certificates for the API requests.

  • name (str) – The name of the file or folder whose ID is to be retrieved.

  • is_file (bool, optional) – Whether to retrieve a file ID (True) or folder ID (False). Default is True.

Returns:

str

Return type:

The ID of the specified file or folder.

Raises:
  • ValueError – If the specified file or folder is not found.

  • Exception – If there is an error during the API interaction or data retrieval.

Notes

  • This function uses the generate_datasets_for_project function to create a Datasets object for the specified project.

  • The list_folder_content method is used for files, and list_project_content is used for folders.

  • The function assumes that the IDs are stored in the “_id” field of the metadata.

cloudos_cli.utils.array_job.is_glob_pattern(s)[source]

Check if a given string contains glob pattern characters.

Glob patterns are commonly used for filename matching and include special characters such as ‘*’, ‘?’, and ‘[‘.

Parameters:

s (str) – The string to check for glob pattern characters.

Returns:

True if the string contains any glob pattern characters, otherwise False.

Return type:

bool

cloudos_cli.utils.array_job.is_probably_regex(s)[source]

Determines if a given string is likely a regular expression.

This function checks whether the input string matches common patterns that are indicative of regular expressions. It first validates the string using is_valid_regex(s) and then searches for specific regex indicators such as quantifiers, character classes, anchors, and alternation.

Parameters:

s (str) – The string to evaluate.

Returns:

True if the string is likely a regular expression, False otherwise.

Return type:

bool

Notes

The function assumes the existence of is_valid_regex(s) which

validates whether the input string is a valid regex.

cloudos_cli.utils.array_job.is_valid_regex(s)[source]

Validates whether the given string is a valid regular expression.

Parameters:

s (str) – The string to be checked as a regular expression.

Returns:

True if the string is a valid regular expression, False otherwise.

Return type:

bool