refactor librefit and added docstrings
This commit is contained in:
@@ -14,10 +14,13 @@
|
|||||||
3.1 remove all files like '*.tar'
|
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 ??
|
- ~~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?
|
||||||
|
- get rid of input argument, default to current directory and and make it positional
|
||||||
|
|
||||||
## 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-09-29> V0.3.1 - Removed the requirement for an input
|
<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-29> V0.2.4 - Improved logging and log readability
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
from .refit_logger import logger
|
from .refit_logger import logger
|
||||||
|
|
||||||
|
|
||||||
def get_standard_name_number(current_number, number_str_length):
|
def get_standard_name_number(current_number: str, number_str_length: int) -> str:
|
||||||
"""Returns a number string filled to the length of the input number
|
"""Returns a number string filled to the length of the input number
|
||||||
|
|
||||||
This function returns the number in a standartized way as a string.
|
This function returns the number in a standartized way as a string.
|
||||||
@@ -9,7 +9,7 @@ def get_standard_name_number(current_number, number_str_length):
|
|||||||
number which determines the length of the string.
|
number which determines the length of the string.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
current_number (int): The current number of the item.
|
current_number (str): The current number of the item.
|
||||||
number_str_length (int): The length of the string which gets returned.
|
number_str_length (int): The length of the string which gets returned.
|
||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
@@ -29,7 +29,7 @@ def get_standard_name_number(current_number, number_str_length):
|
|||||||
return standard_name_number
|
return standard_name_number
|
||||||
|
|
||||||
|
|
||||||
def get_standard_folder_name(name) -> str:
|
def get_standard_folder_name(name: str) -> str:
|
||||||
"""Returnes a standard name either from a list or the default value.
|
"""Returnes a standard name either from a list or the default value.
|
||||||
|
|
||||||
This function sanitizes the input, which gets passed as a list or None from
|
This function sanitizes the input, which gets passed as a list or None from
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import argparse
|
|
||||||
import os
|
import os
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
import sys
|
||||||
|
|
||||||
from .refit_logger import logger
|
from .refit_logger import logger
|
||||||
from . import librefit
|
from . import librefit
|
||||||
@@ -20,19 +20,21 @@ class Refit_Create:
|
|||||||
|
|
||||||
def __init__(self, args):
|
def __init__(self, args):
|
||||||
"""Initiating variables for creation"""
|
"""Initiating variables for creation"""
|
||||||
self.args = args
|
|
||||||
|
|
||||||
self.name = args.name
|
self.name = args.name
|
||||||
self.input = args.input
|
self.input = args.input
|
||||||
self.n = args.n
|
self.n = args.n
|
||||||
self.filemode = args.filemode
|
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
|
"""Checks if the input is argument for its existence. If no input
|
||||||
argument with a value is passed, the current directory is used and
|
argument with a value is passed, the current directory is used and
|
||||||
passed to the input"""
|
passed to the input"""
|
||||||
|
|
||||||
logger.debug(f"Start create_input_valid() value= {self.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:
|
if self.input is None:
|
||||||
input = "."
|
input = "."
|
||||||
self.input = input
|
self.input = input
|
||||||
@@ -101,7 +103,6 @@ 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)
|
||||||
@@ -121,17 +122,29 @@ class Refit_Create:
|
|||||||
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")
|
||||||
if self.create_input_valid():
|
|
||||||
logger.debug(f"Valid input. value={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.critical(self.input)
|
||||||
|
|
||||||
if self.filemode:
|
if self.filemode:
|
||||||
logger.debug("DECISION if filemode")
|
logger.debug("DECISION if filemode")
|
||||||
self.create_n_files(self.n, self.input, self.name)
|
self.create_n_files(self.n, self.input, self.name)
|
||||||
else:
|
elif self.n is not None:
|
||||||
logger.debug(
|
logger.debug(
|
||||||
f"DIR-MODE | ARGS: n={self.n} input={self.input} name={self.name}"
|
f"DIR-MODE | ARGS: n={self.n} input={self.input} name={self.name}"
|
||||||
)
|
)
|
||||||
self.create_n_folders(self.n, self.input, 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):
|
def __call__(self):
|
||||||
"""Gets called when the 'create' subcommand is used."""
|
"""Gets called when the 'create' subcommand is used."""
|
||||||
|
|||||||
@@ -70,6 +70,12 @@ create_parser.add_argument(
|
|||||||
create_parser.add_argument(
|
create_parser.add_argument(
|
||||||
"--filemode", action="store_true", help="creates files instead of directories"
|
"--filemode", action="store_true", help="creates files instead of directories"
|
||||||
)
|
)
|
||||||
|
create_parser.add_argument(
|
||||||
|
"-r",
|
||||||
|
"--recursive",
|
||||||
|
nargs="*",
|
||||||
|
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)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
[VERSION]
|
[VERSION]
|
||||||
major = 0
|
major = 0
|
||||||
minor = 3
|
minor = 3
|
||||||
patch = 1
|
patch = 2
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user