From a0f2f83a8a143f13c462a42fb779ef827c9c468b Mon Sep 17 00:00:00 2001 From: cerberus Date: Tue, 30 Sep 2025 17:46:36 +0200 Subject: [PATCH] refactor get_standard_name_number() and added proper docstring --- refit/src/modules/librefit.py | 55 ++++++++++++++++++++++++----------- 1 file changed, 38 insertions(+), 17 deletions(-) diff --git a/refit/src/modules/librefit.py b/refit/src/modules/librefit.py index 756b54d..9a3a9fa 100644 --- a/refit/src/modules/librefit.py +++ b/refit/src/modules/librefit.py @@ -2,7 +2,22 @@ from .refit_logger import logger def get_standard_name_number(current_number, number_str_length): - """returns a number string filled to the length of the input number""" + """Returns a number string filled to the length of the input number + + This function returns the number in a standartized way as a string. + As input it takes the current number of the string to build and a + number which determines the length of the string. + + Args: + current_number (int): The current number of the item. + number_str_length (int): The length of the string which gets returned. + + Examples: + >>> get_standard_name_number(1, 2) + '01' + >>> get_standard_name_number(23, 4) + '0023' + """ # logger.debug( # f"FUNC: get_standard_name_number() index={current_number} string_length={number_str_length}" # ) @@ -16,19 +31,19 @@ def get_standard_name_number(current_number, number_str_length): def get_standard_folder_name(name) -> str: """Returnes a standard name either from a list or the default value. - + This function sanitizes the input, which gets passed as a list or None from - argparse. The function either chooses the first entry of the list, given to + argparse. The function either chooses the first entry of the list, given to the --name argument or returns the default value 'directory' - + Args: name (list[str] | None): A list of names if passed to the --name argument or None if no name is passed. - + Returns: str: The file name. Returns 'file' as default value if name argument is 'None' otherwise the first element of the list. - + Examples: >>> get_standard_file_name(None) 'file' @@ -38,29 +53,33 @@ def get_standard_folder_name(name) -> str: 'directory_name' """ - logger.debug(f"FUNC: get_standard_folder_name() MSG: entered function with value: '{name}'") + logger.debug( + f"FUNC: get_standard_folder_name() MSG: entered function with value: '{name}'" + ) standard_folder_name = name[0] if name is not None else "directory" - logger.debug(f"FUNC: get_standard_folder_name() MSG: exiting function with folder name: '{standard_folder_name}'") + logger.debug( + f"FUNC: get_standard_folder_name() MSG: exiting function with folder name: '{standard_folder_name}'" + ) return standard_folder_name def get_standard_file_name(name) -> str: """Returnes a name either from a list or the default value. - + This function sanitizes the input, which gets passed as a list or None from - argparse. The function either chooses the first entry of the list, given to + argparse. The function either chooses the first entry of the list, given to the --name argument or returns the default value 'file' - + Args: name (list[str] | None): A list of names if passed to the --name argument or None if no name is passed. - + Returns: str: The file name. Returns 'file' as default value if name argument is 'None' otherwise the first element of the list. - + Examples: >>> get_standard_file_name(None) 'file' @@ -70,11 +89,13 @@ def get_standard_file_name(name) -> str: 'file_name' """ - logger.debug(f"FUNC: get_standard_file_name() MSG: entered function with name='{name}'") + logger.debug( + f"FUNC: get_standard_file_name() MSG: entered function with name='{name}'" + ) standard_file_name = name[0] if name is not None else "file" - logger.debug(f"FUNC: get_standard_file_name MSG: Continuing with expected input: '{standard_file_name}'") + logger.debug( + f"FUNC: get_standard_file_name MSG: Continuing with expected input: '{standard_file_name}'" + ) logger.debug("FUNC get_standard_file_name() MSG: Exit") return standard_file_name - -