[Yum-devel] [PATCH] Add downloadonly option to userconfirm download prompt.

James Antill james at and.org
Tue Apr 23 13:57:46 UTC 2013


---
 cli.py          |   22 +++++++++++++++++++---
 output.py       |   45 +++++++++++++++++++++++++--------------------
 yum/__init__.py |    2 +-
 3 files changed, 45 insertions(+), 24 deletions(-)

diff --git a/cli.py b/cli.py
index ba2e343..c8a5554 100755
--- a/cli.py
+++ b/cli.py
@@ -529,6 +529,12 @@ class YumBaseCli(yum.YumBase, output.YumOutput):
            errors.  A negative return code indicates that errors
            occurred in the pre-transaction checks
         """
+        def _downloadonly_userconfirm(self):
+            return self.userconfirm(prompt=_('Is this ok [y/d/N]: '),
+                                    extra={'downloadonly' :
+                                           (u'd', _('d'), _('download'),
+                                            _('downloadonly'))})
+
         # just make sure there's not, well, nothing to do
         if len(self.tsInfo) == 0:
             self.verbose_logger.info(_('Trying to run the transaction but nothing to do. Exiting.'))
@@ -586,12 +592,22 @@ class YumBaseCli(yum.YumBase, output.YumOutput):
 
         # confirm with user
         if self._promptWanted():
-            if self.conf.assumeno or not self.userconfirm():
+            uc = None
+            if not self.conf.assumeno:
+                uc = _downloadonly_userconfirm(self)
+
+            if not uc:
                 self.verbose_logger.info(_('Exiting on user command'))
                 return -1
+            elif uc == 'downloadonly':
+                self.conf.downloadonly = True
 
-        self.verbose_logger.log(yum.logginglevels.INFO_2,
-            _('Downloading packages:'))
+        if self.conf.downloadonly:
+            self.verbose_logger.log(yum.logginglevels.INFO_2,
+                                    _('Background downloading packages, then exiting:'))
+        else:
+            self.verbose_logger.log(yum.logginglevels.INFO_2,
+                                    _('Downloading packages:'))
         problems = self.downloadPkgs(downloadpkgs, callback_total=self.download_callback_total_cb) 
 
         if len(problems) > 0:
diff --git a/output.py b/output.py
index 020e2b6..e17194c 100755
--- a/output.py
+++ b/output.py
@@ -958,20 +958,23 @@ class YumOutput:
                 return 1, ['No Packages to list']
             return 0, []
         
-    
-        
-    def userconfirm(self):
-        """Get a yes or no from the user, and default to No
+    def userconfirm(self, prompt=_('Is this ok [y/N]: '), extra={}):
+        """Get a yes or no from the user, and default to No, and maybe more.
 
-        :return: True if the user selects yes, and False if the user
-           selects no
+        :param extra: a dict of ui responses to a list of their inputs.
+        :return: the UI response or None for no. At it's simplest this is 'yes' or None
         """
-        yui = (to_unicode(_('y')), to_unicode(_('yes')))
-        nui = (to_unicode(_('n')), to_unicode(_('no')))
-        aui = (yui[0], yui[1], nui[0], nui[1])
+
+        # Allow the one letter english versions in all langs.
+        yui = (u'y', to_unicode(_('y')), to_unicode(_('yes')))
+        nui = (u'n', to_unicode(_('n')), to_unicode(_('no')))
+        aui = set(yui + nui)
+        for xui in extra:
+            aui.update(extra[xui])
+
         while True:
             try:
-                choice = raw_input(_('Is this ok [y/N]: '))
+                choice = raw_input(prompt)
             except UnicodeEncodeError:
                 raise
             except UnicodeDecodeError:
@@ -982,17 +985,19 @@ class YumOutput:
             choice = choice.lower()
             if len(choice) == 0 or choice in aui:
                 break
-            # If the enlish one letter names don't mix, allow them too
-            if u'y' not in aui and u'y' == choice:
-                choice = yui[0]
-                break
-            if u'n' not in aui and u'n' == choice:
-                break
 
-        if len(choice) == 0 or choice not in yui:
-            return False
-        else:            
-            return True
+        if not choice:
+            # Default, maybe configure this?
+            #  Would need to never allow default=yes as that's really bad.
+            return None
+
+        if choice in yui:
+            return 'yes'
+        for xui in extra:
+            if choice in extra[xui]:
+                return xui
+
+        return None
     
     def _cli_confirm_gpg_key_import(self, keydict):
         # FIXME what should we be printing here?
diff --git a/yum/__init__.py b/yum/__init__.py
index 766f960..543ca2d 100644
--- a/yum/__init__.py
+++ b/yum/__init__.py
@@ -2423,7 +2423,7 @@ much more problems).
             urlgrabber.grabber.reset_curl_obj()
 
         if downloadonly and not errors: # caller handles errors
-            self.verbose_logger.info(_('exiting because --downloadonly specified'))
+            self.verbose_logger.info(_('exiting because "Download Only" specified'))
             sys.exit(self.exit_code)
         return errors
 
-- 
1.7.7.6



More information about the Yum-devel mailing list