refactor librefit and added docstrings
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
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
|
||||
|
||||
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.
|
||||
|
||||
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.
|
||||
|
||||
Examples:
|
||||
@@ -29,7 +29,7 @@ def get_standard_name_number(current_number, number_str_length):
|
||||
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.
|
||||
|
||||
This function sanitizes the input, which gets passed as a list or None from
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import argparse
|
||||
import os
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
from .refit_logger import logger
|
||||
from . import librefit
|
||||
@@ -20,19 +20,21 @@ 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):
|
||||
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
|
||||
@@ -101,17 +103,16 @@ class Refit_Create:
|
||||
)
|
||||
|
||||
while n > 0:
|
||||
|
||||
# Get number of the file(s) to create
|
||||
file_number = str(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.
|
||||
temp_name = f"{file_name}_{number_string}"
|
||||
|
||||
file_path = Path(os.path.join(input, temp_name)) # Build file path
|
||||
file_path.touch(exist_ok=True) # creating file
|
||||
|
||||
file_path = Path(os.path.join(input, temp_name)) # Build file path
|
||||
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)}"
|
||||
)
|
||||
@@ -121,17 +122,29 @@ class Refit_Create:
|
||||
def rf_create_decider(self):
|
||||
"""Coordination of the 'create' sub command"""
|
||||
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.filemode:
|
||||
logger.debug("DECISION if filemode")
|
||||
self.create_n_files(self.n, self.input, self.name)
|
||||
else:
|
||||
logger.debug(
|
||||
f"DIR-MODE | ARGS: n={self.n} input={self.input} name={self.name}"
|
||||
)
|
||||
self.create_n_folders(self.n, self.input, self.name)
|
||||
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:
|
||||
logger.debug("DECISION if filemode")
|
||||
self.create_n_files(self.n, self.input, self.name)
|
||||
elif self.n is not None:
|
||||
logger.debug(
|
||||
f"DIR-MODE | ARGS: 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() 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."""
|
||||
|
||||
Reference in New Issue
Block a user