refactor get_standard_name_number() and added proper docstring

This commit is contained in:
2025-09-30 17:46:36 +02:00
parent af80345ff6
commit a0f2f83a8a

View File

@@ -2,7 +2,22 @@ from .refit_logger import logger
def get_standard_name_number(current_number, number_str_length): 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( # logger.debug(
# f"FUNC: get_standard_name_number() index={current_number} string_length={number_str_length}" # 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: def get_standard_folder_name(name) -> str:
"""Returnes a standard name either from a list or the default value. """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 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' the --name argument or returns the default value 'directory'
Args: Args:
name (list[str] | None): A list of names if passed to the --name argument name (list[str] | None): A list of names if passed to the --name argument
or None if no name is passed. or None if no name is passed.
Returns: Returns:
str: The file name. Returns 'file' as default value if name argument is 'None' str: The file name. Returns 'file' as default value if name argument is 'None'
otherwise the first element of the list. otherwise the first element of the list.
Examples: Examples:
>>> get_standard_file_name(None) >>> get_standard_file_name(None)
'file' 'file'
@@ -38,29 +53,33 @@ def get_standard_folder_name(name) -> str:
'directory_name' '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" 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 return standard_folder_name
def get_standard_file_name(name) -> str: def get_standard_file_name(name) -> str:
"""Returnes a name either from a list or the default value. """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 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' the --name argument or returns the default value 'file'
Args: Args:
name (list[str] | None): A list of names if passed to the --name argument name (list[str] | None): A list of names if passed to the --name argument
or None if no name is passed. or None if no name is passed.
Returns: Returns:
str: The file name. Returns 'file' as default value if name argument is 'None' str: The file name. Returns 'file' as default value if name argument is 'None'
otherwise the first element of the list. otherwise the first element of the list.
Examples: Examples:
>>> get_standard_file_name(None) >>> get_standard_file_name(None)
'file' 'file'
@@ -70,11 +89,13 @@ def get_standard_file_name(name) -> str:
'file_name' '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" 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") logger.debug("FUNC get_standard_file_name() MSG: Exit")
return standard_file_name return standard_file_name