added support for file extensions

This commit is contained in:
2025-10-05 19:43:09 +02:00
parent 9c39b773da
commit 8c81064743
2 changed files with 12 additions and 8 deletions

View File

@@ -22,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
@@ -50,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."""
@@ -71,6 +72,9 @@ 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.
if file_extension is not None:
temp_name = f"{file_name}_{number_string}.{file_extension}"
else:
temp_name = f"{file_name}_{number_string}" 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
@@ -127,19 +131,18 @@ class Refit_Create:
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():
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:
# NOTE: for the dynamic name use two more args, if they
# exist, take them as name for the two dirs. else use
# default names
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}"
) )

View File

@@ -78,6 +78,7 @@ create_parser.add_argument(
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", 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()