[app/console] use EDITOR env variable to edit input
This commit is contained in:
parent
7c573b47a6
commit
4b05f77329
1 changed files with 19 additions and 5 deletions
|
|
@ -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,11 +434,24 @@ class ConsoleApplication(BaseApplication):
|
||||||
|
|
||||||
return v.get()
|
return v.get()
|
||||||
|
|
||||||
def acquire_input(self):
|
def acquire_input(self, content=None):
|
||||||
if sys.stdin.isatty():
|
editor = os.environ.get('EDITOR')
|
||||||
print 'Reading content from stdin... Type ctrl-D ' \
|
if sys.stdin.isatty() and editor:
|
||||||
'from an empty line to stop.'
|
f = NamedTemporaryFile(delete=False)
|
||||||
text = sys.stdin.read()
|
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():
|
||||||
|
print 'Reading content from stdin... Type ctrl-D ' \
|
||||||
|
'from an empty line to stop.'
|
||||||
|
text = sys.stdin.read()
|
||||||
return text.decode(sys.stdin.encoding or locale.getpreferredencoding())
|
return text.decode(sys.stdin.encoding or locale.getpreferredencoding())
|
||||||
|
|
||||||
def bcall_error_handler(self, backend, error, backtrace):
|
def bcall_error_handler(self, backend, error, backtrace):
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue