add create delete folder files
This commit is contained in:
@@ -63,6 +63,37 @@ def select_file(file_path: Path) -> ProcessFile:
|
|||||||
raise ValueError(f"{file_path} is not a file")
|
raise ValueError(f"{file_path} is not a file")
|
||||||
|
|
||||||
|
|
||||||
|
def create_folder(file_path: Path) -> ProcessFile:
|
||||||
|
"""Creates a folder in a file_path"""
|
||||||
|
input_folder = INPUT / file_path
|
||||||
|
if input_folder.exists():
|
||||||
|
raise ValueError(f"{file_path} already exists")
|
||||||
|
else:
|
||||||
|
input_folder.mkdir(exist_ok=True, parents=True)
|
||||||
|
return ProcessFile(input_folder)
|
||||||
|
|
||||||
|
|
||||||
|
def delete_folder(file_path: Path):
|
||||||
|
"""delete an empty folder in file_path"""
|
||||||
|
input_folder = INPUT / file_path
|
||||||
|
if input_folder.exists():
|
||||||
|
if any(Path("some/path/here").iterdir()):
|
||||||
|
raise ValueError(f"{file_path} has files inside")
|
||||||
|
else:
|
||||||
|
input_folder.rmdir()
|
||||||
|
else:
|
||||||
|
raise ValueError(f"{file_path} doesn't exists")
|
||||||
|
|
||||||
|
|
||||||
|
def delete_file(file_path: Path):
|
||||||
|
"""Deletes a file in a file_path"""
|
||||||
|
input_file = INPUT / file_path
|
||||||
|
if input_file.if_file():
|
||||||
|
input_file.unlink()
|
||||||
|
else:
|
||||||
|
raise ValueError(f"{file_path} doesn't exists")
|
||||||
|
|
||||||
|
|
||||||
def list_file_resources(file_path: ProcessFile):
|
def list_file_resources(file_path: ProcessFile):
|
||||||
"""Returns a list of a file_path resources files"""
|
"""Returns a list of a file_path resources files"""
|
||||||
return [file_path.resources.glob("*")]
|
return [file_path.resources.glob("*")]
|
||||||
@@ -130,7 +161,6 @@ def write_input_file(process_file: ProcessFile, text: str):
|
|||||||
file.write(f"{line}\n")
|
file.write(f"{line}\n")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def write_resource_file(process_file: ProcessFile, language_id: str, text: str):
|
def write_resource_file(process_file: ProcessFile, language_id: str, text: str):
|
||||||
process_file.language_id = language_id
|
process_file.language_id = language_id
|
||||||
with process_file.dictionary_resource_file.open(
|
with process_file.dictionary_resource_file.open(
|
||||||
|
|||||||
Reference in New Issue
Block a user