qgis_deployment_toolbelt.profiles.profiles_handler_base module¶
Handle remote git repository.
Author: Julien Moura (https://github.com/guts).
Inspired from: QGIS Resource Sharing
- class qgis_deployment_toolbelt.profiles.profiles_handler_base.RemoteProfilesHandlerBase(source_repository_type: Literal['git_local', 'git_remote', 'http', 'local', 'remote'], branch_to_use: str | None = None)¶
Bases:
object
Common git repository handler using dulwich.
It’s designed to handle thoses cases:
the distant repository (source) is on a local network or drive
the distant repository (source) is on Internet (github.com, gitlab.com, gitlab.company.org…)
the local repository (destination) is on a local network or drive
- SOURCE_REPOSITORY_TYPE: Literal['git_local', 'git_remote', 'http', 'local', 'remote'] | None = None¶
- __init__(source_repository_type: Literal['git_local', 'git_remote', 'http', 'local', 'remote'], branch_to_use: str | None = None) None ¶
Object instanciation.
- Parameters:
source_repository_type (Literal["git_local", "git_remote", "local", "remote"]) – type of source repository
branch_to_use (str | None, optional) – branch to clone or checkout. If None, the source active branch will be used. Defaults to None.
- clone_or_pull(to_local_destination_path: Path, attempt: int = 1) Repo ¶
Clone or fetch/pull remote repository to local path. If this one doesn’t exist, it’s created. If fetch or pull action fail, it removes the existing folder and clone the remote again.
- Parameters:
to_local_destination_path (Path) – path to the folder where to clone (or pull)
attempt (int) – attempt count. If attempts < 2 and it fails, the destination path is completely removed before cloning again. Defaults to 1.
- Raises:
err – if something fails during clone or pull operations
- Returns:
the local repository object
- Return type:
Repo
- download(**kwargs)¶
Decorator wrapper to define environment variable for proxy use.
If a proxy settings is available for https or http we: - backup current environment value - define environment value with proxy settings - run function - restore environment value if available
- Returns:
function result
- Return type:
_type_
- get_active_branch_from_local_repository(**kwargs)¶
Decorator wrapper to define environment variable for proxy use.
If a proxy settings is available for https or http we: - backup current environment value - define environment value with proxy settings - run function - restore environment value if available
- Returns:
function result
- Return type:
_type_
- is_branch_existing_in_repository(branch_name: str | bytes, repository_path_or_url: Path | str | None = None) bool ¶
Determine if the given branch name is part of the given repository.
- Parameters:
- Raises:
NotGitRepository – if the path is not a valid Git Repository
- Returns:
True is the rbanch is part of given repository existing branches
- Return type:
- is_valid_git_repository(source_repository_path_or_url: Path | str | None = None, force_type: Literal['git_local', 'git_remote', 'local', 'remote'] | None = None, raise_error: bool = True) bool ¶
Determine if the given path or URL is a valid repository or not.
- Parameters:
source_repository_path_or_url (Path | str | None, optional) – _description_. Defaults to None.
force_type (Literal["git_local","local", "remote"], optional) – force git repository type to check. If None, it uses the SOURCE_REPOSITORY_TYPE attribute. Defaults None.
raise_error (bool, optional) – if True, it raises an exception. Defaults to True.
- Raises:
NotGitRepository – if given path or URL is not a valid Git repository
- Returns:
True if the given path or URL is a valid Git repository
- Return type:
- list_remote_branches(**kwargs)¶
Decorator wrapper to define environment variable for proxy use.
If a proxy settings is available for https or http we: - backup current environment value - define environment value with proxy settings - run function - restore environment value if available
- Returns:
function result
- Return type:
_type_