new method ConsoleApplication.acquire_input() to read stdin friendly
This commit is contained in:
parent
9e3b1a049e
commit
e731f42cb9
4 changed files with 12 additions and 9 deletions
|
|
@ -230,12 +230,7 @@ class Boobmsg(ReplApplication):
|
||||||
"""
|
"""
|
||||||
receivers, text = self.parse_command_args(line, 2, 1)
|
receivers, text = self.parse_command_args(line, 2, 1)
|
||||||
if text is None:
|
if text is None:
|
||||||
if self.interactive:
|
text = self.acquire_input()
|
||||||
print 'Reading message content from stdin... Type ctrl-D ' \
|
|
||||||
'from an empty line to post message.'
|
|
||||||
text = sys.stdin.read()
|
|
||||||
if sys.stdin.encoding:
|
|
||||||
text = text.decode(sys.stdin.encoding)
|
|
||||||
|
|
||||||
if self.options.skip_empty and not text.strip():
|
if self.options.skip_empty and not text.strip():
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -77,7 +77,7 @@ class Pastoob(ReplApplication):
|
||||||
The filename can be '-' for reading standard input (pipe).
|
The filename can be '-' for reading standard input (pipe).
|
||||||
"""
|
"""
|
||||||
if not filename or filename == '-':
|
if not filename or filename == '-':
|
||||||
contents = sys.stdin.read().decode(sys.stdin.encoding or locale.getpreferredencoding())
|
contents = self.acquire_input()
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
with codecs.open(filename, encoding=locale.getpreferredencoding()) as fp:
|
with codecs.open(filename, encoding=locale.getpreferredencoding()) as fp:
|
||||||
|
|
|
||||||
|
|
@ -107,7 +107,7 @@ class WeboobCfg(ReplApplication):
|
||||||
print >>sys.stderr, 'Error: backend "%s" does not support accounts management' % backend_name
|
print >>sys.stderr, 'Error: backend "%s" does not support accounts management' % backend_name
|
||||||
return 1
|
return 1
|
||||||
|
|
||||||
mail = sys.stdin.read()
|
mail = self.acquire_input()
|
||||||
if not backend.confirm_account(mail):
|
if not backend.confirm_account(mail):
|
||||||
print >>sys.stderr, 'Error: Unable to confirm account creation'
|
print >>sys.stderr, 'Error: Unable to confirm account creation'
|
||||||
return 1
|
return 1
|
||||||
|
|
|
||||||
|
|
@ -23,6 +23,7 @@ import getpass
|
||||||
import logging
|
import logging
|
||||||
import sys
|
import sys
|
||||||
import os
|
import os
|
||||||
|
import locale
|
||||||
|
|
||||||
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
|
||||||
|
|
@ -186,7 +187,7 @@ class ConsoleApplication(BaseApplication):
|
||||||
backends = [(b.name, b) for b in self.enabled_backends]
|
backends = [(b.name, b) for b in self.enabled_backends]
|
||||||
if unique_backend and not backend_name:
|
if unique_backend and not backend_name:
|
||||||
if len(backends) == 1:
|
if len(backends) == 1:
|
||||||
backend_name = backends[0]
|
backend_name = backends[0][0]
|
||||||
else:
|
else:
|
||||||
raise BackendNotGiven(_id, backends)
|
raise BackendNotGiven(_id, backends)
|
||||||
if backend_name is not None and not backend_name in dict(backends):
|
if backend_name is not None and not backend_name in dict(backends):
|
||||||
|
|
@ -413,6 +414,13 @@ class ConsoleApplication(BaseApplication):
|
||||||
|
|
||||||
return v.get()
|
return v.get()
|
||||||
|
|
||||||
|
def acquire_input(self):
|
||||||
|
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())
|
||||||
|
|
||||||
def bcall_error_handler(self, backend, error, backtrace):
|
def bcall_error_handler(self, backend, error, backtrace):
|
||||||
"""
|
"""
|
||||||
Handler for an exception inside the CallErrors exception.
|
Handler for an exception inside the CallErrors exception.
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue