[PATCH rhel6-branch master 1/2] Move proxy parsing to AnacondaYumRepo (#604137)

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Make it possible to add proxy to AnacondaYumRepo objects from a
proxy string.

Related: rhbz#604137
---
 yuminstall.py |   90 ++++++++++++++++++++++++++++++++++-----------------------
 1 files changed, 54 insertions(+), 36 deletions(-)

diff --git a/yuminstall.py b/yuminstall.py
index 69519d3..f6264b7 100644
--- a/yuminstall.py
+++ b/yuminstall.py
@@ -159,6 +159,7 @@ class AnacondaCallback:
             po = txmbrs[0].po
 
             repo = self.repos.getRepo(po.repoid)
+            open("/tmp/yum-proxy.log","a").write("callback: %s %s\n"%(repo.name, repo.proxy))
 
             pkgStr = "%s-%s-%s.%s" % (po.name, po.version, po.release, po.arch)
             s = to_unicode(_("<b>Installing %(pkgStr)s</b> (%(size)s)\n")) \
@@ -294,6 +295,48 @@ class AnacondaYumRepo(YumRepository):
     anacondaBaseURLs = property(_getAnacondaBaseURLs, _setAnacondaBaseURLs,
                                 doc="Extends AnacondaYum.baseurl to store non-yum urls:")
 
+    def setProxyFromString(self, proxyString):
+        """
+        parse the proxy string and set proxy, username and password
+        """
+        # This is the same pattern as from loader/urls.c:splitProxyParam
+        # except that the POSIX classes have been replaced with character
+        # ranges
+        # NOTE: If this changes, update tests/regex/proxy.py
+        #
+        # proxy=[protocol://][username[:password]@]host[:port][path]
+        pattern = re.compile("([A-Za-z]+://)?(([A-Za-z0-9]+)(:[^:@]+)?@)?([^:/]+)(:[0-9]+)?(/.*)?")
+
+        m = pattern.match(proxyString)
+
+        if m and m.group(5):
+            # If both a host and port was found, just paste them
+            # together using the colon at the beginning of the port
+            # match as a separator.  Otherwise, just use the host.
+            if m.group(6):
+                proxy = m.group(5) + m.group(6)
+            else:
+                proxy = m.group(5)
+
+            # yum also requires a protocol.  If none was given,
+            # default to http.
+            if m.group(1):
+                proxy = m.group(1) + proxy
+            else:
+                proxy = "http://"; + proxy
+
+            # Set the repo proxy. NOTE: yum immediately parses this and
+            # raises an error if it isn't correct
+            self.proxy = proxy
+
+        if m and m.group(3):
+            self.proxy_username = m.group(3)
+
+        if m and m.group(4):
+            # Skip the leading colon.
+            self.proxy_password = m.group(4)[1:]
+
+
 class YumSorter(yum.YumBase):
     def _transactionDataFactory(self):
         return SplitMediaTransactionData()
@@ -528,6 +571,8 @@ class AnacondaYum(YumSorter):
                 log.info("set mediaid of repo %s to: %s" % (rid, repo.mediaid))
 
             repo.enable()
+            open("/tmp/yum-proxy.log","a").write("configBaseRepo: %s %s\n"%(repo.name, repo.proxy))
+            open("/tmp/yum-proxy.log","a").write(repo.dump())
             self.repos.add(repo)
 
     def mediaHandler(self, *args, **kwargs):
@@ -564,6 +609,8 @@ class AnacondaYum(YumSorter):
         repo = AnacondaYumRepo(section)
         repo.populate(parser, section, self.conf)
 
+        open("/tmp/yum-proxy.log","a").write("readRepoConfig %s %s\n"%(repo.name, repo.proxy))
+
         # Ensure that the repo name is set
         if not repo.name:
             repo.name = section
@@ -711,16 +758,10 @@ class AnacondaYum(YumSorter):
             repo.baseurl = [ "file://%s" % d ]
             repo.name = "Driver Disk %s" % dirname.split("-")[1]
             repo.enable()
+            open("/tmp/yum-proxy.log","a").write("DriverDisk %s %s\n"%(repo.name, repo.proxy))
             extraRepos.append(repo)
 
         if self.anaconda.isKickstart:
-            # This is the same pattern as from loader/urls.c:splitProxyParam except that
-            # the POSIX classes have been replaced with character ranges
-            # NOTE: If this changes, update tests/regex/proxy.py
-            #
-            # proxy=[protocol://][username[:password]@]host[:port][path]
-            pattern = re.compile("([A-Za-z]+://)?(([A-Za-z0-9]+)(:[^:@]+)?@)?([^:/]+)(:[0-9]+)?(/.*)?")
-
             for ksrepo in self.anaconda.id.ksdata.repo.repoList:
                 anacondaBaseURLs = [ksrepo.baseurl]
 
@@ -762,36 +803,10 @@ class AnacondaYum(YumSorter):
                     repo.includepkgs = ksrepo.includepkgs
 
                 if ksrepo.proxy:
-                    m = pattern.match(ksrepo.proxy)
-
-                    if m and m.group(5):
-                        # If both a host and port was found, just paste them
-                        # together using the colon at the beginning of the port
-                        # match as a separator.  Otherwise, just use the host.
-                        if m.group(6):
-                            proxy = m.group(5) + m.group(6)
-                        else:
-                            proxy = m.group(5)
-
-                        # yum also requires a protocol.  If none was given,
-                        # default to http.
-                        if m.group(1):
-                            proxy = m.group(1) + proxy
-                        else:
-                            proxy = "http://"; + proxy
-
-                        # Set the repo proxy. NOTE: yum immediately parses this and
-                        # raises an error if it isn't correct
-                        repo.proxy = proxy
-
-                    if m and m.group(3):
-                        repo.proxy_username = m.group(3)
-
-                    if m and m.group(4):
-                        # Skip the leading colon.
-                        repo.proxy_password = m.group(4)[1:]
+                    repo.setProxyFromString(ksrepo.proxy)
 
                 repo.enable()
+                open("/tmp/yum-proxy.log","a").write("ksrepo %s %s\n"%(repo.name, repo.proxy))
                 extraRepos.append(repo)
 
         initialRepos = self.repos.repos.values() + extraRepos
@@ -805,6 +820,7 @@ class AnacondaYum(YumSorter):
                 extraRepos.append(addonRepo)
 
         for repo in extraRepos:
+            open("/tmp/yum-proxy.log","a").write("extraRepos %s %s\n"%(repo.name, repo.proxy))
             try:
                 self.repos.add(repo)
                 log.info("added repository %s with URL %s" % (repo.name, repo.mirrorlist or repo.baseurl[0]))
@@ -1162,7 +1178,7 @@ pluginpath=/usr/lib/yum-plugins,/tmp/updates/yum-plugins
 pluginconfpath=/etc/yum/pluginconf.d,/tmp/updates/pluginconf.d
 plugins=1
 reposdir=/etc/anaconda.repos.d,/tmp/updates/anaconda.repos.d,/tmp/product/anaconda.repos.d
-debuglevel=10
+debuglevel=7
 """ % (anaconda.rootPath)
 
         if anaconda.proxy:
@@ -1281,6 +1297,7 @@ debuglevel=10
             repos = self.ayum.repos.listEnabled()
 
         for repo in repos:
+            open("/tmp/yum-proxy.log","a").write("FuncDo: %s repo.proxy=%s\n"%(repo.name, repo.proxy))
             if repo.name is None:
                 txt = _("Retrieving installation information.")
             else:
@@ -1291,6 +1308,7 @@ debuglevel=10
             while True:
                 try:
                     fn(repo)
+                    open("/tmp/yum-proxy.log","a").write("FuncDo2: %s repo.proxy=%s\n"%(repo.name, repo.proxy))
                     waitwin.pop()
                 except RepoError, e:
                     waitwin.pop()
-- 
1.7.0.1

_______________________________________________
Anaconda-devel-list mailing list
Anaconda-devel-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/anaconda-devel-list


[Index of Archives]     [Kickstart]     [Fedora Users]     [Fedora Legacy List]     [Fedora Maintainers]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]
  Powered by Linux