added doc strings to librefit and cleaned refit.py
This commit is contained in:
@@ -153,15 +153,30 @@ def get_current_path(path) -> str:
|
|||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
def create_linear_directories(input_path, target_depth, current_depth, name):
|
def create_linear_directories(
|
||||||
"""Creates the linear directories for the x*y pattern"""
|
input_path: str, target_depth: int, current_depth: int, name
|
||||||
|
):
|
||||||
|
"""Creates the linear directories for the x*y pattern
|
||||||
|
|
||||||
|
If no name is given the name of the level is defaulted to 'level'.
|
||||||
|
Otherwise it takes the second input of the --name argument. In the
|
||||||
|
end it appends the number of the folder.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
input_path ( str ): _The current working directory.
|
||||||
|
target_depth ( int ): _The depth on how deepo directories are created._
|
||||||
|
current_depth ( int ): _The current depth of the folder creation._
|
||||||
|
name ( list[str] | None ): _The name of the level directories._
|
||||||
|
"""
|
||||||
|
|
||||||
# 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}'"
|
||||||
# )
|
# )
|
||||||
|
|
||||||
|
# TODO: Find a way on how to specify the type in the function call
|
||||||
|
# and let the if statement pass.
|
||||||
|
|
||||||
|
# Get base directory name
|
||||||
if name is None:
|
if name is None:
|
||||||
base_name = "level"
|
base_name = "level"
|
||||||
else:
|
else:
|
||||||
@@ -169,39 +184,63 @@ def create_linear_directories(input_path, target_depth, current_depth, name):
|
|||||||
|
|
||||||
if current_depth > target_depth:
|
if current_depth > target_depth:
|
||||||
return
|
return
|
||||||
|
# Create directory name
|
||||||
directory_name = (
|
directory_name = (
|
||||||
base_name
|
base_name
|
||||||
+ "_"
|
+ "_"
|
||||||
+ get_standard_name_number(current_depth, get_int_length(target_depth))
|
+ get_standard_name_number(current_depth, get_int_length(target_depth))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Create the path where to create directory
|
||||||
path = os.path.join(input_path, directory_name)
|
path = os.path.join(input_path, directory_name)
|
||||||
|
|
||||||
os.mkdir(path)
|
os.mkdir(path)
|
||||||
|
|
||||||
|
# Recursive call of itself
|
||||||
create_linear_directories(path, target_depth, current_depth + 1, name)
|
create_linear_directories(path, target_depth, current_depth + 1, name)
|
||||||
|
|
||||||
|
|
||||||
def create_parallel_directories(input_path, target_depth, width, name):
|
def create_parallel_directories(input_path: str, target_depth: int, width: int, name):
|
||||||
"""Creates directories after the pattern x*y"""
|
"""Creates the branches which house the levels.
|
||||||
|
|
||||||
# TODO: - add dynamic name input
|
As input it takes the input_path and the width from which it creates
|
||||||
# - add docstring
|
the branches of the structure. Afterwards it passes the target_depth
|
||||||
logger.debug(
|
to another function to create the levels of each branch.
|
||||||
f"FUNC: create_parallel_directories(entered) VALUES: path='{input_path}', target_depth='{target_depth}', width='{width}', name={name}"
|
If 'None' is passed to the '--name' argument, the default name 'branch'
|
||||||
)
|
gets used as base directory name.
|
||||||
|
|
||||||
|
Args:
|
||||||
|
input_path ( str ): _The current working directory.
|
||||||
|
target_depth ( int ): _The depth on how deepo directories are created._
|
||||||
|
width ( int ): _The ammount of branches to create._
|
||||||
|
name ( list[str] | None ): _The name of the level directories._
|
||||||
|
|
||||||
|
"""
|
||||||
|
|
||||||
|
# logger.debug(
|
||||||
|
# f"FUNC: create_parallel_directories(entered) VALUES: path='{input_path}', target_depth='{target_depth}', width='{width}', name={name}"
|
||||||
|
# )
|
||||||
|
|
||||||
|
# TODO: Find a way on how to specify the type in the function call
|
||||||
|
# and let the if statement pass.
|
||||||
|
|
||||||
|
# Get base directory name
|
||||||
if name is None:
|
if name is None:
|
||||||
base_name = "branch"
|
base_name = "branch"
|
||||||
else:
|
else:
|
||||||
base_name = name[0]
|
base_name = name[0]
|
||||||
|
|
||||||
for i in range(width):
|
for i in range(width):
|
||||||
|
# Create directory name
|
||||||
directory_name = (
|
directory_name = (
|
||||||
base_name + "_" + get_standard_name_number(i, get_int_length(width))
|
base_name + "_" + get_standard_name_number(i, get_int_length(width))
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Create the path where to create directory
|
||||||
path = os.path.join(input_path, directory_name)
|
path = os.path.join(input_path, directory_name)
|
||||||
os.mkdir(path)
|
os.mkdir(path)
|
||||||
|
|
||||||
|
# Recursive call of itself
|
||||||
create_linear_directories(
|
create_linear_directories(
|
||||||
input_path=path,
|
input_path=path,
|
||||||
target_depth=target_depth,
|
target_depth=target_depth,
|
||||||
|
|||||||
@@ -43,11 +43,10 @@ REFIT_VERSION = f"Refit Beta {read_version_config()}"
|
|||||||
|
|
||||||
# Main Parser
|
# Main Parser
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
prog="Refit",
|
prog="refit",
|
||||||
description="This is a file and directory manipulation tool.\
|
description="""This is a file and directory manipulation tool. It can create, move and delete files and directories as well as renaming them""",
|
||||||
it can create, move and delete files and directories as well as \
|
|
||||||
renaming them",
|
|
||||||
epilog=REFIT_VERSION,
|
epilog=REFIT_VERSION,
|
||||||
|
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Main Parser Arguments
|
# Main Parser Arguments
|
||||||
@@ -55,30 +54,51 @@ parser = argparse.ArgumentParser(
|
|||||||
# Create Parser
|
# Create Parser
|
||||||
subparser = parser.add_subparsers(
|
subparser = parser.add_subparsers(
|
||||||
title="Commands",
|
title="Commands",
|
||||||
dest="create",
|
|
||||||
required=False,
|
required=False,
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create Parser Arguments
|
# Create Parser Arguments
|
||||||
create_parser = subparser.add_parser("create", help="creates a new file/folder")
|
create_parser = subparser.add_parser(
|
||||||
create_parser.add_argument("-n", type=int, help="number of items")
|
name="create",
|
||||||
create_parser.add_argument("-i", "--input", help="input file")
|
description="The create sub command lets you create files, folders and directory structures.",
|
||||||
|
help="The create sub command lets you create files, folders and directory structures.",
|
||||||
|
)
|
||||||
|
create_parser.add_argument(
|
||||||
|
"-n",
|
||||||
|
metavar="COUNT",
|
||||||
|
type=int,
|
||||||
|
help="Number of items",
|
||||||
|
)
|
||||||
|
create_parser.add_argument(
|
||||||
|
"-i",
|
||||||
|
"--input",
|
||||||
|
metavar="PATH",
|
||||||
|
help="Input path. If not specified the current directory is used.",
|
||||||
|
)
|
||||||
create_parser.add_argument(
|
create_parser.add_argument(
|
||||||
"--name",
|
"--name",
|
||||||
nargs="*",
|
nargs="*",
|
||||||
help="the name of the folder you want to create\n Default: directory",
|
help="the name of the folder you want to create\n Default: directory",
|
||||||
)
|
)
|
||||||
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(
|
create_parser.add_argument(
|
||||||
"-r",
|
"-r",
|
||||||
"--recursive",
|
"--recursive",
|
||||||
|
metavar="INT",
|
||||||
type=int,
|
type=int,
|
||||||
nargs=2,
|
nargs=2,
|
||||||
help="Sets the recursive mode for folders to true. First argumet is for the depth and the second for the width.",
|
help="""Sets the recursive mode for folders to true. First argumet
|
||||||
|
is for the depth and the second for the width.""",
|
||||||
|
)
|
||||||
|
create_parser.add_argument(
|
||||||
|
"-e",
|
||||||
|
type=str,
|
||||||
|
help="File extension which gets appended to the end of the file name.",
|
||||||
)
|
)
|
||||||
create_parser.add_argument("-e", help="File extension")
|
|
||||||
create_parser.set_defaults(command_class=Refit_Create)
|
create_parser.set_defaults(command_class=Refit_Create)
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|||||||
Reference in New Issue
Block a user