added proper docstring and refactored get_standard_file_name()

This commit is contained in:
2025-09-30 09:35:25 +02:00
parent cf828c7f97
commit b0e3594b49
2 changed files with 39 additions and 27 deletions

View File

@@ -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

View File

@@ -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)}"
)