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

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

 



NOTE: Revised to remove debugging output

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

Related: rhbz#604137
---
 yuminstall.py |   78 +++++++++++++++++++++++++++++++-------------------------
 1 files changed, 43 insertions(+), 35 deletions(-)

diff --git a/yuminstall.py b/yuminstall.py
index 69519d3..07e9501 100644
--- a/yuminstall.py
+++ b/yuminstall.py
@@ -294,6 +294,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()
@@ -714,13 +756,6 @@ class AnacondaYum(YumSorter):
             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,34 +797,7 @@ 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()
                 extraRepos.append(repo)
-- 
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