[PATCH rhel6 1/3] Move setProxy to AnacondaYum (#634655)

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

 



Move setProxy over to AnacondaYum so that it can be used for repos
and for setting up proxy info for the initial grab of .treeinfo

Related: rhbz#634655
---
 yuminstall.py |  131 +++++++++++++++++++++++++++++++++------------------------
 1 files changed, 76 insertions(+), 55 deletions(-)

diff --git a/yuminstall.py b/yuminstall.py
index 6a55273..9c8c210 100644
--- a/yuminstall.py
+++ b/yuminstall.py
@@ -294,54 +294,6 @@ class AnacondaYumRepo(YumRepository):
     anacondaBaseURLs = property(_getAnacondaBaseURLs, _setAnacondaBaseURLs,
                                 doc="Extends AnacondaYum.baseurl to store non-yum urls:")
 
-    def setProxy(self, obj):
-        """
-        Set the proxy settings from a string in obj.proxy
-        If the string includes un/pw use those, otherwise set the un/pw from
-        obj.proxyUsername and obj.proxyPassword
-        """
-        # 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(obj.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
-            self.proxy = proxy
-
-        if m and m.group(3):
-            self.proxy_username = m.group(3)
-        elif getattr(obj, "proxyUsername", None):
-            self.proxy_username = obj.proxyUsername
-
-        if m and m.group(4):
-            # Skip the leading colon.
-            self.proxy_password = m.group(4)[1:]
-        elif getattr(obj, "proxyPassword", None):
-            self.proxy_password = obj.proxyPassword
-
-
 class YumSorter(yum.YumBase):
     def _transactionDataFactory(self):
         return SplitMediaTransactionData()
@@ -383,6 +335,14 @@ class AnacondaYum(YumSorter):
         self.updates = []
         self.localPackages = []
 
+        # Parse proxy values from anaconda
+        self.proxy = None
+        self.proxy_url = None
+        self.proxy_username = None
+        self.proxy_password = None
+        if self.anaconda.proxy:
+            self.setProxy(self.anaconda, self)
+
     def setup(self):
         # yum doesn't understand all our method URLs, so use this for all
         # except FTP and HTTP installs.
@@ -577,7 +537,7 @@ class AnacondaYum(YumSorter):
                 log.info("set mediaid of repo %s to: %s" % (rid, repo.mediaid))
 
             if self.anaconda.proxy:
-                repo.setProxy(self.anaconda)
+                self.setProxy(self.anaconda, repo)
 
             repo.enable()
             self.repos.add(repo)
@@ -649,9 +609,70 @@ class AnacondaYum(YumSorter):
 
         return repo
 
-    # Given the baseurl for a repository, see if it has any valid addon repos and
-    # if so, return a list of (repo name, repo URL).
-    def _getAddons(self, baseurl):
+    def setProxy(self, src, dest):
+        """
+        Set the proxy settings from a string in src.proxy
+        If the string includes un/pw use those, otherwise set the un/pw from
+        src.proxyUsername and src.proxyPassword
+
+        dest has dest.proxy set to the host and port (no un/pw)
+        dest.proxy_username and dest.proxy_password are set if present in src
+        """
+        # 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(src.proxy)
+
+        if m and m.group(3):
+            dest.proxy_username = m.group(3)
+        elif getattr(src, "proxyUsername", None):
+            dest.proxy_username = src.proxyUsername
+
+        if m and m.group(4):
+            # Skip the leading colon.
+            dest.proxy_password = m.group(4)[1:]
+        elif getattr(src, "proxyPassword", None):
+            dest.proxy_password = src.proxyPassword
+
+        if dest.proxy_username or dest.proxy_password:
+            proxy_auth = "%s:%s@" % (dest.proxy_username or '',
+                                     dest.proxy_password or '')
+        else:
+            proxy_auth = ""
+
+        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):
+                dest.proxy_url = m.group(1) + proxy_auth + proxy
+                proxy = m.group(1) + proxy
+            else:
+                dest.proxy_url = "http://"; + proxy_auth + proxy
+                proxy = "http://"; + proxy
+
+            # Set the repo proxy. NOTE: yum immediately parses this and
+            # raises an error if it isn't correct
+            dest.proxy = proxy
+
+    def _getAddons(self, repo):
+        """
+        Check the baseurl or mirrorlist for a repository, see if it has any
+        valid addon repos and if so, return a list of (repo name, repo URL).
+        """
+        baseurl = repo.mirrorlist or repo.baseurl[0]
         retval = []
         c = ConfigParser()
 
@@ -819,21 +840,21 @@ class AnacondaYum(YumSorter):
                     repo.includepkgs = ksrepo.includepkgs
 
                 if ksrepo.proxy:
-                    repo.setProxy(ksrepo)
+                    self.setProxy(ksrepo, repo)
 
                 repo.enable()
                 extraRepos.append(repo)
 
         initialRepos = self.repos.repos.values() + extraRepos
         for repo in initialRepos:
-            addons = self._getAddons(repo.mirrorlist or repo.baseurl[0])
+            addons = self._getAddons(repo)
             for addon in addons:
                 addonRepo = AnacondaYumRepo(addon[0])
                 addonRepo.name = addon[1]
                 addonRepo.baseurl = [ addon[2] ]
 
                 if self.anaconda.proxy:
-                    addonRepo.setProxy(self.anaconda)
+                    self.setProxy(self.anaconda, addonRepo)
 
                 extraRepos.append(addonRepo)
 
-- 
1.7.3.2

_______________________________________________
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