From 691b68cb4c653caa34814d77cbbe8d9e15168811 Mon Sep 17 00:00:00 2001 From: cerberus Date: Wed, 1 Oct 2025 22:20:23 +0200 Subject: [PATCH] modified .gitignore --- .gitignore | 1 + refit/README.md | 1 + refit/src/modules/librefit.py | 24 +++++---- refit/src/modules/refit_create.py | 90 +++++++++++++++---------------- refit/src/refit.py | 2 +- 5 files changed, 61 insertions(+), 57 deletions(-) diff --git a/.gitignore b/.gitignore index b5752ec..49617d2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ releases version.py +tester # ---> Python # Byte-compiled / optimized / DLL files diff --git a/refit/README.md b/refit/README.md index 476d2bd..b5396d6 100644 --- a/refit/README.md +++ b/refit/README.md @@ -18,6 +18,7 @@ - rework rf_create_decider() so it does not execute if no inputs are given -> valid input check back for no arguments passed? - check done in rf_create_decider() - get rid of input argument, default to current directory and and make it positional +- implement back in the valid input check # Changelog diff --git a/refit/src/modules/librefit.py b/refit/src/modules/librefit.py index c215c96..10e1bc5 100644 --- a/refit/src/modules/librefit.py +++ b/refit/src/modules/librefit.py @@ -104,32 +104,38 @@ def get_standard_file_name(name) -> str: return standard_file_name -def get_current_path(path: str) -> str: +def get_current_path(path) -> str: """Checks if the path argument is emty and applies the current directory as working path. - This function takes an list with strings as an input. If the input is `None` the current + This function takes an list with strings as an input. If the input is `None` the current directory is taken as the working directory. If the path is passed, a check for its existence takes place. - + Args: path (str): _The current working directory._ Returns: str: _Returns the path of the current directory after check for existence_ """ - + logger.debug(f"FUNC: get_current_path() MSG: entered function with path = '{path}'") if path is None: path = "." - logger.debug(f"FUNC: {get_current_path.__name__} MSG: Path now has the value: '{path}'") + logger.debug( + f"FUNC: {get_current_path.__name__} MSG: Path now has the value: '{path}'" + ) return path else: # Here the check for the path to exist takes place - + if os.path.exists(path) is True: - logger.debug(f"FUNC: {get_current_path.__name__} MSG: Path '{path}' exists, continue....") + logger.debug( + f"FUNC: {get_current_path.__name__} MSG: Path '{path}' exists, continue...." + ) return path else: - ERROR_MESSAGE = f"FUNC: {get_current_path.__name__} MSG: '{path}' is no valid path." - logger.error(ERROR_MESSAGE) + ERROR_MESSAGE = ( + f"FUNC: {get_current_path.__name__} MSG: '{path}' does not exist" + ) + logger.warning(ERROR_MESSAGE) print(ERROR_MESSAGE) sys.exit(1) diff --git a/refit/src/modules/refit_create.py b/refit/src/modules/refit_create.py index 6fc4ba6..732436b 100644 --- a/refit/src/modules/refit_create.py +++ b/refit/src/modules/refit_create.py @@ -1,3 +1,4 @@ +from logging import log import os from pathlib import Path import sys @@ -20,33 +21,13 @@ 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, 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 - # logger.info( - # f"FUNC: create_input_valid MSG: Usingsing current directory as input. value={self.input} " - # ) - # return self.input - # else: - # logger.debug( - # f"FUNC: create_input_valid() MSG: Exit with valid input. value= {self.input}" - # ) - # return True def create_n_folders(self, n, input, name): """Creates an set ammount of folders. Using the default directory @@ -119,39 +100,54 @@ class Refit_Create: # Counting down n for the next ieration of the while-loop n -= 1 + def input_validator(self): + logger.debug("FUNC: input_validator()") + return True + def rf_create_decider(self): """Coordination of the 'create' sub command""" logger.debug("FUNC: rf_create_decider() MSG: Entered decider function") + # !!!ToDo: implement input_validator() + if self.input_validator(): + logger.debug("yippie") + # if no input is provided, current directory is set to input + logger.debug(f"DEBUG HERE!: type of path is: {type(self.input)}") self.input = librefit.get_current_path(self.input) - print(self.input) - - # if self.input is None: - # self.input = "." - # logger.info( - # f"FUNC: rf_create_decider() MSG: Usingsing current directory as input. value={self.input} " - # ) + logger.debug( + f"FUNC: rf_create_decider() MSG: successfully retrievd input value: '{self.input}'" + ) + # Exit the program if the -n argument is not passed + if self.n is None: + logger.error( + f"FUNC rf_create_decider() MSG: the number value cannot be '{self.n}'" + ) + print("Use the '-n' flag for the create command.") + sys.exit(1) - # if self.filemode: - # logger.debug("DECISION if filemode") - # self.create_n_files(self.n, self.input, self.name) - - - # if self.recursive is False: - # logger.debug( - # f"FUNC: {self.rf_create_decider.__name__} DIR-MODE | ARGS: n={self.n} input={self.input} name={self.name}" - # ) - # if self.n is not None: self.create_n_folders(self.n, self.input, self.name) - # else: - # ERROR_MESSAGE="Please input the number on how many objects you want to create" - - # 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) + # 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: + print("help") + + if self.recursive is None: + self.create_n_folders(self.n, self.input, self.name) + else: + logger.debug( + f"FUNC: rf_create_decider(end) 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.""" diff --git a/refit/src/refit.py b/refit/src/refit.py index 9531664..127b8df 100644 --- a/refit/src/refit.py +++ b/refit/src/refit.py @@ -84,7 +84,7 @@ args = parser.parse_args() # Dispatcher -# determines what code gets addressed based of the users choosen flags. +# determines what code gets addressed based of the users chosen flags. if hasattr(args, "command_class"): logger.debug(f"In dispatcher with args: {args}") Refit_Create = args.command_class