def __init__(self, config, source, buildroot='', reponame="default", nc=None): """Exclude packages matching whitespace-separated excludes. Use reponame for cache subdirectory name and pkg["yumreponame"]. Load PGP keys from URLs in key_urls.""" memorydb.RpmMemoryDB.__init__(self, config, source, buildroot) self.reponame = reponame self.excludes = self.config.excludes[:] self.mirrorlist = None self.baseurls = None self.yumconf = None self.key_urls = [] if nc: self.nc = nc else: self.nc = NetworkCache([], self.config.cachedir, self.reponame) if isinstance(source, types.DictType): found_urls = False self.yumconf = source if self.yumconf.has_key("main"): sec = self.yumconf["main"] if sec.has_key("exclude"): self.excludes.extend(sec["exclude"]) sec = self.yumconf[self.reponame] if sec.has_key("exclude"): self.excludes.extend(sec["exclude"]) if sec.has_key("gpgkey"): self.key_urls = sec["gpgkey"] if sec.has_key("baseurl"): self.nc.addCache(sec["baseurl"], self.reponame) found_urls = True if sec.has_key("mirrorlist"): self.mirrorlist = sec["mirrorlist"] found_urls = True if not found_urls: raise ValueError, "yum.conf is missing mirrorlist or baseurl parameter" else: self.baseurls = source self.nc.addCache(self.baseurls, self.reponame) self.repomd = None self.filelist_imported = 0 # Files included in primary.xml self._filerc = re.compile('^(.*bin/.*|/etc/.*|/usr/lib/sendmail)$') self._dirrc = re.compile('^(.*bin/.*|/etc/.*)$') self.comps = None
def getOperations(self, resolver=None, installdb=None, erasedb=None): """Return an ordered list of (operation, RpmPackage). If resolver is None, use packages previously added to be acted upon; otherwise use the operations from resolver. Return None on error (after warning the user). New packages to be acted upon can't be added after calling this function, neither before nor after performing the current operations.""" if self.config.timer: time1 = clock() self.__preprocess() # hack: getOperations() is called from yum.py where deps are already # and from scripts/pyrpminstall where we still need todo dep checking. # This should get re-worked to clean this up. nodeps = 1 if resolver == None: nodeps = 0 db = self.db.getMemoryCopy() resolver = RpmResolver(self.config, db) for r in self.rpms: # Ignore errors from RpmResolver, the functions already warn # the user if necessary. if self.operation == OP_INSTALL: resolver.install(r) elif self.operation == OP_UPDATE: resolver.update(r) elif self.operation == OP_FRESHEN: resolver.freshen(r) elif self.operation == OP_ERASE: resolver.erase(r) else: log.error("Unknown operation") del self.rpms if not self.config.nodeps and not nodeps and resolver.resolve() != 1: return None if self.config.timer: log.info2("resolver took %s seconds", (clock() - time1)) time1 = clock() log.info2("Ordering transaction...") orderer = RpmOrderer(self.config, resolver.installs, resolver.updates, resolver.obsoletes, resolver.erases, installdb=installdb, erasedb=erasedb) del resolver operations = orderer.order() if operations is None: # Currently can't happen log.error("Errors found during package dependency " "checks and ordering.") return None # replace repodb pkgs by binaryrpm instances for idx, (op, pkg) in enumerate(operations): if op in (OP_UPDATE, OP_INSTALL, OP_FRESHEN): nc = None if not self.config.nocache and \ (pkg.source.startswith("http://") or \ pkg.source.startswith("https://") or \ pkg.yumrepo != None): if pkg.yumrepo != None: nc = pkg.yumrepo.getNetworkCache() else: nc = NetworkCache( "/", os.path.join(self.config.cachedir, "default")) p = package.RpmPackage(pkg.config, pkg.source, pkg.verifySignature, db=self.db) if pkg.yumrepo != None: p.source = os.path.join( pkg.yumrepo.getNetworkCache().getBaseURL(), p.source) p.nc = nc p.yumhref = pkg.yumhref p.issrc = pkg.issrc # copy NEVRA for tag in self.config.nevratags: p[tag] = pkg[tag] operations[idx] = (op, p) if self.config.timer: log.info2("orderer took %s seconds", (clock() - time1)) del orderer if not self.config.ignoresize: if self.config.timer: time1 = clock() ret = getFreeCachespace(self.config, operations) if self.config.timer: log.info2("getFreeCachespace took %s seconds", (clock() - time1)) if not ret: return None if self.config.timer: time1 = clock() ret = getFreeDiskspace(self.config, operations) if self.config.timer: log.info2("getFreeDiskspace took %s seconds", (clock() - time1)) if not ret: return None return operations
def load(self, ks, dir, beta_key_verify=False): self.dir = dir self.exclude = None # mount source to dir if ks.has_key("cdrom"): self.url = mount_cdrom(dir) if ks["cdrom"].has_key("exclude"): self.exclude = ks["cdrom"]["exclude"] elif ks.has_key("nfs"): opts = None if ks["nfs"].has_key("opts"): opts = ks["nfs"]["opts"] self.url = mount_nfs("nfs://%s:%s" % \ (ks["nfs"]["server"], ks["nfs"]["dir"]), dir, options=opts) if ks["nfs"].has_key("exclude"): self.exclude = ks["nfs"]["exclude"] else: self.url = ks["url"]["url"] if ks["url"].has_key("exclude"): self.exclude = ks["url"]["exclude"] # create network cache self.cache = NetworkCache([self.url], cachedir=rpmconfig.cachedir) # get source information via .discinfo file if not self.cache.cache(".discinfo"): log.error("No .discinfo for '%s'", self.url) return 0 di = get_discinfo(self.cache.cache(".discinfo")) if not di: log.error("Getting .discinfo for '%s' failed.", self.url) return 0 (self.name, self.version, self.arch) = di if self.name.startswith("Red Hat Enterprise Linux"): self.variant = self.name[24:].strip() self.id = "RHEL" self.prefix = "RedHat" elif self.name.startswith("Fedora"): self.variant = "" self.id = "FC" self.prefix = "Fedora" else: log.error("Unknown source '%s'.", self.name) return 0 self.release = "%s-%s" % (self.id, self.version) log.info1("Installation source: %s %s [%s]", self.name, self.version, self.arch) # load repos repos = [] self.yumconf = YumConf(self.version, self.arch, rpmdb=None, filenames=[], reposdirs=[]) if self.isRHEL() and self.cmpVersion("4.9") >= 0: # RHEL-5 key = None skip = False if ks.has_key("key"): key = ks["key"].keys()[0] if ks["key"][key].has_key("skip"): skip = True key = None inum = None if key and not skip and not beta_key_verify: if not instnum: log.warning("Unable to verify installation key, " "module instkey is missing.. using default" "installation.") else: try: inum = instnum.InstNum(key) except: log.error("Installation key '%s' is not valid.", key) return 0 if inum: if inum.get_product_string().lower() != \ self.variant.lower(): log.error( "Installation key for '%s' does not match " "'%s' media.", inum.get_product_string().lower(), self.variant.lower()) return 0 for name, path in inum.get_repos_dict().items(): if path == "VT" and \ not self.arch in [ "i386", "x86_64", "ia64" ]: continue repos.append(path) else: # BETA if self.variant == "Server": repos.append("Server") if key and key.find("C") >= 0: repos.append("Cluster") if key and key.find("S") >= 0: repos.append("ClusterStorage") elif self.variant == "Client": repos.append("Client") if key and key.find("W") >= 0: repos.append("Workstation") if self.arch in ["i386", "x86_64", "ia64"]: if key and key.find("V") >= 0: repos.append("VT") for repo in repos: repo_name = "%s-%s" % (self.release, repo) if repo in self.repos: log.error("Repository '%s' already defined.", repo_name) return 0 log.info1("Loading repo '%s'", repo_name) # create yumconf self.yumconf[repo_name] = {} self.yumconf[repo_name]["baseurl"] = [ "%s/%s" % (self.url, repo) ] if self.exclude: self.yumconf[repo_name]["exclude"] = self.exclude _repo = getRepoDB(rpmconfig, self.yumconf, reponame=repo_name) self.repos[repo_name] = _repo if not _repo.read(): log.error("Could not load repository '%s'.", repo_name) return 0 else: # RHEL <= 4 # FC repo = self.release self.yumconf[repo] = {} self.yumconf[repo]["baseurl"] = [self.url] if self.exclude: self.yumconf[repo]["exclude"] = self.exclude _repo = getRepoDB(rpmconfig, self.yumconf, reponame=repo) self.repos[repo] = _repo if not _repo.read(): log.error("Could not load repository '%s'.", repo) return 0 if not _repo.comps: # every source repo has to have a comps log.error("Missing comps file for '%s'.", repo) return 0 self.base_repo_names = self.repos.keys() if not ks.has_key("repo"): return 1 for repo in ks["repo"]: if repo in self.repos: log.error("Repository '%s' already defined.", repo) return 0 log.info1("Loading repository '%s'", repo) self.yumconf[repo] = {} url = ks["repo"][repo]["baseurl"] if url[:6] == "nfs://": d = "%s/%s" % (dir, repo) create_dir("", d) url = mount_nfs(url, d) self.yumconf[repo]["baseurl"] = [url] if ks["repo"][repo].has_key("exclude"): self.yumconf[repo]["exclude"] = ks["repo"][repo]["exclude"] if ks["repo"][repo].has_key("mirrorlist"): self.yumconf[repo]["mirrorlist"] = \ ks["repo"][repo]["mirrorlist"] _repo = getRepoDB(rpmconfig, self.yumconf, reponame=repo) self.repos[repo] = _repo if not _repo.read(): log.error("Could not load repository '%s'.", repo) return 0 return 1