From b0e3594b4967da39e6344af43ee37f8218a37e65 Mon Sep 17 00:00:00 2001 From: cerberus Date: Tue, 30 Sep 2025 09:35:25 +0200 Subject: [PATCH] added proper docstring and refactored get_standard_file_name() --- refit/src/modules/librefit.py | 65 ++++++++++++++++++------------- refit/src/modules/refit_create.py | 1 + 2 files changed, 39 insertions(+), 27 deletions(-) diff --git a/refit/src/modules/librefit.py b/refit/src/modules/librefit.py index 8aa825c..aad45e3 100644 --- a/refit/src/modules/librefit.py +++ b/refit/src/modules/librefit.py @@ -14,9 +14,18 @@ def get_standard_name_number(current_number, number_str_length): return standard_name_number -def get_standard_folder_name(name): - """returns the default name if name=None else, it returns the first - given name to the argument --name as astring""" +def get_standard_folder_name(name) -> str: + """Takes the --name argument as input and returns an default value if no name is provided + or takes the first element of the list, passed to the argument. + + + Example: + None -> . + ["directory"] -> dirctory + ["folder", "directory"] -> folder + + Returns str + """ logger.debug("get_standard_folder_name() call") if name is None: standard_folder_name = "directory" @@ -46,31 +55,33 @@ def get_standard_folder_name(name): return standard_folder_name -def get_standard_file_name(name): - """Returns the default file name if none is provided.""" +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 + 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' + >>> get_standard_file_name(["example"]) + 'example' + >>> get_standard_file_name(["file_name", "example"]) + 'file_name' + """ - logger.debug( - f"FUNC: get_standard_file_name() MSG: entered function with name='{name}'" - ) - - if name is None: - standard_file_name = "file" - logger.info( - f"No file name assigned, continue with default value '{standard_file_name}'" - ) - else: - if len(name) > 1: - _NAMES_WARNING = f"{len(name)} names given, only one required.\nContinuing with '{name[0]}' as name." - logger.warning(_NAMES_WARNING) - print(_NAMES_WARNING) - standard_file_name = name[0] - - logger.debug(f"{standard_file_name}, Type: {type(standard_file_name)}") - else: - standard_file_name = name[0] - 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: 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("FUNC get_standard_file_name() MSG: Exit") return standard_file_name diff --git a/refit/src/modules/refit_create.py b/refit/src/modules/refit_create.py index a1e37d1..4780511 100644 --- a/refit/src/modules/refit_create.py +++ b/refit/src/modules/refit_create.py @@ -111,6 +111,7 @@ class Refit_Create: file_path = Path(os.path.join(input, temp_name)) # Build file path file_path.touch(exist_ok=True) # creating file + logger.debug( f"FUNC: create_n_files MSG: created file at {os.path.join(input, temp_name)}" )