back to an working state

This commit is contained in:
2025-10-02 20:47:40 +02:00
parent 36333b3b99
commit fb4e8a3be6
3 changed files with 53 additions and 29 deletions

View File

@@ -84,6 +84,7 @@ class Refit_Create:
while n > 0: while n > 0:
# Get number of the file(s) to create # Get number of the file(s) to create
file_number = str(n - 1) file_number = str(n - 1)
number_string = librefit.get_standard_name_number(file_number, length_n) number_string = librefit.get_standard_name_number(file_number, length_n)
@@ -102,9 +103,6 @@ class Refit_Create:
def input_validator(self): def input_validator(self):
"""Function, which checks if the user input is valid""" """Function, which checks if the user input is valid"""
# NOTE: find a way on how to return 'True' when the user input
# is valid
# Check working directory # Check working directory
if self.input is None: if self.input is None:
self.input = librefit.get_current_path(self.input) self.input = librefit.get_current_path(self.input)
@@ -112,42 +110,68 @@ class Refit_Create:
"FUNC: input_validator() MSG: No directory passed to the command, continue with current directory" "FUNC: input_validator() MSG: No directory passed to the command, continue with current directory"
) )
# Check if recursive input is an empty list
if self.recursive is not None:
if len(self.recursive) < 3:
logger.error("Recursive flag cannot be set without values.")
sys.exit(1)
# Exit the program if the -n argument is not passed # Exit the program if the -n argument is not passed
if self.n is None: if self.n is None:
logger.error( logger.error(
f"FUNC rf_create_decider() MSG: the number value cannot be '{self.n}'" f"FUNC rf_create_decider(n=None ?) MSG: the number value cannot be '{self.n}'"
) )
print("Use the '-n' flag for the create command.") print("Use the '-n' flag for the create command.")
sys.exit(1) sys.exit(1)
else:
logger.debug(
f"FUNC: input_validator() MSG: valid number entered n={self.n}"
)
return True
def rf_create_decider(self): def rf_create_decider(self):
"""Coordination of the 'create' sub command""" """Coordination of the 'create' sub command"""
logger.debug("FUNC: rf_create_decider() MSG: Entered decider function") logger.debug("FUNC: rf_create_decider() MSG: Entered decider function")
# WARNING: implement the input validator and only continue with
# the decider if the validator returns true
if self.input_validator(): if self.input_validator():
logger.debug("yippie")
# Exits the program if recursive and filemode flags are set at the same time
if self.filemode:
logger.debug("DECISION filemode set, creating files instead of folders")
if self.recursive is None:
self.create_n_files(self.n, self.input, self.name)
else:
logger.error("Recursive and filemode don´t work together.")
print("Recursive and filemode don´t work together.")
if self.recursive is None:
self.create_n_folders(self.n, self.input, self.name)
else:
logger.debug( logger.debug(
f"FUNC: rf_create_decider(end) MSG: given arguments: {self.args}" f"FUNC: rf_create_decider() MSG: n={self.n} after input validating"
) )
print(
"Use '-n' argument to create directories.\nPlease use 'refit create -h' for help" # Exits the program if recursive and filemode flags are set at the same time
) if self.filemode:
sys.exit(1) logger.debug(
f"FUNC: rf_create_decider(filemode) MSG: given arguments: {self.n} {self.input} {self.name}"
)
if self.recursive is None:
self.create_n_files(self.n, self.input, self.name)
else:
logger.error("Recursive and filemode don´t work together.")
print("Recursive and filemode don´t work together.")
if self.recursive is not None:
logger.debug(
f"FUNC: rf_create_decider(recursive) MSG: given arguments: n={self.n} input={self.input} name={self.name} recursive={self.recursive}"
)
# OPTIMIZE:Enters the standard creation mode and crerates directories.
if self.recursive is None:
if not self.filemode:
logger.debug(
f"FUNC: rf_create_decider(n_folder) MSG: given arguments: n={self.n} input={self.input} name={self.name}"
)
self.create_n_folders(self.n, self.input, self.name)
else:
print("How did we end up here?????")
else:
logger.debug(
f"FUNC: rf_create_decider(exit no input) MSG: given arguments: n={self.n} input={self.input} name={self.name} recursive={self.recursive}"
)
print(
"Use '-n' argument to create directories.\nPlease use 'refit create -h' for help"
)
sys.exit(1)
def __call__(self): def __call__(self):
"""Gets called when the 'create' subcommand is used.""" """Gets called when the 'create' subcommand is used."""

View File

@@ -22,7 +22,7 @@ def read_version_config():
if not os.path.exists(CONFIG_FILE): if not os.path.exists(CONFIG_FILE):
logger.error( logger.error(
f"Func: read_version_config() MSG: Could not find config file '{CONFIG_FILE}'" f"FUNC: read_version_config() MSG: Could not find config file '{CONFIG_FILE}'"
) )
return "x.x.x" return "x.x.x"
@@ -82,8 +82,8 @@ create_parser.add_argument(
create_parser.add_argument( create_parser.add_argument(
"-r", "-r",
"--recursive", "--recursive",
action="store_true", # action="store_true",
# nargs="*", nargs="*",
help="Sets the recursive mode for folders to true. First argumet\n is for the depth and the second for the width.", help="Sets the recursive mode for folders to true. First argumet\n is for the depth and the second for the width.",
) )
create_parser.set_defaults(command_class=Refit_Create) create_parser.set_defaults(command_class=Refit_Create)