Compare commits
3 Commits
fb4e8a3be6
...
acd3f5fe39
| Author | SHA1 | Date | |
|---|---|---|---|
| acd3f5fe39 | |||
| 0e84c959ce | |||
| aa5041a46c |
@@ -13,19 +13,27 @@
|
||||
3. file removal
|
||||
3.1 remove all files like '*.tar'
|
||||
|
||||
- ~~make input default the current directory and the second argument after `refit create`~~
|
||||
- ~~make input default the current directory and the
|
||||
second argument after `refit create`~~
|
||||
- ~~maybe get rid of valid input ??~~
|
||||
- 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
|
||||
- rework rf_create_decider() so it does not execute if no inputs are give
|
||||
n -> valid input check back for no arguments passed?
|
||||
- check done in rf_create_decider()
|
||||
- get rid of input argument, default to current directory and make it
|
||||
positional
|
||||
- implement back in the valid input check
|
||||
|
||||
# Changelog
|
||||
## Changelog
|
||||
|
||||
<2025-09-30> V0.3.2 - Refactoring librefit and added proper docstrings; begun to remove the check for the valid input and put it in the decider
|
||||
<2025-10-03> V0.3.3 - Added the beginning of recursive mode
|
||||
<2025-09-30> V0.3.2 - Refactoring librefit and added proper docstrings;
|
||||
begun to remove the check for the valid input and put it in the decider
|
||||
<2025-09-29> V0.3.1 - Removed the requirement for an input
|
||||
<2025-09-29> V0.3.0 - Added file creation in the pattern like directories
|
||||
<2025-09-29> V0.3.0 - Added file creation in the pattern like
|
||||
directories
|
||||
<2025-09-29> V0.2.4 - Improved logging and log readability
|
||||
<2025-09-28> V0.2.3 - Added logging for version file and --filemode path to the decider
|
||||
<2025-09-28> V0.2.3 - Added logging for version file and --filemode
|
||||
path to the decider
|
||||
<2025-09-28> V0.2.0 - Added librefit for standard functions
|
||||
<2025-09-28> V0.1.0 - Added the creation of multiple numbered directories in a given directory with the pattern default directory_n
|
||||
<2025-09-28> V0.1.0 - Added the creation of multiple numbered
|
||||
directories in a given directory with the pattern default directory_n
|
||||
|
||||
@@ -7,7 +7,7 @@ from .refit_logger import logger
|
||||
# reusable
|
||||
|
||||
|
||||
def get_standard_name_number(current_number: str, number_str_length: int) -> str:
|
||||
def get_standard_name_number(current_number: int, number_str_length: int) -> str:
|
||||
"""Returns a number string filled to the length of the input number
|
||||
|
||||
This function returns the number in a standartized way as a string.
|
||||
@@ -27,8 +27,8 @@ def get_standard_name_number(current_number: str, number_str_length: int) -> str
|
||||
# logger.debug(
|
||||
# f"FUNC: get_standard_name_number() index={current_number} string_length={number_str_length}"
|
||||
# )
|
||||
current_number = str(current_number)
|
||||
standard_name_number = str.zfill(current_number, number_str_length)
|
||||
temp_current_number = str(current_number)
|
||||
standard_name_number = str.zfill(temp_current_number, number_str_length)
|
||||
# logger.debug(
|
||||
# f"FUNC: get_standard_name_number() return value= '{standard_name_number}'"
|
||||
# )
|
||||
@@ -121,13 +121,6 @@ def get_current_path(path) -> str:
|
||||
str: _Returns the path of the current directory after check for existence_
|
||||
"""
|
||||
|
||||
# TODO: write test for the current path function, test for:
|
||||
# - None
|
||||
# - for existing path
|
||||
# - for non existing path
|
||||
|
||||
# NOTE: research how to check for paths in test functions...
|
||||
|
||||
logger.debug(f"FUNC: get_current_path() MSG: entered function with path = '{path}'")
|
||||
if path is None:
|
||||
# Set the current directory if none is passed with the command.
|
||||
@@ -150,3 +143,38 @@ def get_current_path(path) -> str:
|
||||
logger.warning(ERROR_MESSAGE)
|
||||
print(ERROR_MESSAGE)
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
# FIXME: th function needs some attention
|
||||
# TODO:
|
||||
# - add proper debugging
|
||||
# - make it walk down one directory.
|
||||
def create_recursive_folders(
|
||||
input_path, target_depth, current_depth, width, curret_width
|
||||
):
|
||||
"""Creates a recursive directory structure with y as depth and x as width"""
|
||||
|
||||
if current_depth == target_depth:
|
||||
sys.exit(1)
|
||||
# length_width = str(len(width))
|
||||
|
||||
length_width = len(str(width))
|
||||
logger.debug(
|
||||
f"FUNC: create_recursive_folders(length_width) MSG: length_width='{length_width}'"
|
||||
)
|
||||
while curret_width < width:
|
||||
# TODO: fix the issue, that the number gets appended to an existing number
|
||||
new_directory_name = "sub_dir" + get_standard_name_number(length_width, width)
|
||||
new_directory_path = os.path.join(input_path, new_directory_name)
|
||||
print(new_directory_path)
|
||||
curret_width += 1
|
||||
create_recursive_folders(
|
||||
new_directory_path,
|
||||
target_depth,
|
||||
width,
|
||||
current_depth + 1,
|
||||
curret_width,
|
||||
)
|
||||
|
||||
|
||||
# create_recursive_folders(".", 2, 0, 3)
|
||||
|
||||
@@ -52,7 +52,7 @@ class Refit_Create:
|
||||
|
||||
while n > 0:
|
||||
# iterating down for the files number.
|
||||
folder_number = str(n - 1)
|
||||
folder_number = n - 1
|
||||
|
||||
# Passing the number and the length of the string to get the string back.
|
||||
number_string = librefit.get_standard_name_number(folder_number, length_n)
|
||||
@@ -85,7 +85,7 @@ class Refit_Create:
|
||||
while n > 0:
|
||||
# Get number of the file(s) to create
|
||||
|
||||
file_number = str(n - 1)
|
||||
file_number = 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.
|
||||
@@ -100,6 +100,19 @@ class Refit_Create:
|
||||
# Counting down n for the next ieration of the while-loop
|
||||
n -= 1
|
||||
|
||||
def create_recursive(self, recursive, name, input, n):
|
||||
"""Creating directories recursively"""
|
||||
logger.debug(
|
||||
f"FUNC: create_recursive(beginning) MSG: entered function with following arguments: recursive='{recursive}' name='{name}' input='{input}' n='{n}'"
|
||||
)
|
||||
librefit.create_recursive_folders(
|
||||
input,
|
||||
recursive[0],
|
||||
0,
|
||||
recursive[1],
|
||||
0,
|
||||
)
|
||||
|
||||
def input_validator(self):
|
||||
"""Function, which checks if the user input is valid"""
|
||||
|
||||
@@ -110,16 +123,21 @@ class Refit_Create:
|
||||
"FUNC: input_validator() MSG: No directory passed to the command, continue with current directory"
|
||||
)
|
||||
|
||||
# Check for conflicting flags
|
||||
if self.recursive is not None and self.filemode:
|
||||
logger.error("Filemode and recursive do not work together.")
|
||||
print("Filemode and recursive do not work together.")
|
||||
sys.exit(1)
|
||||
# Check if recursive input is an empty list
|
||||
if self.recursive is not None:
|
||||
if len(self.recursive) < 3:
|
||||
if len(self.recursive) < 2:
|
||||
logger.error("Recursive flag cannot be set without values.")
|
||||
sys.exit(1)
|
||||
|
||||
# Exit the program if the -n argument is not passed
|
||||
if self.n is None:
|
||||
logger.error(
|
||||
f"FUNC rf_create_decider(n=None ?) MSG: the number value cannot be '{self.n}'"
|
||||
f"FUNC create_dispatcher(n=None ?) MSG: the number value cannot be '{self.n}'"
|
||||
)
|
||||
print("Use the '-n' flag for the create command.")
|
||||
sys.exit(1)
|
||||
@@ -129,44 +147,36 @@ class Refit_Create:
|
||||
)
|
||||
return True
|
||||
|
||||
def rf_create_decider(self):
|
||||
def create_dispatcher(self):
|
||||
"""Coordination of the 'create' sub command"""
|
||||
logger.debug("FUNC: rf_create_decider() MSG: Entered decider function")
|
||||
logger.debug("FUNC: create_dispatcher() MSG: Entered decider function")
|
||||
|
||||
if self.input_validator():
|
||||
logger.debug(
|
||||
f"FUNC: rf_create_decider() MSG: n={self.n} after input validating"
|
||||
f"FUNC: create_dispatcher() MSG: n={self.n} after input validating"
|
||||
)
|
||||
|
||||
# Exits the program if recursive and filemode flags are set at the same time
|
||||
if self.filemode:
|
||||
logger.debug(
|
||||
f"FUNC: rf_create_decider(filemode) MSG: given arguments: {self.n} {self.input} {self.name}"
|
||||
f"FUNC: create_dispatcher(filemode) MSG: given arguments: n={self.n} input={self.input} name={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.")
|
||||
self.create_n_files(self.n, self.input, self.name)
|
||||
|
||||
if self.recursive is not None:
|
||||
elif 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}"
|
||||
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)
|
||||
|
||||
# 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?????")
|
||||
elif not self.recursive and not self.filemode:
|
||||
logger.debug(
|
||||
f"FUNC: create_dispatcher(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:
|
||||
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}"
|
||||
f"FUNC: create_dispatcher(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"
|
||||
@@ -175,4 +185,4 @@ class Refit_Create:
|
||||
|
||||
def __call__(self):
|
||||
"""Gets called when the 'create' subcommand is used."""
|
||||
self.rf_create_decider()
|
||||
self.create_dispatcher()
|
||||
|
||||
@@ -82,8 +82,8 @@ create_parser.add_argument(
|
||||
create_parser.add_argument(
|
||||
"-r",
|
||||
"--recursive",
|
||||
# action="store_true",
|
||||
nargs="*",
|
||||
type=int,
|
||||
nargs=2,
|
||||
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)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
[VERSION]
|
||||
major = 0
|
||||
minor = 3
|
||||
patch = 2
|
||||
patch = 3
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
from src.modules.librefit import (
|
||||
get_current_path,
|
||||
get_standard_folder_name,
|
||||
get_standard_name_number,
|
||||
get_standard_file_name,
|
||||
@@ -42,3 +43,18 @@ def test_folder_name_list():
|
||||
folder_names = ["folder1", "folder2", "folder3"]
|
||||
return_folder_name = get_standard_folder_name(folder_names)
|
||||
assert "folder1" in return_folder_name
|
||||
|
||||
|
||||
def test_get_current_directory():
|
||||
"""Tests if the directory is set to the current directory, if None
|
||||
is passed with the argument"""
|
||||
path = None
|
||||
directory = get_current_path(path)
|
||||
assert "." in directory
|
||||
|
||||
|
||||
def test_for_existing_path():
|
||||
"""Tests if the function returns the correct path."""
|
||||
path = "/home/cerberus/Documents/books/"
|
||||
directory = get_current_path(path)
|
||||
assert "/home/cerberus/Documents/books/" in directory
|
||||
|
||||
Reference in New Issue
Block a user