diff --git a/weboob/tools/application/console.py b/weboob/tools/application/console.py index d9a1486b..3859d0d6 100644 --- a/weboob/tools/application/console.py +++ b/weboob/tools/application/console.py @@ -17,6 +17,7 @@ # You should have received a copy of the GNU Affero General Public License # along with weboob. If not, see . +from __future__ import with_statement from copy import copy import getpass @@ -438,18 +439,16 @@ class ConsoleApplication(BaseApplication): return v.get() def acquire_input(self, content=None): - editor = os.environ.get('EDITOR') + editor = os.getenv('EDITOR', 'vi') if sys.stdin.isatty() and editor: - f = NamedTemporaryFile(delete=False) - filename = f.name - if content is not None: - f.write(content) - f.close() - os.system("%s %s" % (editor, filename)) - f = open(filename, 'r') - text = f.read() - f.close() - os.unlink(filename) + with NamedTemporaryFile() as f: + filename = f.name + if content is not None: + f.write(content) + f.flush() + os.system("%s %s" % (editor, filename)) + f.seek(0) + text = f.read() else: if sys.stdin.isatty(): print 'Reading content from stdin... Type ctrl-D ' \