summaryrefslogtreecommitdiff
path: root/base/utils.py
diff options
context:
space:
mode:
authorDidier Raboud <odyx@debian.org>2016-02-13 15:36:35 +0100
committerDidier Raboud <odyx@debian.org>2016-02-13 15:36:35 +0100
commit42862c2115c242b8eb685a29af5b3db6a07655e7 (patch)
tree78915f483c1f1e47c1438e7e1f3b488789a37b17 /base/utils.py
parentd1298c61974ba45d190a1e6bc26ac551676f726f (diff)
Imported Upstream version 3.16.2
Diffstat (limited to 'base/utils.py')
-rw-r--r--base/utils.py56
1 files changed, 36 insertions, 20 deletions
diff --git a/base/utils.py b/base/utils.py
index f1ec1e168..d6debaf6c 100644
--- a/base/utils.py
+++ b/base/utils.py
@@ -107,23 +107,21 @@ ERROR_DIGITAL_SIGN_BAD =3
MAJ_VER = sys.version_info[0]
MIN_VER = sys.version_info[1]
-
-
EXPECT_WORD_LIST = [
pexpect.EOF, # 0
pexpect.TIMEOUT, # 1
- "Continue?", # 2 (for zypper)
- "passwor[dt]:", # en/de/it/ru
- "kennwort", # de?
- "password for", # en
- "mot de passe", # fr
- "contraseña", # es
- "palavra passe", # pt
- "口令", # zh
- "wachtwoord", # nl
- "heslo", # czech
- "密码",
- "Lösenord", #sv
+ u"Continue?", # 2 (for zypper)
+ u"passwor[dt]:", # en/de/it/ru
+ u"kennwort", # de?
+ u"password for", # en
+ u"mot de passe", # fr
+ u"contraseña", # es
+ u"palavra passe", # pt
+ u"口令", # zh
+ u"wachtwoord", # nl
+ u"heslo", # czech
+ u"密码",
+ u"Lösenord", #sv
]
@@ -1260,6 +1258,17 @@ def run(cmd, passwordObj = None, pswd_msg='', log_output=True, spinner=True, tim
import io
output = io.StringIO()
+ pwd_prompt_str = ""
+ if passwordObj and ('su' in cmd or 'sudo' in cmd) and os.geteuid() != 0:
+ pwd_prompt_str = passwordObj.getPasswordPromptString()
+ log.debug("cmd = %s pwd_prompt_str = [%s]"%(cmd, pwd_prompt_str))
+ if(pwd_prompt_str == ""):
+ passwd = passwordObj.getPassword(pswd_msg, 0)
+ pwd_prompt_str = passwordObj.getPasswordPromptString()
+ log.debug("pwd_prompt_str2 = [%s]"%(pwd_prompt_str))
+ if(passwd == ""):
+ return 127, ""
+
try:
child = pexpect.spawnu(cmd, timeout=timeout)
except pexpect.ExceptionPexpect as e:
@@ -1277,15 +1286,22 @@ def run(cmd, passwordObj = None, pswd_msg='', log_output=True, spinner=True, tim
continue
if child.before:
+ if(pwd_prompt_str and pwd_prompt_str not in EXPECT_LIST):
+ log.debug("Adding %s to EXPECT LIST"%pwd_prompt_str)
+ try:
+ p = re.compile(pwd_prompt_str, re.I)
+ except TypeError:
+ EXPECT_LIST.append(pwd_prompt_str)
+ else:
+ EXPECT_LIST.append(p)
+ EXPECT_LIST.append(pwd_prompt_str)
+
try:
output.write(child.before)
+ if log_output:
+ log.debug(child.before)
except Exception:
pass
- if log_output:
- try:
- log.debug(child.before)
- except Exception:
- pass
if i == 0: # EOF
break
@@ -2018,7 +2034,7 @@ def download_from_network(weburl, outputFile = None, useURLLIB=False):
if useURLLIB:
- sys.stdout.write("Download in progress..........")
+ #sys.stdout.write("Download in progress..........")
try:
response = urllib2_request.urlopen(weburl)
file_fd = open(outputFile, 'wb')