[Yum-devel] [PATCH] Add downloadonly to the userconfirm for downloads.

James Antill james at and.org
Mon Apr 22 21:34:00 UTC 2013


---
 cli.py          |   14 +++++++++++++-
 output.py       |   47 +++++++++++++++++++++++++++++++++++++++++++++++
 yum/__init__.py |    2 +-
 3 files changed, 61 insertions(+), 2 deletions(-)

diff --git a/cli.py b/cli.py
index ba2e343..acaecba 100755
--- a/cli.py
+++ b/cli.py
@@ -529,6 +529,11 @@ class YumBaseCli(yum.YumBase, output.YumOutput):
            errors.  A negative return code indicates that errors
            occurred in the pre-transaction checks
         """
+        def _downloadonly_userconfirm(self):
+            if hasattr(self, 'downloadonly_userconfirm'):
+                return self.downloadonly_userconfirm()
+            return self.userconfirm()
+
         # 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,9 +591,16 @@ 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.info(_('Will exit after downloads are complete'))
 
         self.verbose_logger.log(yum.logginglevels.INFO_2,
             _('Downloading packages:'))
diff --git a/output.py b/output.py
index 020e2b6..060a804 100755
--- a/output.py
+++ b/output.py
@@ -994,6 +994,53 @@ class YumOutput:
         else:            
             return True
     
+    def downloadonly_userconfirm(self):
+        """Get a yes or no or downloadonly from the user, and default to No
+
+        :return: True if the user selects yes, and False if the user
+           selects no
+        """
+        dui = (to_unicode(_('d')), to_unicode(_('download')),
+               to_unicode(_('downloadonly')))
+        yui = (to_unicode(_('y')), to_unicode(_('yes')))
+        nui = (to_unicode(_('n')), to_unicode(_('no')))
+        aui = (dui[0], dui[1], dui[2], yui[0], yui[1], nui[0], nui[1])
+        while True:
+            try:
+                choice = raw_input(_('Is this ok [y/d/N]: '))
+            except UnicodeEncodeError:
+                raise
+            except UnicodeDecodeError:
+                raise
+            except:
+                choice = ''
+            choice = to_unicode(choice)
+            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'd' not in aui and u'd' == choice:
+                choice = dui[0]
+                break
+            if u'n' not in aui and u'n' == choice:
+                break
+
+        if not choice:
+            # Default, maybe configure this for downloadonly ?
+            #  Would need to change above prompt, but also never allow
+            # default=yes as that's really bad.
+            return None
+
+        if choice in dui:
+            return 'downloadonly'
+        if choice in yui:
+            return 'yes'
+
+        return None
+
     def _cli_confirm_gpg_key_import(self, keydict):
         # FIXME what should we be printing here?
         return self.userconfirm()
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