Exemple #1
0
 def searchPkgs(self, names):
     """Return a list of RpmPackage's from pkgs matching pkgnames.
     pkgnames is a list of names, each name can contain epoch, version,
     release and arch. If the name doesn't match literally, it is
     interpreted as a glob pattern. The resulting list contains all matches
     in arbitrary order, and it may contain a single package more than
     once."""
     result = []
     pkgnames = None
     for name in names:
         parts = self.__splitre__.split(name)
         if self.__fnmatchre__.match(name):
             regex = re.compile(fnmatch.translate(name))
             if pkgnames is None:
                 pkgnames = self.getNames()
             for pkgname in pkgnames:
                 if pkgname.startswith(parts[0]):
                     pkgs = self.getPkgsByName(pkgname)
                     for pkg in pkgs:
                         for n in pkg.getAllNames():
                             if regex.match(n):
                                 result.append(pkg)
                                 break
         else:
             for idx in xrange(1, len(parts)+1, 2):
                 pkgs = self.getPkgsByName(''.join(parts[:idx]))
                 for pkg in pkgs:
                     for n in pkg.getAllNames():
                         if n == name:
                             result.append(pkg)
                             break
     functions.normalizeList(result)
     return result
Exemple #2
0
 def search(self, pkgnames):
     result = []
     hash = self.hash
     for pkgname in pkgnames:
         if hash.has_key(pkgname):
             result.extend(hash[pkgname])
         if self._fnmatchre.match(pkgname):
             restring = fnmatch.translate(pkgname)
             regex = re.compile(restring)
             for item in hash.keys():
                 if regex.match(item):
                     result.extend(hash[item])
     functions.normalizeList(result)
     return result
Exemple #3
0
 def search(self, pkgnames):
     result = []
     hash = self.hash
     for pkgname in pkgnames:
         if hash.has_key(pkgname):
             result.extend(hash[pkgname])
         if self._fnmatchre.match(pkgname):
             restring = fnmatch.translate(pkgname)
             regex = re.compile(restring)
             for item in hash.keys():
                 if regex.match(item):
                     result.extend(hash[item])
     functions.normalizeList(result)
     return result
Exemple #4
0
    def getPackages(self, ks, languages, all_comps, has_raid, fstypes):
        groups = [ ]
        pkgs = [ ]
        everything = False
        if ks.has_key("packages") and \
               ks["packages"].has_key("groups") and \
               len(ks["packages"]["groups"]) > 0:
            groups = ks["packages"]["groups"]

        # add default group "base" and "core if it is not in groups and
        # nobase is not set
        if not ks.has_key("packages") or not ks["packages"].has_key("nobase"):
            if not "base" in groups:
                groups.append("base")
            if not "core" in groups:
                groups.append("core")

        if all_comps:
            repos = self.repos.keys()
        else:
            repos = self.base_repo_names

        if "everything" in groups:
            for repo in repos:
                for group in self.repos[repo].comps.getGroups():
                    if not group in groups:
                        groups.append(group)
            groups.remove("everything")
            everything = True

        if ks.has_key("packages") and ks["packages"].has_key("add") and \
               "*" in ks["packages"]["add"]:
            # add all packages
            for repo in self.repos.keys():
                pkgs.extend(self.repos[repo].getNames())
        else:
            # add default desktop
            if ks.has_key("xconfig"):
                if ks["xconfig"].has_key("startxonboot"):
                    if not "base-x" in groups:
                        log.info1("Adding group 'base-x'.")
                        groups.append("base-x")
                    desktop = "GNOME"
                    if ks["xconfig"].has_key("defaultdesktop"):
                        desktop = ks["xconfig"]["defaultdesktop"]
                    desktop = "%s-desktop" % desktop.lower()
                    if not desktop in groups:
                        log.info1("Adding group '%s'.", desktop)
                        groups.append(desktop)

            normalizeList(groups)

            # test if groups are available
            repo_groups = { }
            for group in groups:
                found = False
                for repo in repos:
                    if not self.repos[repo].comps:
                        continue
                    _group = self.repos[repo].comps.getGroup(group)
                    if not _group:
                        continue
                    found = True
                    if not _group in repo_groups.keys() or \
                           not repo in repo_groups[_group]:
                        repo_groups.setdefault(_group, [ ]).append(repo)
                if not found:
                    log.warning("Group '%s' does not exist.", group)
            del groups

            # add packages for groups
            for group in repo_groups:
                for repo in repo_groups[group]:
                    comps = self.repos[repo].comps
                    for pkg in comps.getPackageNames(group):
                        if len(self.repos[repo].searchPkgs([pkg])) > 0:
                            if not pkg in pkgs:
                                pkgs.append(pkg)
                    if everything:
                        # add all packages in this group
                        for (pkg, req) in \
                                comps.getConditionalPackageNames(group):
                            if len(self.repos[repo].searchPkgs([pkg])) > 0:
                                if not pkg in pkgs:
                                    pkgs.append(pkg)
            del repo_groups

        # add packages
        if ks.has_key("packages") and ks["packages"].has_key("add"):
            for name in ks["packages"]["add"]:
                if name == "*":
                    continue
                found = False
                for repo in self.repos.keys():
                    _pkgs = self.repos[repo].searchPkgs([name])
                    if len(_pkgs) > 0:
                        # silently add package
                        if not name in pkgs:
                            pkgs.append(name)
                        found = True
                        break
                if not found:
                    log.warning("Package '%s' is not available.", pkg)

        # remove packages
        if ks.has_key("packages") and ks["packages"].has_key("drop"):
            for pkg in ks["packages"]["drop"]:
                if pkg in pkgs:
                    log.info1("Removing package '%s'.", pkg)
                    pkgs.remove(pkg)

        # add xorg driver package for past FC-5, RHEL-4
        if ks.has_key("xconfig"):
            if (self.isRHEL() and self.cmpVersion("4.9") > 0) or \
                   (self.isFedora() and self.cmpVersion("4") > 0):
                if ks["xconfig"].has_key("driver"):
                    self._addPkg("xorg-x11-drv-%s" % ks["xconfig"]["driver"],
                                 pkgs)
                else:
                    if not "xorg-x11-drivers" in pkgs:
                        self._addPkg("xorg-x11-drivers", pkgs)

        # add packages for needed filesystem types
        for fstype in fstypes:
            if fstype == "swap":
                continue
            self._addPkgByFilename("/sbin/mkfs.%s" % fstype, pkgs,
                                   "%s filesystem creation" % fstype)

        # add comps package
        if not "comps" in pkgs:
            try:
                self._addPkg("comps", pkgs)
            except:
                # ignore missing comps package
                pass

        # append mdadm
        if has_raid:
            self._addPkgByFilename("/sbin/mdadm", pkgs, "raid configuration")

        # append authconfig
        if ks.has_key("authconfig"):
            self._addPkgByFilename("/usr/sbin/authconfig", pkgs,
                                   "authentication configuration")

        # append iptables and config tool
        if ks.has_key("firewall") and \
               not ks["firewall"].has_key("disabled"):
            self._addPkg("iptables", pkgs)

        # no firewall config tool in RHEL-3
        if (self.isRHEL() and self.cmpVersion("4") >= 0) or \
               (self.isFedora() and self.cmpVersion("3") >= 0):
            self._addPkgByFilename("/usr/sbin/lokkit", pkgs,
                                   "firewall configuration")

        # append lokkit
        if ks.has_key("selinux") and \
               ((self.isRHEL() and self.cmpVersion("4") >= 0) or \
                (self.isFedora() and self.cmpVersion("3") >= 0)):
            self._addPkgByFilename("/usr/sbin/lokkit", pkgs,
                                   "selinux configuration")

        # append kernel
        if not "kernel" in pkgs and not "kernel-smp" in pkgs:
            self._addPkg("kernel", pkgs)

        # append kernel-devel for FC-6 and RHEL-5
        if "gcc" in pkgs and \
               ((self.isRHEL() and self.cmpVersion("5") >= 0 and \
                 (self.getVariant() != "Client" or \
                  "%s-Workstation" % (self.release) in self.repos.keys())) or \
                (self.isFedora() and self.cmpVersion("6") >= 0)):
            if "kernel" in pkgs:
                self._addPkg("kernel-devel", pkgs)
            elif "kernel-smp" in pkgs:
                self._addPkg("kernel-smp-devel", pkgs)

        # append firstboot
        if ks.has_key("firstboot") and \
               not ks["firstboot"].has_key("disabled"):
            self._addPkg("firstboot", pkgs)

        # append dhclient
        if ks.has_key("bootloader"):
            self._addPkg("grub", pkgs)
#            if self.getArch() == "ia64":
#                self._addPkg("elilo", pkgs)
#            elif self.getArch in [ "s390", "s390x" ]:
#                self._addPkg("s390utils", pkgs)
#            elif self.getArch() in [ "ppc", "ppc64" ]:
#                self._addPkg("yaboot", pkgs)
#            else:
#                self._addPkg("grub", pkgs)

        # append grub
        if ks.has_key("network") and len(ks["network"]) > 0:
            for net in ks["network"]:
                if net["bootproto"] == "dhcp":
                    self._addPkg("dhclient", pkgs)

        # languages (pre FC-6 and pre RHEL-5)
        if len(languages) > 0:
            for repo in repos:
                _repo = self.repos[repo]
                if not _repo.comps:
                    continue
                for group in _repo.comps.grouphash.keys():
                    self._compsLangsupport(pkgs, _repo.comps, languages, group)

        normalizeList(pkgs)
        return pkgs
Exemple #5
0
    def getPackages(self, ks, languages, all_comps, has_raid, fstypes):
        groups = []
        pkgs = []
        everything = False
        if ks.has_key("packages") and \
               ks["packages"].has_key("groups") and \
               len(ks["packages"]["groups"]) > 0:
            groups = ks["packages"]["groups"]

        # add default group "base" and "core if it is not in groups and
        # nobase is not set
        if not ks.has_key("packages") or not ks["packages"].has_key("nobase"):
            if not "base" in groups:
                groups.append("base")
            if not "core" in groups:
                groups.append("core")

        if all_comps:
            repos = self.repos.keys()
        else:
            repos = self.base_repo_names

        if "everything" in groups:
            for repo in repos:
                for group in self.repos[repo].comps.getGroups():
                    if not group in groups:
                        groups.append(group)
            groups.remove("everything")
            everything = True

        if ks.has_key("packages") and ks["packages"].has_key("add") and \
               "*" in ks["packages"]["add"]:
            # add all packages
            for repo in self.repos.keys():
                pkgs.extend(self.repos[repo].getNames())
        else:
            # add default desktop
            if ks.has_key("xconfig"):
                if ks["xconfig"].has_key("startxonboot"):
                    if not "base-x" in groups:
                        log.info1("Adding group 'base-x'.")
                        groups.append("base-x")
                    desktop = "GNOME"
                    if ks["xconfig"].has_key("defaultdesktop"):
                        desktop = ks["xconfig"]["defaultdesktop"]
                    desktop = "%s-desktop" % desktop.lower()
                    if not desktop in groups:
                        log.info1("Adding group '%s'.", desktop)
                        groups.append(desktop)

            normalizeList(groups)

            # test if groups are available
            repo_groups = {}
            for group in groups:
                found = False
                for repo in repos:
                    if not self.repos[repo].comps:
                        continue
                    _group = self.repos[repo].comps.getGroup(group)
                    if not _group:
                        continue
                    found = True
                    if not _group in repo_groups.keys() or \
                           not repo in repo_groups[_group]:
                        repo_groups.setdefault(_group, []).append(repo)
                if not found:
                    log.warning("Group '%s' does not exist.", group)
            del groups

            # add packages for groups
            for group in repo_groups:
                for repo in repo_groups[group]:
                    comps = self.repos[repo].comps
                    for pkg in comps.getPackageNames(group):
                        if len(self.repos[repo].searchPkgs([pkg])) > 0:
                            if not pkg in pkgs:
                                pkgs.append(pkg)
                    if everything:
                        # add all packages in this group
                        for (pkg, req) in \
                                comps.getConditionalPackageNames(group):
                            if len(self.repos[repo].searchPkgs([pkg])) > 0:
                                if not pkg in pkgs:
                                    pkgs.append(pkg)
            del repo_groups

        # add packages
        if ks.has_key("packages") and ks["packages"].has_key("add"):
            for name in ks["packages"]["add"]:
                if name == "*":
                    continue
                found = False
                for repo in self.repos.keys():
                    _pkgs = self.repos[repo].searchPkgs([name])
                    if len(_pkgs) > 0:
                        # silently add package
                        if not name in pkgs:
                            pkgs.append(name)
                        found = True
                        break
                if not found:
                    log.warning("Package '%s' is not available.", pkg)

        # remove packages
        if ks.has_key("packages") and ks["packages"].has_key("drop"):
            for pkg in ks["packages"]["drop"]:
                if pkg in pkgs:
                    log.info1("Removing package '%s'.", pkg)
                    pkgs.remove(pkg)

        # add xorg driver package for past FC-5, RHEL-4
        if ks.has_key("xconfig"):
            if (self.isRHEL() and self.cmpVersion("4.9") > 0) or \
                   (self.isFedora() and self.cmpVersion("4") > 0):
                if ks["xconfig"].has_key("driver"):
                    self._addPkg("xorg-x11-drv-%s" % ks["xconfig"]["driver"],
                                 pkgs)
                else:
                    if not "xorg-x11-drivers" in pkgs:
                        self._addPkg("xorg-x11-drivers", pkgs)

        # add packages for needed filesystem types
        for fstype in fstypes:
            if fstype == "swap":
                continue
            self._addPkgByFilename("/sbin/mkfs.%s" % fstype, pkgs,
                                   "%s filesystem creation" % fstype)

        # add comps package
        if not "comps" in pkgs:
            try:
                self._addPkg("comps", pkgs)
            except:
                # ignore missing comps package
                pass

        # append mdadm
        if has_raid:
            self._addPkgByFilename("/sbin/mdadm", pkgs, "raid configuration")

        # append authconfig
        if ks.has_key("authconfig"):
            self._addPkgByFilename("/usr/sbin/authconfig", pkgs,
                                   "authentication configuration")

        # append iptables and config tool
        if ks.has_key("firewall") and \
               not ks["firewall"].has_key("disabled"):
            self._addPkg("iptables", pkgs)

        # no firewall config tool in RHEL-3
        if (self.isRHEL() and self.cmpVersion("4") >= 0) or \
               (self.isFedora() and self.cmpVersion("3") >= 0):
            self._addPkgByFilename("/usr/sbin/lokkit", pkgs,
                                   "firewall configuration")

        # append lokkit
        if ks.has_key("selinux") and \
               ((self.isRHEL() and self.cmpVersion("4") >= 0) or \
                (self.isFedora() and self.cmpVersion("3") >= 0)):
            self._addPkgByFilename("/usr/sbin/lokkit", pkgs,
                                   "selinux configuration")

        # append kernel
        if not "kernel" in pkgs and not "kernel-smp" in pkgs:
            self._addPkg("kernel", pkgs)

        # append kernel-devel for FC-6 and RHEL-5
        if "gcc" in pkgs and \
               ((self.isRHEL() and self.cmpVersion("5") >= 0 and \
                 (self.getVariant() != "Client" or \
                  "%s-Workstation" % (self.release) in self.repos.keys())) or \
                (self.isFedora() and self.cmpVersion("6") >= 0)):
            if "kernel" in pkgs:
                self._addPkg("kernel-devel", pkgs)
            elif "kernel-smp" in pkgs:
                self._addPkg("kernel-smp-devel", pkgs)

        # append firstboot
        if ks.has_key("firstboot") and \
               not ks["firstboot"].has_key("disabled"):
            self._addPkg("firstboot", pkgs)

        # append dhclient
        if ks.has_key("bootloader"):
            self._addPkg("grub", pkgs)
#            if self.getArch() == "ia64":
#                self._addPkg("elilo", pkgs)
#            elif self.getArch in [ "s390", "s390x" ]:
#                self._addPkg("s390utils", pkgs)
#            elif self.getArch() in [ "ppc", "ppc64" ]:
#                self._addPkg("yaboot", pkgs)
#            else:
#                self._addPkg("grub", pkgs)

# append grub
        if ks.has_key("network") and len(ks["network"]) > 0:
            for net in ks["network"]:
                if net["bootproto"] == "dhcp":
                    self._addPkg("dhclient", pkgs)

        # languages (pre FC-6 and pre RHEL-5)
        if len(languages) > 0:
            for repo in repos:
                _repo = self.repos[repo]
                if not _repo.comps:
                    continue
                for group in _repo.comps.grouphash.keys():
                    self._compsLangsupport(pkgs, _repo.comps, languages, group)

        normalizeList(pkgs)
        return pkgs