Blame SOURCES/hplip-stuck-plugin.patch

b99885
From f46ac074d066884480098c14397f5f3e34475e11 Mon Sep 17 00:00:00 2001
b99885
From: Jiri Popelka <jpopelka@redhat.com>
b99885
Date: Fri, 22 Jan 2016 16:30:13 +0100
b99885
Subject: [PATCH] fix from launchpad #1510950
b99885
b99885
---
b99885
 base/password.py | 17 ++++++++++++++++-
b99885
 base/utils.py    | 53 ++++++++++++++++++++++++++++++++++-------------------
b99885
 2 files changed, 50 insertions(+), 20 deletions(-)
b99885
b99885
diff --git a/base/password.py b/base/password.py
b99885
index 3ca16ae..6caefdf 100644
b99885
--- a/base/password.py
b99885
+++ b/base/password.py
b99885
@@ -104,6 +104,7 @@ def get_distro_name():
b99885
 class Password(object):
b99885
     def __init__(self, Mode = INTERACTIVE_MODE):
b99885
         self.__password =""
b99885
+        self.__password_prompt_str=""
b99885
         self.__passwordValidated = False
b99885
         self.__mode = Mode
b99885
         self.__readAuthType()  #self.__authType   
b99885
@@ -201,7 +202,17 @@ class Password(object):
b99885
                     
b99885
                     cb = child.before
b99885
                     if cb:
b99885
-
b99885
+                        if('true' in cmd and self.__password_prompt_str == ""): #sudo true or su -c "true"
b99885
+                            cb = cb.replace("[", "\[")
b99885
+                            cb = cb.replace("]", "\]")
b99885
+                            self.__password_prompt_str = cb
b99885
+                            try:
b99885
+                                p = re.compile(cb, re.I)
b99885
+                            except TypeError:
b99885
+                                self.__expectList.append(cb)
b99885
+                            else:
b99885
+                                self.__expectList.append(p)
b99885
+                            
b99885
                         start = time.time()
b99885
                         output.write(cb)
b99885
 
b99885
@@ -355,3 +366,7 @@ class Password(object):
b99885
         self.__validatePassword( pswd_msg)
b99885
         return self.__password
b99885
 
b99885
+    def getPasswordPromptString(self):
b99885
+        return self.__password_prompt_str
b99885
+
b99885
+
b99885
diff --git a/base/utils.py b/base/utils.py
b99885
index f1ec1e1..5d108f0 100644
b99885
--- a/base/utils.py
b99885
+++ b/base/utils.py
b99885
@@ -108,22 +108,21 @@ MAJ_VER = sys.version_info[0]
b99885
 MIN_VER = sys.version_info[1]
b99885
 
b99885
 
b99885
-
b99885
 EXPECT_WORD_LIST = [
b99885
     pexpect.EOF, # 0
b99885
     pexpect.TIMEOUT, # 1
b99885
-    "Continue?", # 2 (for zypper)
b99885
-    "passwor[dt]:", # en/de/it/ru
b99885
-    "kennwort", # de?
b99885
-    "password for", # en
b99885
-    "mot de passe", # fr
b99885
-    "contraseña", # es
b99885
-    "palavra passe", # pt
b99885
-    "口令", # zh
b99885
-    "wachtwoord", # nl
b99885
-    "heslo", # czech
b99885
-    "密码",
b99885
-    "Lösenord", #sv
b99885
+    u"Continue?", # 2 (for zypper)
b99885
+    u"passwor[dt]:", # en/de/it/ru
b99885
+    u"kennwort", # de?
b99885
+    u"password for", # en
b99885
+    u"mot de passe", # fr
b99885
+    u"contraseña", # es
b99885
+    u"palavra passe", # pt
b99885
+    u"口令", # zh
b99885
+    u"wachtwoord", # nl
b99885
+    u"heslo", # czech
b99885
+    u"密码",
b99885
+    u"Lösenord", #sv
b99885
 ]
b99885
 
b99885
 
b99885
@@ -1260,6 +1259,15 @@ def run(cmd, passwordObj = None, pswd_msg='', log_output=True, spinner=True, tim
b99885
     import io
b99885
     output = io.StringIO()
b99885
 
b99885
+    pwd_prompt_str = ""
b99885
+    if passwordObj and ('su' in cmd or 'sudo' in cmd):
b99885
+        pwd_prompt_str = passwordObj.getPasswordPromptString()
b99885
+        log.debug("cmd = %s pwd_prompt_str = [%s]"%(cmd, pwd_prompt_str))
b99885
+        if(pwd_prompt_str == ""):
b99885
+            passwordObj.getPassword(pswd_msg, 0)
b99885
+            pwd_prompt_str = passwordObj.getPasswordPromptString()
b99885
+            log.debug("pwd_prompt_str2 = [%s]"%(pwd_prompt_str))
b99885
+
b99885
     try:
b99885
         child = pexpect.spawnu(cmd, timeout=timeout)
b99885
     except pexpect.ExceptionPexpect as e:
b99885
@@ -1277,15 +1285,22 @@ def run(cmd, passwordObj = None, pswd_msg='', log_output=True, spinner=True, tim
b99885
                 continue
b99885
 
b99885
             if child.before:
b99885
+                if(pwd_prompt_str and pwd_prompt_str not in EXPECT_LIST):
b99885
+                    log.debug("Adding %s to EXPECT LIST"%pwd_prompt_str)
b99885
+                    try:
b99885
+                        p = re.compile(pwd_prompt_str, re.I)
b99885
+                    except TypeError:
b99885
+                        EXPECT_LIST.append(pwd_prompt_str)
b99885
+                    else:
b99885
+                        EXPECT_LIST.append(p)
b99885
+                        EXPECT_LIST.append(pwd_prompt_str)
b99885
+
b99885
                 try:
b99885
                     output.write(child.before)
b99885
+                    if log_output:
b99885
+                        log.debug(child.before)
b99885
                 except Exception:
b99885
                     pass
b99885
-                if log_output:
b99885
-                    try:
b99885
-                        log.debug(child.before)
b99885
-                    except Exception:
b99885
-                        pass
b99885
 
b99885
             if i == 0: # EOF
b99885
                 break
b99885
@@ -2018,7 +2033,7 @@ def download_from_network(weburl, outputFile = None, useURLLIB=False):
b99885
 
b99885
         if useURLLIB:
b99885
 		
b99885
-            sys.stdout.write("Download in progress..........")
b99885
+            #sys.stdout.write("Download in progress..........")
b99885
             try:
b99885
                 response = urllib2_request.urlopen(weburl)    
b99885
                 file_fd = open(outputFile, 'wb')
b99885
-- 
b99885
2.5.0
b99885