Compare commits
2 Commits
2b324fe2ef
...
16aba4c60f
| Author | SHA1 | Date | |
|---|---|---|---|
| 16aba4c60f | |||
| 2ad1d32fcc |
@@ -1,6 +1,7 @@
|
||||
# refit
|
||||
|
||||
`refit` is a file, directory manipulation and creation tool.
|
||||
`refit` is a file and directory manipulation tool. Currently it can create a flat folder and file structure
|
||||
as well as an linear directory structure.
|
||||
|
||||
## ToDos
|
||||
|
||||
@@ -16,6 +17,9 @@
|
||||
- implement config file containing version, default names and other
|
||||
configurations
|
||||
- make file and directory creation start counting at 1 instead of 0
|
||||
- Add security check which benchmarks the creation of folders and files
|
||||
before the first execution in order to prevent either python, the file
|
||||
system or the system in general to crash.
|
||||
|
||||
## Changelog
|
||||
|
||||
|
||||
@@ -153,15 +153,30 @@ def get_current_path(path) -> str:
|
||||
sys.exit(1)
|
||||
|
||||
|
||||
def create_linear_directories(input_path, target_depth, current_depth, name):
|
||||
"""Creates the linear directories for the x*y pattern"""
|
||||
def create_linear_directories(
|
||||
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(
|
||||
# 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:
|
||||
base_name = "level"
|
||||
else:
|
||||
@@ -169,39 +184,63 @@ def create_linear_directories(input_path, target_depth, current_depth, name):
|
||||
|
||||
if current_depth > target_depth:
|
||||
return
|
||||
|
||||
# Create directory name
|
||||
directory_name = (
|
||||
base_name
|
||||
+ "_"
|
||||
+ 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)
|
||||
|
||||
os.mkdir(path)
|
||||
|
||||
# Recursive call of itself
|
||||
create_linear_directories(path, target_depth, current_depth + 1, name)
|
||||
|
||||
|
||||
def create_parallel_directories(input_path, target_depth, width, name):
|
||||
"""Creates directories after the pattern x*y"""
|
||||
def create_parallel_directories(input_path: str, target_depth: int, width: int, name):
|
||||
"""Creates the branches which house the levels.
|
||||
|
||||
# TODO: - add dynamic name input
|
||||
# - add docstring
|
||||
logger.debug(
|
||||
f"FUNC: create_parallel_directories(entered) VALUES: path='{input_path}', target_depth='{target_depth}', width='{width}', name={name}"
|
||||
)
|
||||
As input it takes the input_path and the width from which it creates
|
||||
the branches of the structure. Afterwards it passes the target_depth
|
||||
to another function to create the levels of each branch.
|
||||
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:
|
||||
base_name = "branch"
|
||||
else:
|
||||
base_name = name[0]
|
||||
|
||||
for i in range(width):
|
||||
# Create directory name
|
||||
directory_name = (
|
||||
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)
|
||||
os.mkdir(path)
|
||||
|
||||
# Recursive call of itself
|
||||
create_linear_directories(
|
||||
input_path=path,
|
||||
target_depth=target_depth,
|
||||
|
||||
@@ -43,11 +43,10 @@ REFIT_VERSION = f"Refit Beta {read_version_config()}"
|
||||
|
||||
# Main Parser
|
||||
parser = argparse.ArgumentParser(
|
||||
prog="Refit",
|
||||
description="This is a file and directory manipulation tool.\
|
||||
it can create, move and delete files and directories as well as \
|
||||
renaming them",
|
||||
prog="refit",
|
||||
description="""This is a file and directory manipulation tool. It can create, move and delete files and directories as well as renaming them""",
|
||||
epilog=REFIT_VERSION,
|
||||
formatter_class=argparse.RawDescriptionHelpFormatter,
|
||||
)
|
||||
|
||||
# Main Parser Arguments
|
||||
@@ -55,30 +54,51 @@ parser = argparse.ArgumentParser(
|
||||
# Create Parser
|
||||
subparser = parser.add_subparsers(
|
||||
title="Commands",
|
||||
dest="create",
|
||||
required=False,
|
||||
)
|
||||
|
||||
# Create Parser Arguments
|
||||
create_parser = subparser.add_parser("create", help="creates a new file/folder")
|
||||
create_parser.add_argument("-n", type=int, help="number of items")
|
||||
create_parser.add_argument("-i", "--input", help="input file")
|
||||
create_parser = subparser.add_parser(
|
||||
name="create",
|
||||
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(
|
||||
"--name",
|
||||
nargs="*",
|
||||
help="the name of the folder you want to create\n Default: directory",
|
||||
)
|
||||
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",
|
||||
metavar="INT",
|
||||
type=int,
|
||||
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)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
Reference in New Issue
Block a user