[opensuse-buildservice] [PATCH0/1] raw_input checks if stdin is tty
Python's raw_input does not check if stdin is conntected to the terminal, which makes it pretty hard to call such script from an another one or from ssh. This patch changes the raw_input from osc.core - in case sys.stdin is not connected to the terminal, it raises RawInputError. The from osc.core import raw_input lines were added to oscssl.py and build.py to enforce this behavior as much as possible. --- osc/build.py | 1 + osc/core.py | 2 ++ osc/oscerr.py | 8 ++++++++ osc/oscssl.py | 2 ++ 4 files changed, 13 insertions(+) diff --git a/osc/build.py b/osc/build.py index add7631..211b046 100644 --- a/osc/build.py +++ b/osc/build.py @@ -14,6 +14,7 @@ from tempfile import NamedTemporaryFile, mkdtemp from osc.fetch import * from osc.core import get_buildinfo, store_read_apiurl, store_read_project, store_read_package, meta_exists, quote_plus, get_buildconfig, is_package_dir from osc.core import get_binarylist, get_binary_file +from osc.core import raw_input from osc.util import rpmquery, debquery, archquery import osc.conf import oscerr diff --git a/osc/core.py b/osc/core.py index 1ac189b..70d064e 100644 --- a/osc/core.py +++ b/osc/core.py @@ -6381,6 +6381,8 @@ def get_user_projpkgs(apiurl, user, role=None, exclude_projects=[], proj=True, p return res def raw_input(*args): + if getattr(os, "isatty") and not os.isatty(sys.stdin.fileno()): + raise oscerr.RawInputError(*args) import __builtin__ try: return __builtin__.raw_input(*args) diff --git a/osc/oscerr.py b/osc/oscerr.py index 5429ddf..cd6ba62 100644 --- a/osc/oscerr.py +++ b/osc/oscerr.py @@ -150,4 +150,12 @@ class PackageInternalError(PackageError): def __init__(self, prj, pac, msg): PackageError.__init__(self, prj, pac) self.msg = msg + +class RawInputError(OscBaseError): + def __init__(self, *args): + OscBaseError.__init__(self, *args) + + def __str__(self): + return "Following question cannot be answered, because tandard input is not connected to the terminal\n\n\n%s" % self.args + # vim: sw=4 et diff --git a/osc/oscssl.py b/osc/oscssl.py index 127c0cd..f6c2dea 100644 --- a/osc/oscssl.py +++ b/osc/oscssl.py @@ -13,6 +13,8 @@ import urllib import httplib import sys +from osc.core import raw_input + class TrustedCertStore: _tmptrusted = {} -- 1.7.10.4
participants (1)
-
Michal Vyskocil