refactor librefit and added docstrings

This commit is contained in:
2025-09-30 20:56:27 +02:00
parent a0f2f83a8a
commit efcec653cb
5 changed files with 46 additions and 24 deletions

View File

@@ -1,6 +1,6 @@
import argparse
import os
from pathlib import Path
import sys
from .refit_logger import logger
from . import librefit
@@ -20,19 +20,21 @@ class Refit_Create:
def __init__(self, args):
"""Initiating variables for creation"""
self.args = args
self.name = args.name
self.input = args.input
self.n = args.n
self.filemode = args.filemode
self.recursive = args.recursive
self.args = args
def create_input_valid(self):
def create_input_valid(self, args):
"""Checks if the input is argument for its existence. If no input
argument with a value is passed, the current directory is used and
passed to the input"""
logger.debug(f"Start create_input_valid() value= {self.input}")
logger.debug(f"FUNC: create_input_valid() MSG: arguments: {args}")
if self.input is None:
input = "."
self.input = input
@@ -101,17 +103,16 @@ class Refit_Create:
)
while n > 0:
# Get number of the file(s) to create
file_number = str(n - 1)
number_string = librefit.get_standard_name_number(file_number, length_n)
# Get the name of the file, either applying default or using first list item.
temp_name = f"{file_name}_{number_string}"
file_path = Path(os.path.join(input, temp_name)) # Build file path
file_path.touch(exist_ok=True) # creating file
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)}"
)
@@ -121,17 +122,29 @@ class Refit_Create:
def rf_create_decider(self):
"""Coordination of the 'create' sub command"""
logger.debug("FUNC: rf_create_decider() MSG: Entered decider function")
if self.create_input_valid():
logger.debug(f"Valid input. value={self.input}")
if self.filemode:
logger.debug("DECISION if filemode")
self.create_n_files(self.n, self.input, self.name)
else:
logger.debug(
f"DIR-MODE | ARGS: n={self.n} input={self.input} name={self.name}"
)
self.create_n_folders(self.n, self.input, self.name)
if self.input is None:
self.input = "."
logger.info(
f"FUNC: rf_create_decider() MSG: Usingsing current directory as input. value={self.input} "
)
logger.critical(self.input)
if self.filemode:
logger.debug("DECISION if filemode")
self.create_n_files(self.n, self.input, self.name)
elif self.n is not None:
logger.debug(
f"DIR-MODE | ARGS: n={self.n} input={self.input} name={self.name}"
)
self.create_n_folders(self.n, self.input, self.name)
else:
logger.debug(f"FUNC: rf_create_decider() MSG: given arguments: {self.args}")
print(
"Use '-n' argument to create directories.\nPlease use 'refit create -h' for help"
)
sys.exit(1)
def __call__(self):
"""Gets called when the 'create' subcommand is used."""