From 24be25dc7b834f26a9011477ae0706ae250c7368 Mon Sep 17 00:00:00 2001 From: Playermet Date: Tue, 19 May 2015 13:09:08 +0300 Subject: [PATCH] Way to set note extension If note title has extension and it present in "note_file_extensions" list, than it used instead of "note_save_extension". --- notes.py | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/notes.py b/notes.py index 9b86322..8bd9adb 100644 --- a/notes.py +++ b/notes.py @@ -144,7 +144,11 @@ def create_note(self, title): if not os.path.exists(directory): os.makedirs(directory) - ext = "." + settings().get("note_save_extension") + if any(title.endswith("." + ext) for ext in settings().get("note_file_extensions")): + ext = "" + else: + ext = "." + settings().get("note_save_extension") + file = os.path.join(directory, title + ext) if not os.path.exists(file): open(file, 'w+').close() @@ -332,7 +336,11 @@ def rename_note(self, title): if not os.path.exists(directory): os.makedirs(directory) - ext = "." + settings().get("note_save_extension") + if any(title.endswith("." + ext) for ext in settings().get("note_file_extensions")): + ext = "" + else: + ext = "." + settings().get("note_save_extension") + new_file_path = os.path.join(directory, title + ext) # pardir = os.path.abspath(os.path.join(self.file_path, '..')) if not os.path.isfile(new_file_path):