From 2541c6bee536085fedd7576debc5eef8d34a9abd Mon Sep 17 00:00:00 2001 From: Raz Luvaton Date: Fri, 1 May 2020 18:13:55 +0300 Subject: [PATCH 1/2] =?UTF-8?q?hot-fix(pull)=20create=20file=20if=20doesn?= =?UTF-8?q?=E2=80=99t=20exist?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Used `w+` > `w+` create file if it doesn't exist and open it in (over)write mode > [it overwrites the file if it already exists] --- keep/commands/cmd_pull.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/keep/commands/cmd_pull.py b/keep/commands/cmd_pull.py index 50250ca8..25d35a19 100644 --- a/keep/commands/cmd_pull.py +++ b/keep/commands/cmd_pull.py @@ -22,6 +22,7 @@ def cli(ctx): if click.confirm(prompt_str, abort=True): os.remove(commands_file_path) - with open(commands_file_path, 'w') as commands_file: + """Using `w+` so it create the file if doesn't exist (Issue #64)""" + with open(commands_file_path, 'w+') as commands_file: commands_file.write(gist.files['commands.json'].content) - click.echo("Done!") \ No newline at end of file + click.echo("Done!") From 4be00fbdb546d9edf83afb6c72c8e590ee4dbefa Mon Sep 17 00:00:00 2001 From: Raz Luvaton Date: Fri, 1 May 2020 18:32:08 +0300 Subject: [PATCH 2/2] =?UTF-8?q?hot-fix(pull)=20don=E2=80=99t=20remove=20th?= =?UTF-8?q?e=20file=20just=20overwrite=20it?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit The bug in #64 was in `os.remove` because the file didn’t exist so it couldn’t be removed, so I removed the `remove` because we overwrite the file anyway --- keep/commands/cmd_pull.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/keep/commands/cmd_pull.py b/keep/commands/cmd_pull.py index 25d35a19..446b9049 100644 --- a/keep/commands/cmd_pull.py +++ b/keep/commands/cmd_pull.py @@ -20,7 +20,7 @@ def cli(ctx): gist_url = f"https://gist.github.com/{token['gist']}" prompt_str = f"[CRITICAL] Replace local commands with GitHub gist\nGist URL : {gist_url} ?" if click.confirm(prompt_str, abort=True): - os.remove(commands_file_path) + pass """Using `w+` so it create the file if doesn't exist (Issue #64)""" with open(commands_file_path, 'w+') as commands_file: