add output overwrite promt

This commit is contained in:
Zen 2021-05-10 07:46:02 +03:00
parent 6b06327103
commit 7c1e3dc8d8
2 changed files with 22 additions and 4 deletions

View file

@ -38,6 +38,7 @@ class Main:
project = Project(vars(self.args))
project.input = file
project.outputs_filenames()
project.promt_output_overwrite()
queue.append(project)
return queue

View file

@ -126,7 +126,7 @@ class Project(object):
def outputs_filenames(self):
"""
Set output filename
Set output filename and promts overwrite if file exists
:param project: the Project
"""
@ -137,15 +137,32 @@ class Project(object):
# Check for non-empty string
if isinstance(self.output_file, str) and self.output_file:
if self.output_file[-1] in ('\\', '/'):
if self.output_file[-1] in ("\\", "/"):
if not Path(self.output_file).exists():
os.makedirs(Path(self.output_file), exist_ok=True)
self.output_file = Path(f"{self.output_file}{self.input.stem}_{self.encoder}{suffix}")
self.output_file = Path(
f"{self.output_file}{self.input.stem}_{self.encoder}{suffix}"
)
else:
self.output_file = Path(self.output_file).with_suffix(suffix)
else:
self.output_file = Path(f"{self.input.stem}_{self.encoder}{suffix}")
def promt_output_overwrite(self):
if self.output_file.exists():
print(
f":: Output file {self.output_file} exist, overwrite? [y/n or enter]:"
)
promt = input()
if "y" in promt.lower() or promt.strip() == "":
pass
else:
print("Stopping")
sys.exit()
def load_project_from_file(self, path_string):
"""
Loads projedt attributes from json to this class
@ -202,7 +219,7 @@ class Project(object):
"""Creating temporally folders when needed."""
if self.temp:
if self.temp[-1] in ('\\', '/'):
if self.temp[-1] in ("\\", "/"):
self.temp = Path(f"{self.temp}{'.' + str(hash_path(str(self.input)))}")
else:
self.temp = Path(str(self.temp))