From 540b2c311393d918d4ae802e628d1a926971b6e5 Mon Sep 17 00:00:00 2001 From: Fabien Benureau Date: Thu, 22 Jan 2015 04:07:30 +0100 Subject: [PATCH] more robust parsing of bash commands. added remove_file method stub. --- pubs/content.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/pubs/content.py b/pubs/content.py index 9d015fc..b646b7c 100644 --- a/pubs/content.py +++ b/pubs/content.py @@ -3,6 +3,7 @@ import io import subprocess import tempfile import shutil +import shlex from .p3 import urlparse, HTTPConnection, urlopen @@ -66,6 +67,11 @@ def read_file(filepath): return content +def remove_file(filepath): + check_file(filepath) + os.remove(filepath) + + def write_file(filepath, data): check_directory(os.path.dirname(filepath)) with _open(filepath, 'w') as f: @@ -150,7 +156,7 @@ def editor_input(editor, initial=u"", suffix='.tmp'): with tempfile.NamedTemporaryFile(suffix=suffix, delete=False) as temp_file: tfile_name = temp_file.name temp_file.write(str_initial) - cmd = editor.split() # this enable editor command with option, e.g. gvim -f + cmd = shlex.split(editor) # this enable editor command with option, e.g. gvim -f cmd.append(tfile_name) subprocess.call(cmd) content = read_file(tfile_name)