cleanup
This commit is contained in:
@@ -153,11 +153,11 @@ def get_current_path(path) -> str:
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
# TODO: - add dynamic name input
|
|
||||||
# - add docstring
|
|
||||||
def create_linear_directories(input_path, target_depth, current_depth):
|
def create_linear_directories(input_path, target_depth, current_depth):
|
||||||
"""Creates the linear directories for the x*y pattern"""
|
"""Creates the linear directories for the x*y pattern"""
|
||||||
|
|
||||||
|
# TODO: - add dynamic name input
|
||||||
|
# - add docstring
|
||||||
logger.debug(
|
logger.debug(
|
||||||
f"FUNC: create_linear_directories(entered) VALUES: path='{input_path}', target_depth='{target_depth}', current_depth='{current_depth}'"
|
f"FUNC: create_linear_directories(entered) VALUES: path='{input_path}', target_depth='{target_depth}', current_depth='{current_depth}'"
|
||||||
)
|
)
|
||||||
@@ -173,24 +173,29 @@ def create_linear_directories(input_path, target_depth, current_depth):
|
|||||||
|
|
||||||
os.mkdir(path)
|
os.mkdir(path)
|
||||||
|
|
||||||
create_linear_directories(path, target_depth, current_depth + 1)
|
create_linear_directories(
|
||||||
|
path,
|
||||||
|
target_depth,
|
||||||
|
current_depth + 1,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
# TODO: - add dynamic name input
|
|
||||||
# - add docstring
|
|
||||||
def create_parallel_directories(input_path, target_depth, width):
|
def create_parallel_directories(input_path, target_depth, width):
|
||||||
"""Creates directories after the pattern x*y"""
|
"""Creates directories after the pattern x*y"""
|
||||||
|
|
||||||
|
# TODO: - add dynamic name input
|
||||||
|
# - add docstring
|
||||||
logger.debug(
|
logger.debug(
|
||||||
f"FUNC: create_parallel_directories(entered) VALUES: path='{input_path}', target_depth='{target_depth}', width='{width}'"
|
f"FUNC: create_parallel_directories(entered) VALUES: path='{input_path}', target_depth='{target_depth}', width='{width}'"
|
||||||
)
|
)
|
||||||
|
|
||||||
# # Getting the lenth of the number string which gets addedto the dir name.
|
|
||||||
# length_width = get_int_length(width)
|
|
||||||
|
|
||||||
for i in range(width):
|
for i in range(width):
|
||||||
directory_name = "branch_" + get_standard_name_number(i, get_int_length(width))
|
directory_name = "branch_" + get_standard_name_number(i, get_int_length(width))
|
||||||
path = os.path.join(input_path, directory_name)
|
path = os.path.join(input_path, directory_name)
|
||||||
os.mkdir(path)
|
os.mkdir(path)
|
||||||
|
|
||||||
create_linear_directories(path, target_depth, current_depth=0)
|
create_linear_directories(
|
||||||
|
path,
|
||||||
|
target_depth,
|
||||||
|
current_depth=0,
|
||||||
|
)
|
||||||
|
|||||||
@@ -35,21 +35,11 @@ class Refit_Create:
|
|||||||
logger.debug(f"FUNC: create_n_folders() ARGS: n={n} input={input} name={name}")
|
logger.debug(f"FUNC: create_n_folders() ARGS: n={n} input={input} name={name}")
|
||||||
|
|
||||||
# Creating the length of the suffix number_string.
|
# Creating the length of the suffix number_string.
|
||||||
length_n = len(str(n))
|
length_n = librefit.get_int_length(n)
|
||||||
logger.debug(
|
|
||||||
f"FUNC: create_n_folders() MSG: Length of numbering string added to the name:{length_n}"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Get either the default folder name or the input name as string.
|
# Get either the default folder name or the input name as string.
|
||||||
logger.debug(
|
|
||||||
f"FUNC: create_n_folders() MSG: Type of name value: {type(name)} name={name}"
|
|
||||||
)
|
|
||||||
folder_name = librefit.get_standard_folder_name(name)
|
folder_name = librefit.get_standard_folder_name(name)
|
||||||
|
|
||||||
logger.debug(
|
|
||||||
f"FUNC: create_n_folders() MSG: Folder name: {folder_name} post get_standard_folder_name() call"
|
|
||||||
)
|
|
||||||
|
|
||||||
while n > 0:
|
while n > 0:
|
||||||
# iterating down for the files number.
|
# iterating down for the files number.
|
||||||
folder_number = n - 1
|
folder_number = n - 1
|
||||||
@@ -76,17 +66,13 @@ class Refit_Create:
|
|||||||
# Get the name from the input argument.
|
# Get the name from the input argument.
|
||||||
file_name = librefit.get_standard_file_name(name)
|
file_name = librefit.get_standard_file_name(name)
|
||||||
|
|
||||||
# Get the length of the entered number to fill it with 0
|
|
||||||
length_n = len(str(n))
|
|
||||||
logger.debug(
|
|
||||||
f"FUNC: create_n_files() MSG: file name='{file_name}' length_n={length_n}"
|
|
||||||
)
|
|
||||||
|
|
||||||
while n > 0:
|
while n > 0:
|
||||||
# Get number of the file(s) to create
|
# Get number of the file(s) to create
|
||||||
|
|
||||||
file_number = n - 1
|
file_number = n - 1
|
||||||
number_string = librefit.get_standard_name_number(file_number, length_n)
|
number_string = librefit.get_standard_name_number(
|
||||||
|
file_number, librefit.get_int_length(n)
|
||||||
|
)
|
||||||
|
|
||||||
# Get the name of the file, either applying default or using first list item.
|
# Get the name of the file, either applying default or using first list item.
|
||||||
temp_name = f"{file_name}_{number_string}"
|
temp_name = f"{file_name}_{number_string}"
|
||||||
@@ -94,26 +80,18 @@ class Refit_Create:
|
|||||||
file_path = Path(os.path.join(input, temp_name)) # Build file path
|
file_path = Path(os.path.join(input, temp_name)) # Build file path
|
||||||
file_path.touch(exist_ok=True) # creating file
|
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)}"
|
|
||||||
)
|
|
||||||
# Counting down n for the next ieration of the while-loop
|
# Counting down n for the next ieration of the while-loop
|
||||||
n -= 1
|
n -= 1
|
||||||
|
|
||||||
def create_recursive(self, recursive, name, input, n):
|
def create_recursive(self, recursive, name, input):
|
||||||
"""Creating directories recursively"""
|
"""Creating directories recursively"""
|
||||||
logger.debug(
|
logger.debug(
|
||||||
f"FUNC: create_recursive(beginning) MSG: entered function with following arguments: recursive='{recursive}' name='{name}' input='{input}' n='{n}'"
|
f"FUNC: create_recursive(beginning) MSG: entered function with following arguments: recursive='{recursive}' name='{name}' input='{input}'"
|
||||||
)
|
)
|
||||||
# librefit.create_recursive_folders(
|
|
||||||
# input_path=input,
|
|
||||||
# target_depth=recursive[0],
|
|
||||||
# current_depth=0,
|
|
||||||
# width=recursive[1],
|
|
||||||
# )
|
|
||||||
|
|
||||||
librefit.create_parallel_directories(
|
librefit.create_parallel_directories(
|
||||||
input_path=input, target_depth=recursive[0], width=recursive[1]
|
input_path=input,
|
||||||
|
target_depth=recursive[0],
|
||||||
|
width=recursive[1],
|
||||||
)
|
)
|
||||||
|
|
||||||
def input_validator(self):
|
def input_validator(self):
|
||||||
@@ -125,19 +103,22 @@ class Refit_Create:
|
|||||||
# 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)
|
||||||
logger.info(
|
logger.info(f"FUNC: input_validator(input check) VALUE: input={self.input}")
|
||||||
"FUNC: input_validator() MSG: No directory passed to the command, continue with current directory"
|
|
||||||
)
|
|
||||||
|
|
||||||
# Check for conflicting flags
|
# Check for conflicting flags
|
||||||
if self.recursive is not None and self.filemode:
|
if self.recursive is not None and self.filemode:
|
||||||
logger.error("Filemode and recursive do not work together.")
|
logger.error(
|
||||||
|
f"FUNC: input_validator(recursive&filemode?) VALUES: recursive='{self.recursive}', filemode={self.filemode}"
|
||||||
|
)
|
||||||
print("Filemode and recursive do not work together.")
|
print("Filemode and recursive do not work together.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Check if recursive input is an empty list
|
# Check if recursive input is an empty list
|
||||||
if self.recursive is not None:
|
if self.recursive is not None:
|
||||||
if len(self.recursive) < 2:
|
if len(self.recursive) < 2:
|
||||||
logger.error("Recursive flag cannot be set without values.")
|
logger.error(
|
||||||
|
"FUNC:input_validator(recursive) MSG: Invalid input, enter 2 numbers!"
|
||||||
|
)
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
# Exit the program if the -n argument is not passed
|
# Exit the program if the -n argument is not passed
|
||||||
@@ -158,10 +139,6 @@ class Refit_Create:
|
|||||||
logger.debug("FUNC: create_dispatcher() MSG: Entered decider function")
|
logger.debug("FUNC: create_dispatcher() MSG: Entered decider function")
|
||||||
|
|
||||||
if self.input_validator():
|
if self.input_validator():
|
||||||
logger.debug(
|
|
||||||
f"FUNC: create_dispatcher() MSG: n={self.n} after input validating"
|
|
||||||
)
|
|
||||||
|
|
||||||
if self.filemode:
|
if self.filemode:
|
||||||
logger.debug(
|
logger.debug(
|
||||||
f"FUNC: create_dispatcher(filemode) MSG: given arguments: n={self.n} input={self.input} name={self.name}"
|
f"FUNC: create_dispatcher(filemode) MSG: given arguments: n={self.n} input={self.input} name={self.name}"
|
||||||
@@ -172,7 +149,7 @@ class Refit_Create:
|
|||||||
logger.debug(
|
logger.debug(
|
||||||
f"FUNC: create_dispatcher(recursive) MSG: given arguments: n={self.n} input={self.input} name={self.name} recursive={self.recursive}"
|
f"FUNC: create_dispatcher(recursive) MSG: given arguments: n={self.n} input={self.input} name={self.name} recursive={self.recursive}"
|
||||||
)
|
)
|
||||||
self.create_recursive(self.recursive, self.name, self.input, self.n)
|
self.create_recursive(self.recursive, self.name, self.input)
|
||||||
|
|
||||||
elif not self.recursive and not self.filemode:
|
elif not self.recursive and not self.filemode:
|
||||||
logger.debug(
|
logger.debug(
|
||||||
|
|||||||
@@ -16,18 +16,18 @@ CONFIG_FILE = "version.cfg"
|
|||||||
# TODO: see the TODO in librefit: move the config file section into the
|
# TODO: see the TODO in librefit: move the config file section into the
|
||||||
# libary
|
# libary
|
||||||
def read_version_config():
|
def read_version_config():
|
||||||
logger.debug(f"Start read_version_config() with config file: {CONFIG_FILE}")
|
# logger.debug(f"Start read_version_config() with config file: {CONFIG_FILE}")
|
||||||
config = configparser.ConfigParser()
|
config = configparser.ConfigParser()
|
||||||
config.read(CONFIG_FILE)
|
config.read(CONFIG_FILE)
|
||||||
|
|
||||||
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"
|
||||||
|
|
||||||
if "VERSION" not in config:
|
if "VERSION" not in config:
|
||||||
logger.error(f"Could not find VERSION-variable in config file '{CONFIG_FILE}'")
|
# logger.error(f"Could not find VERSION-variable in config file '{CONFIG_FILE}'")
|
||||||
return "x.x.x"
|
return "x.x.x"
|
||||||
|
|
||||||
try:
|
try:
|
||||||
@@ -35,10 +35,10 @@ def read_version_config():
|
|||||||
major = v.get("major", "0")
|
major = v.get("major", "0")
|
||||||
minor = v.get("minor", "0")
|
minor = v.get("minor", "0")
|
||||||
patch = v.get("patch", "0")
|
patch = v.get("patch", "0")
|
||||||
logger.debug(f"Config file read successfully. Version: {major}.{minor}.{patch}")
|
# logger.debug(f"Config file read successfully. Version: {major}.{minor}.{patch}")
|
||||||
return f"{major}.{minor}.{patch}"
|
return f"{major}.{minor}.{patch}"
|
||||||
except Exception:
|
except Exception:
|
||||||
logger.warning("Couldn not read version from config file")
|
# logger.warning("Couldn not read version from config file")
|
||||||
return "x.x.x"
|
return "x.x.x"
|
||||||
|
|
||||||
|
|
||||||
@@ -95,7 +95,7 @@ args = parser.parse_args()
|
|||||||
# Dispatcher
|
# Dispatcher
|
||||||
# determines what code gets addressed based of the users chosen flags.
|
# determines what code gets addressed based of the users chosen flags.
|
||||||
if hasattr(args, "command_class"):
|
if hasattr(args, "command_class"):
|
||||||
logger.debug(f"In dispatcher with args: {args}")
|
# logger.debug(f"In dispatcher with args: {args}")
|
||||||
Refit_Create = args.command_class
|
Refit_Create = args.command_class
|
||||||
create_command_instance = Refit_Create(args)
|
create_command_instance = Refit_Create(args)
|
||||||
create_command_instance()
|
create_command_instance()
|
||||||
|
|||||||
Reference in New Issue
Block a user