[Yum-devel] [PATCH] Some UI stuff

Terje Rosten terje.rosten at ntnu.no
Tue Jan 11 18:55:41 UTC 2005


This patch fixes some small things in the cli ui.

  * import readline (if available) to give a nicer raw_input()
  * loop in userconfirm() untill user answer Y/Yes or N/No
  * listing 'Setting up repos' a bit nicer
  * fix this item in TODO:
   - download package callback - right now yum downloads packages but
   it doesn't give you an idea of how many it has left to download -
   this should be added - this is about a 10 minute job :)

   (I used slightly more than 10 minutes :-)

The patch need the text field patch to urlgrabber.

Screenshot:

$ yum install xemacs

 Setting up Install Process
 Setting up Repos
 fedora-updates            100% |=========================|  951 B    00:00     
 fedora-extra              100% |=========================|  951 B    00:00     
 fedora-os                 100% |=========================| 1.0 kB    00:00     
 fedora-optional           100% |=========================|  951 B    00:00     
 Reading repository metadata in from local files
 fedora-upd: ################################################## 482/482
 fedora-ext: ################################################## 62/62
 fedora-os : ################################################## 1689/1689
 fedora-opt: ################################################## 7/7
 Resolving Dependencies
 --> Populating transaction set with selected packages. Please wait.
 ---> Package xemacs.i386 0:21.4.15-9 set to be installed
 --> Running transaction check

 [snip]

   Install: Canna-libs.i386 0:3.7p3-6
   Install: FreeWnn-libs.i386 1:1.10pl020-5
   Install: apel-xemacs.noarch 0:10.6-5
   Install: xemacs-common.i386 0:21.4.15-9
   Install: xemacs-sumo.noarch 0:20040818-2
 Is this ok [y/N]: Y
 Downloading Packages:
 (1/3): xemacs-21.4.15-9.i 100% |=========================| 1.9 MB    00:00     
 (2/3): xemacs-sumo-200408 100% |=========================|  19 MB    00:02     
 (3/3): xemacs-common-21.4 100% |=========================| 3.3 MB    00:00     
 Running Transaction Test

 [snip]

 Installed: xemacs.i386 0:21.4.15-9
 Dependency Installed: Canna-libs.i386 0:3.7p3-6 FreeWnn-libs.i386
 1:1.10pl020-5 apel-xemacs.noarch 0:10.6-5 xemacs-common.i386
 0:21.4.15-9 xemacs-sumo.noarch 0:20040818-2

 Complete!

 - Terje

Index: cli.py
===================================================================
RCS file: /cvsroot/yum/cvs/yum/cli.py,v
retrieving revision 1.135
diff -u -r1.135 cli.py
--- cli.py	11 Jan 2005 03:52:23 -0000	1.135
+++ cli.py	11 Jan 2005 18:53:45 -0000
@@ -57,11 +57,10 @@
     def doRepoSetup(self, nosack=None):
         """grabs the repomd.xml for each enabled repository and sets up the basics
            of the repository"""
-           
+        self.log(2, 'Setting up Repos')           
         for repo in self.repos.listEnabled():
             if repo.repoXML is not None:
                 continue
-            self.log(2, 'Setting up Repo:  %s' % repo)
             try:
                 repo.check()
                 repo.cache = self.conf.getConfigOption('cache')
@@ -71,7 +70,7 @@
                 self.errorlog(0, '%s' % e)
                 sys.exit(1)
             try:
-                repo.getRepoXML()
+                repo.getRepoXML(text=repo)
             except yum.Errors.RepoError, e:
                 self.errorlog(0, 'Cannot open/read repomd.xml file for repository: %s' % repo)
                 self.errorlog(0, str(e))
Index: output.py
===================================================================
RCS file: /cvsroot/yum/cvs/yum/output.py,v
retrieving revision 1.41
diff -u -r1.41 output.py
--- output.py	14 Dec 2004 07:24:23 -0000	1.41
+++ output.py	11 Jan 2005 18:53:45 -0000
@@ -24,6 +24,11 @@
 from i18n import _
 import libxml2
 
+try:
+    import readline
+except:
+    pass
+
 import yum.Errors
 
 class YumOutput:
@@ -234,14 +239,16 @@
         
     def userconfirm(self):
         """gets a yes or no from the user, defaults to No"""
-        choice = raw_input('Is this ok [y/N]: ')
-        if len(choice) == 0:
+
+        while 1:            
+            choice = raw_input('Is this ok [y/N]: ')
+            if len(choice) == 0 or choice[0] in ['Y', 'y', 'N','n']:
+                break
+
+        if len(choice) == 0 or choice[0] not in ['y', 'Y']:
             return 0
-        else:
-            if choice[0] != 'y' and choice[0] != 'Y':
-                return 0
-            else:
-                return 1
+        else:            
+            return 1
                 
     
     def displayPkgsInGroups(self, group):
Index: yum/__init__.py
===================================================================
RCS file: /cvsroot/yum/cvs/yum/yum/__init__.py,v
retrieving revision 1.73
diff -u -r1.73 __init__.py
--- yum/__init__.py	11 Jan 2005 03:52:23 -0000	1.73
+++ yum/__init__.py	11 Jan 2005 18:53:45 -0000
@@ -402,7 +402,7 @@
         """download list of package objects handed to you, output based on
            callback, raise yum.Errors.YumBaseError on problems"""
 
-        errors = {}
+        remote_pkgs = []
         for po in pkglist:
             if hasattr(po, 'pkgtype') and po.pkgtype == 'local':
                 continue
@@ -418,13 +418,24 @@
                         continue
                     else:
                         os.unlink(local)
+            remote_pkgs.append(po)
 
+        errors = {}
+        i = 0
+        for po in remote_pkgs:
+            i += 1
             repo = self.repos.getRepo(po.repoid)
             remote = po.returnSimple('relativepath')
             checkfunc = (self.verifyPkg, (po, 1), {})
 
             try:
-                mylocal = repo.get(relative=remote, local=local, checkfunc=checkfunc)
+                text = '(%s/%s): %s' % (i, len(remote_pkgs),
+                                        os.path.basename(remote))
+                local = po.localPkg()
+                mylocal = repo.get(relative=remote,
+                                   local=local,
+                                   checkfunc=checkfunc,
+                                   text=text)
             except Errors.RepoError, e:
                 if not errors.has_key(po):
                     errors[po] = []
Index: yum/repos.py
===================================================================
RCS file: /cvsroot/yum/cvs/yum/yum/repos.py,v
retrieving revision 1.53
diff -u -r1.53 repos.py
--- yum/repos.py	30 Nov 2004 06:54:37 -0000	1.53
+++ yum/repos.py	11 Jan 2005 18:53:45 -0000
@@ -390,7 +390,7 @@
  
 
     def get(self, url=None, relative=None, local=None, start=None, end=None,
-            copy_local=0, checkfunc=None):
+            copy_local=0, checkfunc=None, text=None):
         """retrieve file from the mirrorgroup for the repo
            relative to local, optionally get range from
            start to end, also optionally retrieve from a specific baseurl"""
@@ -416,7 +416,7 @@
                 raise Errors.RepoError, \
                     "Caching enabled but no local cache of %s from %s" % (local,
                            self)
-        
+
         if url is not None:
             ug = URLGrabber(keepalive = self.keepalive, 
                             bandwidth = self.bandwidth,
@@ -432,19 +432,23 @@
 
             try:
                 result = ug.urlgrab(remote, local,
+                                    text = text,
                                     range = (start, end), 
                                     retry = self.retries,
                                     copy_local = copy_local,
                                     failure_callback = self.failure_obj,
                                     timeout = self.timeout,
                                     checkfunc = checkfunc)
+                                    
             except URLGrabError, e:
                 raise Errors.RepoError, \
                     "failed to retrieve %s from %s\nerror was %s" % (relative, self.id, e)
               
         else:
             try:
-                result = self.grab.urlgrab(relative, local, range=(start, end),
+                result = self.grab.urlgrab(relative, local,
+                                           text = text,
+                                           range = (start, end),
                                            copy_local=copy_local,
                                            checkfunc=checkfunc)
             except URLGrabError, e:
@@ -453,7 +457,7 @@
         return result
            
         
-    def getRepoXML(self):
+    def getRepoXML(self, text=None):
         """retrieve/check/read in repomd.xml from the repository"""
 
         remote = self.repoMDFile
@@ -468,7 +472,8 @@
                 result = local
         else:
             try:
-                result = self.get(relative=remote, local=local, copy_local=1)
+                result = self.get(relative=remote, local=local,
+                                  copy_local=1, text=text)
             except URLGrabError, e:
                 raise Errors.RepoError, 'Error downloading file %s: %s' % (local, e)
 


 



More information about the Yum-devel mailing list