From 7c1e3dc8d8eb7e6aea461b338f13ef7a7e226be4 Mon Sep 17 00:00:00 2001 From: Zen <46526140+master-of-zen@users.noreply.github.com> Date: Mon, 10 May 2021 07:46:02 +0300 Subject: [PATCH] add output overwrite promt --- av1an/manager/Manager.py | 1 + av1an/project/Project.py | 25 +++++++++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/av1an/manager/Manager.py b/av1an/manager/Manager.py index 19dbf7f..093a342 100644 --- a/av1an/manager/Manager.py +++ b/av1an/manager/Manager.py @@ -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 diff --git a/av1an/project/Project.py b/av1an/project/Project.py index 91bbd18..4f8bfbb 100644 --- a/av1an/project/Project.py +++ b/av1an/project/Project.py @@ -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))