[app/console] use EDITOR env variable to edit input

This commit is contained in:
Roger Philibert 2012-03-31 19:26:18 +02:00 committed by Romain Bignon
commit 4b05f77329

View file

@ -24,6 +24,7 @@ import logging
import sys import sys
import os import os
import locale import locale
from tempfile import NamedTemporaryFile
from weboob.capabilities.account import ICapAccount, Account, AccountRegisterError from weboob.capabilities.account import ICapAccount, Account, AccountRegisterError
from weboob.core.backendscfg import BackendAlreadyExists from weboob.core.backendscfg import BackendAlreadyExists
@ -433,7 +434,20 @@ class ConsoleApplication(BaseApplication):
return v.get() return v.get()
def acquire_input(self): def acquire_input(self, content=None):
editor = os.environ.get('EDITOR')
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)
else:
if sys.stdin.isatty(): if sys.stdin.isatty():
print 'Reading content from stdin... Type ctrl-D ' \ print 'Reading content from stdin... Type ctrl-D ' \
'from an empty line to stop.' 'from an empty line to stop.'