Compare commits

21 Commits

Author SHA1 Message Date
5d4788475e bumped version 2025-10-16 20:00:53 +02:00
de6f0ac17e update README.md 2025-10-16 19:53:49 +02:00
f148beedf5 removed old version file 2025-10-16 19:52:40 +02:00
82e6856439 changed the way on how to get the version to a json file, added helper to libreftit 2025-10-16 19:51:16 +02:00
6cbb352efb added prettifyed version output 2025-10-16 18:16:15 +02:00
ecd460d3ad removed comments 2025-10-16 18:15:33 +02:00
1c47c68c11 i guess it works 2025-10-14 21:31:05 +02:00
d5dcd35696 ups, i made a version bumper 2025-10-13 23:08:34 +02:00
9e954d0790 version bump 2025-10-13 23:07:46 +02:00
171370ecac update README.md 2025-10-12 19:54:53 +02:00
fb78fe459f update README.md 2025-10-12 19:47:16 +02:00
16aba4c60f added doc strings to librefit and cleaned refit.py 2025-10-12 19:45:07 +02:00
2ad1d32fcc update README.md 2025-10-12 19:44:17 +02:00
2b324fe2ef update README.md 2025-10-05 19:58:11 +02:00
99d90d607d update README.md 2025-10-05 19:44:32 +02:00
8c81064743 added support for file extensions 2025-10-05 19:43:09 +02:00
9c39b773da added custom naming to recursion and fixed naming in filemode 2025-10-05 15:58:36 +02:00
46ea1db65d -n flag no longer required for recursive mode 2025-10-05 12:12:49 +02:00
f7ab347316 cleanup 2025-10-04 19:47:56 +02:00
2b1167b3ce cleanup 2025-10-04 19:44:41 +02:00
fe3f32c2af update README.md 2025-10-04 19:20:30 +02:00
9 changed files with 417 additions and 161 deletions

View File

@@ -1,7 +1,14 @@
# Python Programs and Scripts Repository # Python Programs and Scripts Repository
![Python](https://img.shields.io/badge/python-3670A0?style=for-the-badge&logo=python&logoColor=ffdd54) ![Python](https://img.shields.io/badge/python-3670A0?style=for-the-badge&logo=python&logoColor=ffdd54)
Collection of my python scripts and programs. Containing tools to manipulate the behavior of the system. Collection of my python scripts and programs. Containing tools to
manipulate the behavior of the system.
## Wanna Do´s
- Program which creates an file containing a version and
- Creating a Module which loads configuration files
- GUI auto-clicker which accepts command line activation
## tempbox ## tempbox
@@ -10,8 +17,9 @@ directory.
After execution, all contents within the folder get removed. After execution, all contents within the folder get removed.
## refit ## refit
A file and folder manipulation tool. The aim is to unify various steps from moving to creating and deleting A file and folder manipulation tool. The aim is to unify various steps
directories and folder with one tool. from moving to creating and deleting directories and folder with one
tool.

211
pyvers/src/pyvers.py Normal file
View File

@@ -0,0 +1,211 @@
import json
import os
import argparse
import sys
# ======================================================================
# Constantes
FILE_NAME = "version.json"
# ======================================================================
# ======================================================================
# Parser
parser = argparse.ArgumentParser(
prog="pyvers",
description="xD",
)
parser.add_argument(
"config",
help="The location of the config file to edit.",
type=str,
)
parser.add_argument(
"--patch",
help="Bumps the patch version by one.",
action="store_true",
)
parser.add_argument(
"--minor",
help="Bumps the minor version by one.",
action="store_true",
)
parser.add_argument(
"--major",
help="Bumps the major version by one.",
action="store_true",
)
args = parser.parse_args()
# ======================================================================
# ======================================================================
# Functions
def create_version_file(file_path) -> None:
"""Creates a version.json file with all versions set to 0 at the
input location.
Args:
file_path: (str): Path with file name.
Example:
>>>create_version_file(/path/to/file)
file:
{
"minor": 0,
"major": 0,
"patch": 0
}"""
# Defining the dictionary with the initial version numbers.
initial_version = {"minor": 0, "major": 0, "patch": 0}
# Opening/creating the file to write the dictionary as json to it.
file = open(file_path, "x")
file.write(json.dumps(initial_version, indent=4))
print("File written successfully.")
return
def load_version(input_path) -> dict[str, int]:
"""Opens the given file and returns its contents."""
# Open given path and loading the files contents into a variable
file_path = open(input_path)
prog_version = json.load(file_path)
return prog_version
def pretty_version(input_path) -> None:
"""Prints the version in a prettifyed format."""
prog_version = load_version(input_path)
pretty_version = (
f"{prog_version['major']}.{prog_version['minor']}.{prog_version['patch']}"
)
print(pretty_version)
def bump_patch(version_file) -> None:
"""Bumps the patch number of the given file by one."""
# Get the version as dictionary
version = load_version(version_file)
# Adding one to the version from the file and updating
# the dictionary
new_version = version["patch"] + 1
version.update({"patch": new_version})
# Opening the file and overwriting its contents.
with open(version_file, "w") as f:
f.write(json.dumps(version, indent=4))
def bump_minor(version_file) -> None:
"""Bumps the minor version number of the given file by one."""
# Get the version as dictionary
version = load_version(version_file)
# Adding one to the version from the file and updating
# the dictionary
new_version = version["minor"] + 1
version.update({"minor": new_version})
# Opening the file and overwriting its contents.
with open(version_file, "w") as f:
f.write(json.dumps(version, indent=4))
def bump_major(version_file) -> None:
"""Bumps the major version number of the given file by one."""
# Get the version as dictionary
version = load_version(version_file)
# Adding one to the version from the file and updating
# the dictionary
new_version = version["major"] + 1
version.update({"major": new_version})
# Opening the file and overwriting its contents.
with open(version_file, "w") as f:
f.write(json.dumps(version, indent=4))
def version_bumper(version_file, major_version, minor_version, patch) -> None:
"""Decides what version to bump, based on the users passed flags"""
if patch:
bump_patch(version_file)
if minor_version:
bump_minor(version_file)
if major_version:
bump_major(version_file)
def check_for_file(input_path: str) -> bool:
"""Checks if the file 'version.json' exists at the given path.
Args:
input_path ( str ): Path to check for the file.
Example:
>>>check_for_file(".")
'False'
>>>check_for_file("version.json")
'True'
>>>check_for_file("./version.json")
'True'
"""
if FILE_NAME in input_path:
file_path = os.path.expanduser(input_path)
if os.path.exists(file_path):
return True
else:
return False
elif os.path.exists(os.path.join(input_path, FILE_NAME)):
return True
else:
return False
def request_to_create():
"""Prompts the user if he wants to create the file and exits if the
user declines or presses any other character instead of 'y/Y'"""
PROMPT = "The file does not exist, do you want to create it? [y/n]"
PROMPT += "\n>>>"
response = input(PROMPT)
if "y" in response or "Y" in response:
file_path = os.path.join(
os.path.expanduser(args.config),
FILE_NAME,
)
create_version_file(file_path)
return
else:
parser.print_help()
sys.exit(1)
# ======================================================================
# Dispatching
if check_for_file(args.config):
file_path = os.path.join(os.path.expanduser(args.config), FILE_NAME)
if args.patch or args.minor or args.major:
version_bumper(
version_file=file_path,
major_version=args.major,
minor_version=args.minor,
patch=args.patch,
)
else:
pretty_version(file_path)
if check_for_file(args.config) is False:
request_to_create()
file_path = os.path.join(os.path.expanduser(args.config), FILE_NAME)
version_bumper(
version_file=file_path,
major_version=args.major,
minor_version=args.minor,
patch=args.patch,
)

View File

@@ -1,32 +1,33 @@
# refit # 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 ## ToDos
1. folder and file creation 1. folder and file creation
1.1 simple file and folder creation 1.1 simple file and folder creation
1.2 recursive file and folder creation 1.2 recursive file and folder creation
1.3 file in folder creation
2. file movement 2. file movement
2.1 apply a pattern what to move to where 2.1 file deletion
3. file removal
3.1 remove all files like '*.tar'
- ~~make input default the current directory and the - implement config file containing version, default names and other
second argument after `refit create`~~ configurations
- ~~maybe get rid of valid input ??~~ - make file and directory creation start counting at 1 instead of 0
- rework rf_create_decider() so it does not execute if no inputs are give - Add security check which benchmarks the creation of folders and files
n -> valid input check back for no arguments passed? before the first execution in order to prevent either python, the file
- check done in rf_create_decider() system or the system in general to crash.
- get rid of input argument, default to current directory and make it
positional
- implement back in the valid input check
## Changelog ## Changelog
<2025-10-16> V0.3.9 - Changed how the version is read
<2025-10-05> V0.3.8 - Added file extension to file creation mode
<2025-10-05> V0.3.7 - Added custom naming for level and branch in
recursive mode
<2025-10-05> V0.3.6 - Recursive mode no longer requires the -n flag
<2025-10-04> V0.3.5 - Added a function which returns the length of a <2025-10-04> V0.3.5 - Added a function which returns the length of a
number number
<2025-10-04> V0.3.5 - Changed the recursive mode into an linear x*y <2025-10-04> V0.3.5 - Changed the recursive mode into an linear x*y
pattern pattern
<2025-10-04> V0.3.4 - Added recursive directory creation and fixed <2025-10-04> V0.3.4 - Added recursive directory creation and fixed

View File

@@ -1,5 +1,6 @@
import os import os
import sys import sys
import json
from .refit_logger import logger from .refit_logger import logger
@@ -153,44 +154,124 @@ def get_current_path(path) -> str:
sys.exit(1) sys.exit(1)
# TODO: - add dynamic name input def create_linear_directories(
# - add docstring input_path: str, target_depth: int, current_depth: int, name
def create_linear_directories(input_path, target_depth, current_depth): ):
"""Creates the linear directories for the x*y pattern""" """Creates the linear directories for the x*y pattern
logger.debug( If no name is given the name of the level is defaulted to 'level'.
f"FUNC: create_linear_directories(entered) VALUES: path='{input_path}', target_depth='{target_depth}', current_depth='{current_depth}'" 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._
"""
# 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:
base_name = name[1]
if current_depth > target_depth: if current_depth > target_depth:
return return
# Create directory name
directory_name = "level_" + get_standard_name_number( directory_name = (
current_depth, base_name
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)
create_linear_directories(path, target_depth, current_depth + 1) # Recursive call of itself
create_linear_directories(path, target_depth, current_depth + 1, name)
# TODO: - add dynamic name input def create_parallel_directories(input_path: str, target_depth: int, width: int, name):
# - add docstring """Creates the branches which house the levels.
def create_parallel_directories(input_path, target_depth, width):
"""Creates directories after the pattern x*y"""
logger.debug( As input it takes the input_path and the width from which it creates
f"FUNC: create_parallel_directories(entered) VALUES: path='{input_path}', target_depth='{target_depth}', width='{width}'" 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.
# # Getting the lenth of the number string which gets addedto the dir name. Args:
# length_width = get_int_length(width) 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): for i in range(width):
directory_name = "branch_" + get_standard_name_number(i, get_int_length(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) path = os.path.join(input_path, directory_name)
os.mkdir(path) os.mkdir(path)
create_linear_directories(path, target_depth, current_depth=0) # Recursive call of itself
create_linear_directories(
input_path=path,
target_depth=target_depth,
current_depth=0,
name=name,
)
def get_version_from_file(input_path) -> str:
"""Returns the version of the program.
The function accepts an path to a version file as a string and it
returns it version number formatted.
Arg:
input_path (str): The absolute or relative path to the
version file.
Example:
>>>get_version_from_file("/path/to/file.json")
'0.2.1'"""
# Expands the input path
expanded_path = os.path.expanduser(input_path)
# Opening the file and reading its contents, saving as as an dict.
file_path = open(expanded_path)
prog_version = json.load(file_path)
# Formatting the output before returning the string again
pretty_version = (
f"{prog_version['major']}.{prog_version['minor']}.{prog_version['patch']}"
)
return pretty_version

View File

@@ -5,18 +5,13 @@ import sys
from .refit_logger import logger from .refit_logger import logger
from . import librefit from . import librefit
# logger.debug("Initiated refit_create.py")
# ----------------------------------------------------------------------
class Refit_Create: class Refit_Create:
"""A class to create folders and files. """A class to create folders and files.
It first calls the decider which lets the create_input_valid() function It first calls the decider which lets the create_input_valid() function
check if the input argument exists. If create_input_valid() returns check if the input argument exists. If create_input_valid() returns
'True' it continues to execute the command as per the given arguments. 'True' it continues to execute the command as per the given arguments."""
default folder name: directory"""
def __init__(self, args): def __init__(self, args):
"""Initiating variables for creation""" """Initiating variables for creation"""
@@ -27,6 +22,7 @@ class Refit_Create:
self.n = args.n self.n = args.n
self.filemode = args.filemode self.filemode = args.filemode
self.recursive = args.recursive self.recursive = args.recursive
self.e = args.e
def create_n_folders(self, n, input, name): def create_n_folders(self, n, input, name):
"""Creates an set ammount of folders. Using the default directory """Creates an set ammount of folders. Using the default directory
@@ -35,21 +31,11 @@ class Refit_Create:
logger.debug(f"FUNC: create_n_folders() ARGS: n={n} input={input} name={name}") logger.debug(f"FUNC: create_n_folders() ARGS: n={n} input={input} name={name}")
# Creating the length of the suffix number_string. # Creating the length of the suffix number_string.
length_n = len(str(n)) length_n = librefit.get_int_length(n)
logger.debug(
f"FUNC: create_n_folders() MSG: Length of numbering string added to the name:{length_n}"
)
# Get either the default folder name or the input name as string. # Get either the default folder name or the input name as string.
logger.debug(
f"FUNC: create_n_folders() MSG: Type of name value: {type(name)} name={name}"
)
folder_name = librefit.get_standard_folder_name(name) folder_name = librefit.get_standard_folder_name(name)
logger.debug(
f"FUNC: create_n_folders() MSG: Folder name: {folder_name} post get_standard_folder_name() call"
)
while n > 0: while n > 0:
# iterating down for the files number. # iterating down for the files number.
folder_number = n - 1 folder_number = n - 1
@@ -65,7 +51,7 @@ class Refit_Create:
os.mkdir(folder_creation_path) os.mkdir(folder_creation_path)
n -= 1 n -= 1
def create_n_files(self, n, input, name): def create_n_files(self, n, input, name, file_extension):
"""Creates an set ammount of files, using the default file name """Creates an set ammount of files, using the default file name
if none is provided.""" if none is provided."""
@@ -73,15 +59,12 @@ class Refit_Create:
f"FUNC: create_n_files() MSG: Entered function VALUES: n={self.n} name={self.name} input={self.input}" f"FUNC: create_n_files() MSG: Entered function VALUES: n={self.n} name={self.name} input={self.input}"
) )
# Creating the length of the suffix number_string.
length_n = librefit.get_int_length(n)
# Get the name from the input argument. # Get the name from the input argument.
file_name = librefit.get_standard_file_name(name) file_name = librefit.get_standard_file_name(name)
# Get the length of the entered number to fill it with 0
length_n = len(str(n))
logger.debug(
f"FUNC: create_n_files() MSG: file name='{file_name}' length_n={length_n}"
)
while n > 0: while n > 0:
# Get number of the file(s) to create # Get number of the file(s) to create
@@ -89,90 +72,81 @@ class Refit_Create:
number_string = librefit.get_standard_name_number(file_number, length_n) 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. # Get the name of the file, either applying default or using first list item.
temp_name = f"{file_name}_{number_string}" if file_extension is not None:
temp_name = f"{file_name}_{number_string}.{file_extension}"
else:
temp_name = f"{file_name}_{number_string}"
file_path = Path(os.path.join(input, temp_name)) # Build file path file_path = Path(os.path.join(input, temp_name)) # Build file path
file_path.touch(exist_ok=True) # creating file 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)}"
)
# Counting down n for the next ieration of the while-loop # Counting down n for the next ieration of the while-loop
n -= 1 n -= 1
def create_recursive(self, recursive, name, input, n): def create_recursive(self, recursive, name, input):
"""Creating directories recursively""" """Creating directories recursively"""
logger.debug( logger.debug(
f"FUNC: create_recursive(beginning) MSG: entered function with following arguments: recursive='{recursive}' name='{name}' input='{input}' n='{n}'" f"FUNC: create_recursive(beginning) MSG: entered function with following arguments: recursive='{recursive}' name='{name}' input='{input}'"
) )
# librefit.create_recursive_folders(
# input_path=input,
# target_depth=recursive[0],
# current_depth=0,
# width=recursive[1],
# )
librefit.create_parallel_directories( librefit.create_parallel_directories(
input_path=input, target_depth=recursive[0], width=recursive[1] input_path=input,
target_depth=recursive[0],
width=recursive[1],
name=name,
) )
def input_validator(self): def input_validator(self):
"""Function, which checks if the user input is valid""" """Function, which checks if the user input is valid"""
# TODO: make the input validator pass without the n argument
# when recursive mode is active
# Check working directory # Check working directory
if self.input is None: if self.input is None:
self.input = librefit.get_current_path(self.input) self.input = librefit.get_current_path(self.input)
logger.info( logger.info(f"FUNC: input_validator(input check) VALUE: input={self.input}")
"FUNC: input_validator() MSG: No directory passed to the command, continue with current directory"
)
# Check for conflicting flags # Check for conflicting flags
if self.recursive is not None and self.filemode: if self.recursive is not None and self.filemode:
logger.error("Filemode and recursive do not work together.") logger.error(
f"FUNC: input_validator(recursive&filemode?) VALUES: recursive='{self.recursive}', filemode={self.filemode}"
)
print("Filemode and recursive do not work together.") print("Filemode and recursive do not work together.")
sys.exit(1) sys.exit(1)
# Check if recursive input is an empty list # Check if recursive input is an empty list
if self.recursive is not None: if self.recursive is not None:
if len(self.recursive) < 2: if len(self.recursive) < 2:
logger.error("Recursive flag cannot be set without values.") logger.error(
"FUNC:input_validator(recursive) MSG: Invalid input, enter 2 numbers!"
)
sys.exit(1) sys.exit(1)
# Exit the program if the -n argument is not passed # Exit the program if the -n argument is not passed
if self.n is None: if self.n is None and self.recursive is None:
logger.error( logger.error(
f"FUNC create_dispatcher(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.") print("Use the '-n' flag for the create command.")
sys.exit(1) sys.exit(1)
else: else:
logger.debug(
f"FUNC: input_validator() MSG: valid number entered n={self.n}"
)
return True return True
def create_dispatcher(self): def create_dispatcher(self):
"""Coordination of the 'create' sub command""" """Coordination of the 'create' sub command"""
logger.debug("FUNC: create_dispatcher() MSG: Entered decider function") logger.debug(
f"FUNC: create_dispatcher() MSG: Entered decider function {self.args}"
)
if self.input_validator(): if self.input_validator():
logger.debug(
f"FUNC: create_dispatcher() MSG: n={self.n} after input validating"
)
if self.filemode: if self.filemode:
logger.debug( logger.debug(
f"FUNC: create_dispatcher(filemode) MSG: given arguments: n={self.n} input={self.input} name={self.name}" f"FUNC: create_dispatcher(filemode) MSG: given arguments: n={self.n} input={self.input} name={self.name} file_extension={self.e}"
) )
self.create_n_files(self.n, self.input, self.name) self.create_n_files(self.n, self.input, self.name, self.e)
elif self.recursive is not None: elif self.recursive is not None:
logger.debug( logger.debug(
f"FUNC: create_dispatcher(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) self.create_recursive(self.recursive, self.name, self.input)
elif not self.recursive and not self.filemode: elif not self.recursive and not self.filemode:
logger.debug( logger.debug(

View File

@@ -27,6 +27,3 @@ def handle_exception(exec_type, exec_value, exec_traceback):
sys.excepthook = handle_exception sys.excepthook = handle_exception
# logger.debug(f"Log path:\t{log_dir}")
# logger.debug(f"Log file:\t{log_file}")

View File

@@ -1,61 +1,23 @@
import argparse import argparse
import sys import sys
import os
import configparser
from modules.refit_logger import logger from modules.refit_logger import logger
from modules.refit_create import Refit_Create from modules.refit_create import Refit_Create
from modules.librefit import get_version_from_file
# NOTE: The final version file needs a dedicated place to live in
CONFIG_FILE = "version.cfg" # so the version number is always readable, independent from where it
# is executed
REFIT_VERSION = get_version_from_file("~/Documents/git/python/refit/src/version.json")
# TODO: comment the actions done in read_version_config()
# TODO: see the TODO in librefit: move the config file section into the
# libary
def read_version_config():
logger.debug(f"Start read_version_config() with config file: {CONFIG_FILE}")
config = configparser.ConfigParser()
config.read(CONFIG_FILE)
if not os.path.exists(CONFIG_FILE):
logger.error(
f"FUNC: read_version_config() MSG: Could not find config file '{CONFIG_FILE}'"
)
return "x.x.x"
if "VERSION" not in config:
logger.error(f"Could not find VERSION-variable in config file '{CONFIG_FILE}'")
return "x.x.x"
try:
v = config["VERSION"]
major = v.get("major", "0")
minor = v.get("minor", "0")
patch = v.get("patch", "0")
logger.debug(f"Config file read successfully. Version: {major}.{minor}.{patch}")
return f"{major}.{minor}.{patch}"
except Exception:
logger.warning("Couldn not read version from config file")
return "x.x.x"
REFIT_VERSION = f"Refit Beta {read_version_config()}"
# ---------------------------ARGPARSE START--------------------------- # ---------------------------ARGPARSE START---------------------------
# TODO: Rework the structure of the argument parsing
# 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
@@ -63,28 +25,50 @@ 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\n 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.set_defaults(command_class=Refit_Create) create_parser.set_defaults(command_class=Refit_Create)
@@ -95,7 +79,7 @@ args = parser.parse_args()
# Dispatcher # Dispatcher
# determines what code gets addressed based of the users chosen flags. # determines what code gets addressed based of the users chosen flags.
if hasattr(args, "command_class"): if hasattr(args, "command_class"):
logger.debug(f"In dispatcher with args: {args}") # logger.debug(f"In dispatcher with args: {args}")
Refit_Create = args.command_class Refit_Create = args.command_class
create_command_instance = Refit_Create(args) create_command_instance = Refit_Create(args)
create_command_instance() create_command_instance()

View File

@@ -1,5 +0,0 @@
[VERSION]
major = 0
minor = 3
patch = 5

5
refit/src/version.json Normal file
View File

@@ -0,0 +1,5 @@
{
"minor": 3,
"major": 0,
"patch": 9
}