[PATCH 02/10] Add new class to hold specifications of repositories.

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

 



The class is called RepoSpec. It should be backend independent, so perhaps it
will be moved to backend.py or even (new) repos.py.  It will be used instead of
working directly (e.g. in UI steps) with extended YumRepository objects
(AnacondaYumRepository) making going back in UI possible without hacks (by
using new YumBackend object).

Compared to YumRepository, it can hold anconda specific urls (nfs, cdrom,
nfsiso), repository type (method, kickstart, UI, driver disk, addon),
and info about setup status and cause of fail.
---
 pyanaconda/__init__.py   |    1 +
 pyanaconda/yuminstall.py |  207 +++++++++++++++++++++++++++++++++++-----------
 2 files changed, 158 insertions(+), 50 deletions(-)

diff --git a/pyanaconda/__init__.py b/pyanaconda/__init__.py
index 5c07edc..9d94519 100644
--- a/pyanaconda/__init__.py
+++ b/pyanaconda/__init__.py
@@ -86,6 +86,7 @@ class Anaconda(object):
         self.upgradeSwapInfo = None
         self._users = None
         self.mehConfig = None
+        self.repos = []
 
         # *sigh* we still need to be able to write this out
         self.xdriver = None
diff --git a/pyanaconda/yuminstall.py b/pyanaconda/yuminstall.py
index 11f014a..a7e5385 100644
--- a/pyanaconda/yuminstall.py
+++ b/pyanaconda/yuminstall.py
@@ -91,6 +91,159 @@ def size_string (size):
 
     return to_unicode(retval)
 
+
+# TODORV: move into a module?
+class RepoSpec(object):
+
+    def __init__(self):
+        self.url = ""
+        self.mirrorlist = False
+        self.name = ""
+        self.cost = None
+        self.excludepkgs = []
+        self.includepkgs = []
+        self.proxy = ""
+        self.proxy_username = ""
+        self.proxy_password = ""
+        self.ignoregroups = None
+        self.sslverify = True
+        self.baseurl = ""
+        self.mediaid = None
+        self.media_device = None
+
+        self.enabled = False
+
+        self.setup = "?"
+        self.setup_fail_comment = ""
+
+        self.addon_repos = None
+
+        # this should ideally go away, maybe use inheritance
+        self.type = ""
+
+    @property
+    def id(self):
+        id = "%s-%s" % (self.type, self.name.replace(" ", ""))
+        if self.type == "method":
+            id += "-%s" % productStamp
+        return id
+
+
+    # TODORV: remove from AnacondaYumRepo?
+    def needsNetwork(self):
+        return (self.url.startswith("http") or
+                self.url.startswith("ftp:") or
+                self.url.startswith("nfs:") or
+                self.url.startswith("nfsiso:"))
+
+    def isIsoRepo(self):
+        return (self.url.startswith("cdrom:") or
+                self.url.startswith("hd:") or
+            self.url.startswith("nfsiso:"))
+
+    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 YumRepoSpec(RepoSpec):
+    def __init__(self, yumrepo=None):
+        RepoSpec.__init__(self)
+        self.yumrepo = yumrepo
+        if yumrepo:
+            self.initFromYumRepo(yumrepo)
+
+    def initYumRepo(self, yumrepo):
+        if self.mirrorlist:
+            yumrepo.mirrorlist = self.url
+        else:
+            yumrepo.baseurl = self.baseurl
+        yumrepo.name = self.name
+        if self.cost is not None:
+            yumrepo.cost = self.cost
+        if self.excludepkgs:
+            yumrepo.exclude = self.excludepkgs
+        if self.includepkgs:
+            yumrepo.includepkgs = self.includepkgs
+        if self.sslverify is not None:
+            yumrepo.sslverify = self.sslverify
+        if self.mediaid is not None:
+            yumrepo.mediaid = self.mediaid
+        if self.proxy:
+            yumrepo.proxy = self.proxy
+        if self.proxy_username:
+            yumrepo.proxy_username = self.proxy_username
+        if self.proxy_password:
+            yumrepo.proxy_password = self.proxy_password
+
+
+    def initFromYumRepo(self, yumrepo):
+        if self.baseurl:
+            self.url = yumrepo.baseurl[0]
+        else:
+            self.url = yumrepo.mirrorlist
+            self.mirrorlist = True
+        self.name = yumrepo.name
+        self.cost = yumrepo.cost
+        self.excludepkgs = yumrepo.exclude
+        self.includepkgs = yumrepo.includepkgs
+        self.proxy = yumrepo.proxy
+        self.proxy_username = yumrepo.proxy_username
+        self.proxy_password = yumrepo.proxy_password
+        self.sslverify = yumrepo.sslverify
+        self.enabled = yumrepo.enabled
+        self.mediaid = yumrepo.mediaid
+
+def isValidRepoURL(url):
+    return (url.startswith("hd:") or
+            url.startswith("nfsiso:") or
+            url.startswith("http:") or
+            url.startswith("ftp:") or
+            url.startswith("cdrom:") or
+            url.startswith("nfs:"))
+
 class AnacondaCallback:
 
     def __init__(self, ayum, anaconda, instLog, modeText):
@@ -300,53 +453,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):
@@ -1895,9 +2001,10 @@ reposdir=/etc/anaconda.repos.d,/tmp/updates/anaconda.repos.d,/tmp/product/anacon
                 rc = True
         return rc
 
-    def writeKS(self, f):
-        for repo in self.ayum.repos.listEnabled():
-            if repo.name == "Installation Repo":
+    def writeKS(self, f, repos):
+        for repo in repos:
+            if (repo.type not in ["kickstart", "UI"] or
+                not repo.enabled):
                 continue
 
             line = "repo --name=\"%s\" " % (repo.name or repo.repoid)
-- 
1.7.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