Reference¶
kvakk_git_tools package¶
kvakk_git_tools.ssb_gitconfig module¶
This script sets the recommended .gitconfig for the detected platform.
The recommended base git configs are stored in the public git repository https://github.com/statisticsnorway/kvakk-git-tools.git. The script clones this repo and selects the base git config based on the detected platform.
If there is an existing .gitconfig file, it is backed up, and the name and email address are extracted from it and reused.
- class Platform¶
Bases:
objectClass detecting the platform the script is running on.
- is_supported()¶
- Return type:
bool
- is_unsupported()¶
- Return type:
bool
- name()¶
- Return type:
- class PlatformName(*values)¶
Bases:
EnumEnum representing the platform names. Used in the Platform class.
- ADM_MAC = 'adm-mac'¶
- ADM_WINDOWS = 'adm-windows'¶
- DAPLA = 'dapla'¶
- DAPLA_LAB = 'dapla-lab'¶
- PROD_LINUX = 'prod-linux'¶
- PROD_WINDOWS_CITRIX = 'prod-windows-citrix'¶
- PROD_WINDOWS_VDI = 'prod-windows-vdi'¶
- UNKNOWN = 'unknown'¶
- class TempDir(temp_dir)¶
Bases:
objectContext manager class for creating and cleaning up a temporary directory.
- Parameters:
temp_dir (Path)
- backup_gitconfig(gitconfig_file)¶
- Return type:
bool- Parameters:
gitconfig_file (Path)
- check_python_version()¶
- Return type:
None
- enable_additional_package_arguments(parser, enable)¶
Enables packages specific arguments in the given ArgumentParser object.
- Parameters:
parser (
ArgumentParser) – The ArgumentParser object.enable (
bool) – Indicates whether to enable the additional arguments.
- Return type:
None
- extract_name_email()¶
- Return type:
Tuple[Optional[str],Optional[str]]
- get_gitconfig_element(element)¶
- Return type:
Optional[str]- Parameters:
element (str)
- kvakk_git_tools_package_installed()¶
Checks if the kvakk_git_tools package is installed on the system.
- Returns:
True if the package is installed, False otherwise.
- Return type:
bool
- main(test)¶
- Return type:
None- Parameters:
test (bool)
- parse_optional_validation_argument(validate)¶
Parses the optional validation argument and performs SSB Git configuration validation.
- Parameters:
validate (
bool) – Indicates whether to perform the validation.
- ping(host)¶
Returns True if host responds to a ping request.
- Return type:
bool- Parameters:
host (str)
- remove_readonly(func, path, exc_info)¶
Workaround for a bug on Windows https://github.com/python/cpython/issues/87823.
On Windows the command shutil.rmtree() fails on read-only files. This function, used by shutil.rmtree(…, onerror=remove_readonly), is the documented workaround described in the issue.
- replace_text_in_file(old_text, new_text, file)¶
- Return type:
None- Parameters:
old_text (str)
new_text (str)
file (Path)
- request_name_email()¶
- Return type:
Tuple[str,str]
- run()¶
- Return type:
None
- set_base_config(pl, test)¶
Set the base git config for the detected platform.
This function clones the repo with the recommended configs to a temporary directory, and sets the recommended base gitconfig. It also returns the recommended .gitattributes.
- Parameters:
pl (
Platform) – A Platform object with the detected platform.test (
bool) – True if testing
- Return type:
str- Returns:
The recommended .gitattributes
- set_name_email(name, email)¶
- Return type:
None- Parameters:
name (str)
email (str)
kvakk_git_tools.validate_ssb_gitconfig module¶
This module provides functions for validating SSB Git configuration.
- validate_git_config()¶
Validates the local Git configuration file against the recommended Git configuration file for the current platform.
Returns True if the two files are the same, False otherwise.
- Returns:
True if the local Git configuration file matches the recommended Git configuration file, False otherwise.
- Return type:
bool
kvakk_git_tools.validate_ssb_local_git_files module¶
This module provides functions for validating SSB Git local files.
- validate_local_git_files(cwd=PosixPath('.'))¶
Validate the local Git files.
- Parameters:
cwd (
Path) – The path to the current working directory in which to find the local git files.- Returns:
True if the local git files are valid, False otherwise. See: _validate_local_git_files
- Return type:
bool