backport check_output for 2.6
This commit is contained in:
parent
22ac81650d
commit
69a78db3b3
5 changed files with 34 additions and 6 deletions
|
|
@ -31,7 +31,9 @@ import re
|
|||
import os
|
||||
from datetime import datetime
|
||||
from tempfile import mkstemp
|
||||
from subprocess import check_output, STDOUT
|
||||
from subprocess import STDOUT
|
||||
from weboob.tools.compat import check_output
|
||||
|
||||
from time import sleep
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -25,7 +25,8 @@ import ssl
|
|||
import json
|
||||
import os
|
||||
from tempfile import mkstemp
|
||||
from subprocess import check_output, STDOUT
|
||||
from subprocess import STDOUT
|
||||
from weboob.tools.compat import check_output
|
||||
from urllib import unquote
|
||||
|
||||
from .pages import LoginProceedPage, LoginRedirectPage, \
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ from weboob.core.repositories import ModuleInstallError, IProgress
|
|||
from weboob.exceptions import BrowserUnavailable, BrowserIncorrectPassword, BrowserForbidden, BrowserSSLError, BrowserQuestion
|
||||
from weboob.tools.value import Value, ValueBool, ValueFloat, ValueInt, ValueBackendPassword
|
||||
from weboob.tools.misc import to_unicode
|
||||
from weboob.tools.compat import check_output
|
||||
from weboob.tools.ordereddict import OrderedDict
|
||||
|
||||
from .base import Application, MoreResultsAvailable
|
||||
|
|
@ -448,7 +449,7 @@ class ConsoleApplication(Application):
|
|||
while True:
|
||||
cmd = self.ask('')
|
||||
try:
|
||||
subprocess.check_output(cmd, shell=True)
|
||||
check_output(cmd, shell=True)
|
||||
except subprocess.CalledProcessError as e:
|
||||
print('%s' % e)
|
||||
else:
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
# along with weboob. If not, see <http://www.gnu.org/licenses/>.
|
||||
|
||||
|
||||
__all__ = ['unicode', 'long', 'basestring']
|
||||
__all__ = ['unicode', 'long', 'basestring', 'check_output']
|
||||
|
||||
|
||||
try:
|
||||
|
|
@ -35,3 +35,25 @@ try:
|
|||
basestring = basestring
|
||||
except NameError:
|
||||
basestring = str
|
||||
|
||||
|
||||
try:
|
||||
from subprocess import check_output
|
||||
except ImportError:
|
||||
import subprocess
|
||||
|
||||
def check_output(*popenargs, **kwargs):
|
||||
r"""Run command with arguments and return its output as a byte string.
|
||||
Backported from Python 2.7 as it's implemented as pure python on stdlib.
|
||||
"""
|
||||
process = subprocess.Popen(stdout=subprocess.PIPE, *popenargs, **kwargs)
|
||||
output, unused_err = process.communicate()
|
||||
retcode = process.poll()
|
||||
if retcode:
|
||||
cmd = kwargs.get("args")
|
||||
if cmd is None:
|
||||
cmd = popenargs[0]
|
||||
error = subprocess.CalledProcessError(retcode, cmd)
|
||||
error.output = output
|
||||
raise error
|
||||
return output
|
||||
|
|
|
|||
|
|
@ -20,8 +20,10 @@
|
|||
|
||||
import re
|
||||
import subprocess
|
||||
from .ordereddict import OrderedDict
|
||||
|
||||
from .compat import check_output
|
||||
from .misc import to_unicode
|
||||
from .ordereddict import OrderedDict
|
||||
|
||||
|
||||
__all__ = ['ValuesDict', 'Value', 'ValueBackendPassword', 'ValueInt', 'ValueFloat', 'ValueBool']
|
||||
|
|
@ -149,7 +151,7 @@ class ValueBackendPassword(Value):
|
|||
if self.is_command(password):
|
||||
cmd = password[1:-1]
|
||||
try:
|
||||
password = subprocess.check_output(cmd, shell=True)
|
||||
password = check_output(cmd, shell=True)
|
||||
except subprocess.CalledProcessError as e:
|
||||
raise ValueError(u'The call to the external tool failed: %s' % e)
|
||||
else:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue