[yum-commits] Branch 'yum-3_2_X' - 4 commits - cli.py yum/__init__.py yum/misc.py yum/packages.py

James Antill james at osuosl.org
Mon Nov 16 21:28:00 UTC 2009


 cli.py          |   17 +++++++++++------
 yum/__init__.py |   15 ++++++++++-----
 yum/misc.py     |   11 +++++++++++
 yum/packages.py |   37 +++++++++++++++++++++++++++++++++++++
 4 files changed, 69 insertions(+), 11 deletions(-)

New commits:
commit b9fbe55eb7801beb161aa7abbf9f3eff1fcbd4e7
Author: James Antill <james at and.org>
Date:   Mon Nov 16 16:26:58 2009 -0500

    Allow HTTP:// as well as http://, and split the tests for re_remote_url

diff --git a/yum/misc.py b/yum/misc.py
index 1c8719b..642f9a2 100644
--- a/yum/misc.py
+++ b/yum/misc.py
@@ -127,8 +127,14 @@ def re_full_search_needed(s):
 
 def re_remote_url(s):
     """ Tests if a string is a "remote" URL, http, https, ftp. """
-    return (s.startswith("http://") or s.startswith("https://") or
-            s.startswith("ftp://"))
+    s = s.lower()
+    if s.startswith("http://"):
+        return True
+    if s.startswith("https://"):
+        return True
+    if s.startswith("ftp://"):
+        return True
+    return False
 
 ###########
 # Title: Remove duplicates from a sequence
diff --git a/yum/packages.py b/yum/packages.py
index 804db8b..e6d2167 100644
--- a/yum/packages.py
+++ b/yum/packages.py
@@ -1701,7 +1701,7 @@ class YumUrlPackage(YumLocalPackage):
        init takes a YumBase, a ts instance and a url to the package."""
 
     def __init__(self, yb=None, ts=None, url=None, ua=None):
-        if url.startswith("file:"):
+        if url.lower().startswith("file:"):
             result = url[len("file:"):]
         elif not misc.re_remote_url(url):
             result = url
commit 71f5a0625f64a9bec64c1eab1000cbb6bede510d
Author: James Antill <james at and.org>
Date:   Mon Nov 16 14:57:05 2009 -0500

    Have localInstall()/etc. use YumUrlPackage(), so we act more like rpm.

diff --git a/cli.py b/cli.py
index 16194e8..8c67d5d 100644
--- a/cli.py
+++ b/cli.py
@@ -590,7 +590,8 @@ class YumBaseCli(yum.YumBase, output.YumOutput):
         oldcount = len(self.tsInfo)
         
         for arg in userlist:
-            if arg.endswith('.rpm') and os.path.exists(arg): # this is hurky, deal w/it
+            if (arg.endswith('.rpm') and (yum.misc.re_remote_url(arg) or
+                                          os.path.exists(arg))):
                 self.localInstall(filelist=[arg])
                 continue # it was something on disk and it ended in rpm 
                          # no matter what we don't go looking at repos
@@ -623,7 +624,8 @@ class YumBaseCli(yum.YumBase, output.YumOutput):
             # pass them off to localInstall() and then move on
             localupdates = []
             for item in userlist:
-                if item.endswith('.rpm') and os.path.exists(item): # this is hurky, deal w/it
+                if (item.endswith('.rpm') and (yum.misc.re_remote_url(item) or
+                                               os.path.exists(item))):
                     localupdates.append(item)
             
             if len(localupdates) > 0:
@@ -667,7 +669,8 @@ class YumBaseCli(yum.YumBase, output.YumOutput):
         oldcount = len(self.tsInfo)
         
         for arg in userlist:
-            if arg.endswith('.rpm') and os.path.exists(arg):
+            if (arg.endswith('.rpm') and (yum.misc.re_remote_url(arg) or
+                                          os.path.exists(arg))):
                 self.downgradeLocal(arg)
                 continue # it was something on disk and it ended in rpm 
                          # no matter what we don't go looking at repos
@@ -691,7 +694,8 @@ class YumBaseCli(yum.YumBase, output.YumOutput):
         oldcount = len(self.tsInfo)
 
         for arg in userlist:
-            if arg.endswith('.rpm') and os.path.exists(arg):
+            if (arg.endswith('.rpm') and (yum.misc.re_remote_url(arg) or
+                                          os.path.exists(arg))):
                 self.reinstallLocal(arg)
                 continue # it was something on disk and it ended in rpm
                          # no matter what we don't go looking at repos
@@ -825,8 +829,9 @@ class YumBaseCli(yum.YumBase, output.YumOutput):
 
         pkgs = []
         for arg in args:
-            if arg.endswith('.rpm') and os.path.exists(arg): # this is hurky, deal w/it
-                thispkg = yum.packages.YumLocalPackage(self.ts, arg)
+            if (arg.endswith('.rpm') and (yum.misc.re_remote_url(arg) or
+                                          os.path.exists(arg))):
+                thispkg = yum.packages.YumUrlPackage(self, self.ts, arg)
                 pkgs.append(thispkg)
             else:                
                 ematch, match, unmatch = self.pkgSack.matchPackageNames([arg])
diff --git a/yum/__init__.py b/yum/__init__.py
index 90fefb0..35f599c 100644
--- a/yum/__init__.py
+++ b/yum/__init__.py
@@ -62,7 +62,9 @@ import yum.history
 import warnings
 warnings.simplefilter("ignore", Errors.YumFutureDeprecationWarning)
 
-from packages import parsePackages, YumAvailablePackage, YumLocalPackage, YumInstalledPackage, comparePoEVR
+from packages import parsePackages, comparePoEVR
+from packages import YumAvailablePackage, YumLocalPackage, YumInstalledPackage
+from packages import YumUrlPackage
 from constants import *
 from yum.rpmtrans import RPMTransaction,SimpleCliCallBack
 from yum.i18n import to_unicode, to_str
@@ -3250,9 +3252,10 @@ class YumBase(depsolve.Depsolve):
 
         if not po:
             try:
-                po = YumLocalPackage(ts=self.rpmdb.readOnlyTS(), filename=pkg)
+                po = YumUrlPackage(self, ts=self.rpmdb.readOnlyTS(), url=pkg,
+                                   ua=default_grabber.opts.user_agent)
             except Errors.MiscError:
-                self.logger.critical(_('Cannot open file: %s. Skipping.'), pkg)
+                self.logger.critical(_('Cannot open: %s. Skipping.'), pkg)
                 return tx_return
             self.verbose_logger.log(logginglevels.INFO_2,
                 _('Examining %s: %s'), po.localpath, po)
@@ -3348,7 +3351,8 @@ class YumBase(depsolve.Depsolve):
 
         if not po:
             try:
-                po = YumLocalPackage(ts=self.rpmdb.readOnlyTS(), filename=pkg)
+                po = YumUrlPackage(self, ts=self.rpmdb.readOnlyTS(), url=pkg,
+                                   ua=default_grabber.opts.user_agent)
             except Errors.MiscError:
                 self.logger.critical(_('Cannot open file: %s. Skipping.'), pkg)
                 return []
@@ -3431,7 +3435,8 @@ class YumBase(depsolve.Depsolve):
 
         if not po:
             try:
-                po = YumLocalPackage(ts=self.rpmdb.readOnlyTS(), filename=pkg)
+                po = YumUrlPackage(self, ts=self.rpmdb.readOnlyTS(), url=pkg,
+                                   ua=default_grabber.opts.user_agent)
             except Errors.MiscError:
                 self.logger.critical(_('Cannot open file: %s. Skipping.'), pkg)
                 return []
commit 11a0da56a23dc9d2d87c1578efadcb8cd7d72f37
Author: James Antill <james at and.org>
Date:   Mon Nov 16 14:55:04 2009 -0500

    Add YumUrlPackage(), to download packages and use YumLocalPackage on them

diff --git a/yum/packages.py b/yum/packages.py
index 3a14c85..804db8b 100644
--- a/yum/packages.py
+++ b/yum/packages.py
@@ -38,6 +38,7 @@ from constants import *
 
 import urlparse
 urlparse.uses_fragment.append("media")
+from urlgrabber.grabber import URLGrabber, URLGrabError
 
 # For verify
 import pwd
@@ -1693,3 +1694,39 @@ class YumLocalPackage(YumHeaderPackage):
         return msg
 
 
+class YumUrlPackage(YumLocalPackage):
+    """Class to handle an arbitrary package from a URL
+       this inherits most things from YumLocalPackage, but will download a
+       remote package to make it local.
+       init takes a YumBase, a ts instance and a url to the package."""
+
+    def __init__(self, yb=None, ts=None, url=None, ua=None):
+        if url.startswith("file:"):
+            result = url[len("file:"):]
+        elif not misc.re_remote_url(url):
+            result = url
+        else:
+            cb = None
+            pd = {}
+            for repo in yb.repos.listEnabled():
+                cb = repo.callback # Hacky, but these are "always" the same
+                if (repo.proxy == yb.conf.proxy and
+                    repo.proxy_username == yb.conf.proxy_username and
+                    repo.proxy_password == yb.conf.proxy_password):
+                    # Even more hacky...
+                    pd = repo.proxy_dict
+                    break
+            fname = os.path.basename(url)
+            local = "%s/%s" % (yb.conf.cachedir, fname)
+            try:
+                ug = URLGrabber(bandwidth = yb.conf.bandwidth,
+                                retry = yb.conf.retries,
+                                throttle = yb.conf.throttle,
+                                progress_obj = cb,
+                                proxies=pd)
+                if ua is not None:
+                    ug.opts.user_agent = ua
+                result = ug.urlgrab(url, local, text=fname)
+            except URLGrabError, e:
+                raise Errors.MiscError("Cannot download %s: %s" % (url, e))
+        YumLocalPackage.__init__(self, ts, result)
commit cc9924e89920650a8214438bf9ee00febbc51e9b
Author: James Antill <james at and.org>
Date:   Mon Nov 16 14:54:26 2009 -0500

    Add "re_remote_url()" for testing if a url is "remote"

diff --git a/yum/misc.py b/yum/misc.py
index efff267..1c8719b 100644
--- a/yum/misc.py
+++ b/yum/misc.py
@@ -125,6 +125,11 @@ def re_full_search_needed(s):
             return True
     return False
 
+def re_remote_url(s):
+    """ Tests if a string is a "remote" URL, http, https, ftp. """
+    return (s.startswith("http://") or s.startswith("https://") or
+            s.startswith("ftp://"))
+
 ###########
 # Title: Remove duplicates from a sequence
 # Submitter: Tim Peters 


More information about the Yum-commits mailing list