update_projects_from_config
Script to update projects from a configuration file.
This script reads a config file containing project IDs, task template slugs, and variables, then ensures each project is updated with the correct task template version and configurable variables.
Example usage: python -m bitfount.runners.update_projects_from_config \ task_templates/project-config-production-public.yaml --username myuser \ --password mypass
Module
Functions
check_and_update_task_template
def check_and_update_task_template( project_config: ProjectConfig, username: str, jwt: JWT, hub: BitfountHub, hub_url: str,) ‑> Optional[str]:
Check if task template needs updating and update if necessary.
Arguments
project_config
: The project configuration.username
: The authenticated username.jwt
: The JWT token.hub
: The hub connection object.hub_url
: The hub URL.
Returns The task template ID to use, None if failed, or "SKIP_PROJECT" if project should be skipped.
format_template_variables
def format_template_variables(variables: dict) ‑> dict:
Format variables into the expected template variables format.
Arguments
variables
: Dictionary of variable names to values.
Returns Formatted template variables dictionary.
get_project_info
def get_project_info( project_id: str, hub: BitfountHub, hub_url: str,) ‑> Optional[dict]:
Get current project information from the hub.
Arguments
project_id
: The project ID to retrieve.hub
: The hub connection object.hub_url
: The hub URL.
Returns Project information dictionary or None if not found.
get_project_task_definitions
def get_project_task_definitions( project_id: str, hub: BitfountHub, hub_url: str,) ‑> Optional[dict]:
Get task definitions for a project from the hub.
Arguments
project_id
: The project ID.hub
: The hub connection object.hub_url
: The hub URL.
Returns Task definitions response dictionary or None if not found.
get_task_template_info
def get_task_template_info( owner_or_id: str, slug: Optional[str], hub: BitfountHub, hub_url: str,) ‑> Optional[dict]:
Get task template information from the hub by owner/slug or by ID.
Arguments
owner_or_id
: Either the task template owner (if slug provided) or template ID.slug
: The task template slug (if getting by owner/slug), None if getting by ID.hub
: The hub connection object.hub_url
: The hub URL.
Returns Task template information dictionary or None if not found.
load_config
def load_config(config_file: str) ‑> list:
Load and parse the project configuration file.
Arguments
config_file
: Path to the YAML configuration file.
Returns List of ProjectConfig objects.
main
def main(config_file: str, username: str, password: str) ‑> None:
Main function to update projects from configuration file.
Arguments
config_file
: Path to the YAML configuration file.username
: The username for authentication.password
: The password for authentication.
print_template_differences
def print_template_differences( local_template: dict, hub_template: dict, prefix: str = '',) ‑> None:
Print the differences between local and hub templates.
Arguments
local_template
: The local template dictionary.hub_template
: The hub template dictionary.prefix
: Prefix for nested keys (used in recursion).
process_project
def process_project( project_config: ProjectConfig, username: str, jwt: JWT, hub: BitfountHub, hub_url: str,) ‑> ProcessResult:
Process a single project configuration.
Arguments
project_config
: The project configuration to process.username
: The authenticated username.jwt
: The JWT token.hub
: The hub connection object.hub_url
: The hub URL.
Returns ProcessResult enum value.
sort_dict_recursively
def sort_dict_recursively(obj: Any) ‑> Any:
Recursively sort dictionaries by keys to ensure consistent ordering.
Arguments
obj
: The object to sort (can be dict, list, or any other type).
Returns The object with all nested dictionaries sorted by keys.
update_project
def update_project( project_config: ProjectConfig, template_id: str, current_project: dict, hub: BitfountHub, hub_url: str,) ‑> bool:
Update a project with new task template and variables.
Arguments
project_config
: The project configuration.template_id
: The task template ID to use.current_project
: Current project information.hub
: The hub connection object.hub_url
: The hub URL.
Returns True if update was successful, False otherwise.
Classes
ProcessResult
class ProcessResult(value, names=None, *, module=None, qualname=None, type=None, start=1):
Enum representing the result of processing a project.
ProjectConfig
class ProjectConfig(project_id: str, config_data: dict):
Class to represent a project configuration.