added file creation
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import argparse
|
||||
import os
|
||||
from pathlib import Path
|
||||
|
||||
from .refit_logger import logger
|
||||
from . import librefit
|
||||
@@ -65,10 +66,10 @@ class Refit_Create:
|
||||
|
||||
while n > 0:
|
||||
# iterating down for the files number.
|
||||
i = str(n - 1)
|
||||
folder_number = str(n - 1)
|
||||
|
||||
# Passing the number and the length of the string to get the string back.
|
||||
number_string = librefit.get_standard_name_number(i, length_n)
|
||||
number_string = librefit.get_standard_name_number(folder_number, length_n)
|
||||
|
||||
# Creating path for the folder
|
||||
temp_name = f"{folder_name}_{number_string}"
|
||||
@@ -78,6 +79,37 @@ class Refit_Create:
|
||||
os.mkdir(folder_creation_path)
|
||||
n -= 1
|
||||
|
||||
def create_n_files(self, n, input, name):
|
||||
"""Creates an set ammount of files, using the default file name
|
||||
if none is provided."""
|
||||
|
||||
logger.debug(
|
||||
f"FUNC: create_n_files() MSG: Entered function VALUES: n={self.n} name={self.name} input={self.input}"
|
||||
)
|
||||
|
||||
# Get name of the file
|
||||
file_name = librefit.get_standard_file_name(name)
|
||||
length_n = len(str(n))
|
||||
logger.debug(
|
||||
f"FUNC: create_n_files() MSG: file name='{file_name}' length_n={length_n}"
|
||||
)
|
||||
|
||||
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)
|
||||
|
||||
temp_name = f"{file_name}_{number_string}"
|
||||
|
||||
file_path = Path(os.path.join(input, temp_name))
|
||||
|
||||
file_path.touch(exist_ok=True)
|
||||
logger.debug(
|
||||
f"FUNC: create_n_files MSG: created file at {os.path.join(input, temp_name)}"
|
||||
)
|
||||
|
||||
n -= 1
|
||||
|
||||
def rf_create_decider(self):
|
||||
"""Coordination of the 'create' sub command"""
|
||||
logger.debug("FUNC: rf_create_decider() MSG: Entered decider function")
|
||||
@@ -86,6 +118,7 @@ class Refit_Create:
|
||||
|
||||
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}"
|
||||
|
||||
Reference in New Issue
Block a user