From 8697543cb765b21366e8313642d811d0d5159402 Mon Sep 17 00:00:00 2001 From: Gui Chen Date: Tue, 15 Jan 2013 16:29:44 +0800 Subject: [PATCH] add a new opiton --nocache for repo command this option '--nocache' in repo command is used to disable using cached rpm in this repo Signed-off-by: Gui Chen --- mic/imager/baseimager.py | 5 +++-- mic/kickstart/__init__.py | 6 +++++- mic/kickstart/custom_commands/micrepo.py | 8 +++++++- plugins/backend/yumpkgmgr.py | 8 ++++++-- plugins/backend/zypppkgmgr.py | 12 +++++++++++- 5 files changed, 32 insertions(+), 7 deletions(-) diff --git a/mic/imager/baseimager.py b/mic/imager/baseimager.py index ed5412a..5a95726 100644 --- a/mic/imager/baseimager.py +++ b/mic/imager/baseimager.py @@ -905,11 +905,12 @@ class BaseImageCreator(object): for repo in kickstart.get_repos(self.ks, repo_urls): (name, baseurl, mirrorlist, inc, exc, proxy, proxy_username, proxy_password, debuginfo, - source, gpgkey, disable, ssl_verify, cost, priority) = repo + source, gpgkey, disable, ssl_verify, nocache, + cost, priority) = repo yr = pkg_manager.addRepository(name, baseurl, mirrorlist, proxy, proxy_username, proxy_password, inc, exc, ssl_verify, - cost, priority) + nocache, cost, priority) if kickstart.exclude_docs(self.ks): rpm.addMacro("_excludedocs", "1") diff --git a/mic/kickstart/__init__.py b/mic/kickstart/__init__.py index 8a11c69..7b98897 100644 --- a/mic/kickstart/__init__.py +++ b/mic/kickstart/__init__.py @@ -748,6 +748,9 @@ def get_repos(ks, repo_urls = {}): ssl_verify = True if hasattr(repo, "ssl_verify"): ssl_verify = repo.ssl_verify == "yes" + nocache = False + if hasattr(repo, "nocache"): + nocache = repo.nocache cost = None if hasattr(repo, "cost"): cost = repo.cost @@ -757,7 +760,8 @@ def get_repos(ks, repo_urls = {}): repos[repo.name] = (repo.name, baseurl, mirrorlist, inc, exc, proxy, proxy_username, proxy_password, debuginfo, - source, gpgkey, disable, ssl_verify, cost, priority) + source, gpgkey, disable, ssl_verify, nocache, + cost, priority) return repos.values() diff --git a/mic/kickstart/custom_commands/micrepo.py b/mic/kickstart/custom_commands/micrepo.py index 8f14a5d..eed9a56 100644 --- a/mic/kickstart/custom_commands/micrepo.py +++ b/mic/kickstart/custom_commands/micrepo.py @@ -26,7 +26,8 @@ class Mic_RepoData(F8_RepoData): def __init__(self, baseurl="", mirrorlist="", name="", priority=None, includepkgs=[], excludepkgs=[], save=False, proxy=None, proxy_username=None, proxy_password=None, debuginfo=False, - source=False, gpgkey=None, disable=False, ssl_verify="yes"): + source=False, gpgkey=None, disable=False, ssl_verify="yes", + nocache=False): F8_RepoData.__init__(self, baseurl=baseurl, mirrorlist=mirrorlist, name=name, includepkgs=includepkgs, excludepkgs=excludepkgs) @@ -40,6 +41,7 @@ class Mic_RepoData(F8_RepoData): self.gpgkey = gpgkey self.ssl_verify = ssl_verify.lower() self.priority = priority + self.nocache = nocache def _getArgsAsStr(self): retval = F8_RepoData._getArgsAsStr(self) @@ -64,6 +66,8 @@ class Mic_RepoData(F8_RepoData): retval += " --ssl_verify=%s" % self.ssl_verify if self.priority: retval += " --priority=%s" % self.priority + if self.nocache: + retval += " --nocache" return retval @@ -104,4 +108,6 @@ class Mic_Repo(F8_Repo): dest="ssl_verify", default="yes") op.add_option("--priority", type="int", action="store", dest="priority", default=None) + op.add_option("--nocache", action="store_true", dest="nocache", + default=False) return op diff --git a/plugins/backend/yumpkgmgr.py b/plugins/backend/yumpkgmgr.py index 910f1cf..6a94631 100644 --- a/plugins/backend/yumpkgmgr.py +++ b/plugins/backend/yumpkgmgr.py @@ -257,8 +257,8 @@ class Yum(BackendPlugin, yum.YumBase): def addRepository(self, name, url = None, mirrorlist = None, proxy = None, proxy_username = None, proxy_password = None, - inc = None, exc = None, ssl_verify=True, cost = None, - priority=None): + inc = None, exc = None, ssl_verify=True, nocache=False, + cost = None, priority=None): # TODO: Handle priority attribute for repos def _varSubstitute(option): # takes a variable and substitutes like yum configs do @@ -290,6 +290,7 @@ class Yum(BackendPlugin, yum.YumBase): repo.setAttribute(k, v) repo.sslverify = ssl_verify + repo.cache = not nocache repo.basecachedir = self.cachedir repo.base_persistdir = self.conf.persistdir @@ -371,6 +372,9 @@ class Yum(BackendPlugin, yum.YumBase): msger.info("\nChecking packages cache and packages integrity ...") for po in dlpkgs: local = po.localPkg() + repo = filter(lambda r: r.id == po.repoid, self.repos.listEnabled())[0] + if not repo.cache and os.path.exists(local): + os.unlink(local) if not os.path.exists(local): continue if not self.verifyPkg(local, po, False): diff --git a/plugins/backend/zypppkgmgr.py b/plugins/backend/zypppkgmgr.py index 468a8b7..48894b2 100755 --- a/plugins/backend/zypppkgmgr.py +++ b/plugins/backend/zypppkgmgr.py @@ -43,6 +43,7 @@ class RepositoryStub: self.proxy = None self.proxy_username = None self.proxy_password = None + self.nocache = False self.enabled = True self.autorefresh = True @@ -303,6 +304,7 @@ class Zypp(BackendPlugin): inc = None, exc = None, ssl_verify = True, + nocache = False, cost=None, priority=None): # TODO: Handle cost attribute for repos @@ -320,6 +322,7 @@ class Zypp(BackendPlugin): repo.proxy_username = proxy_username repo.proxy_password = proxy_password repo.ssl_verify = ssl_verify + repo.nocache = nocache repo.baseurl.append(url) if inc: for pkg in inc: @@ -448,8 +451,15 @@ class Zypp(BackendPlugin): cached_count += 1 else: local = self.getLocalPkgPath(po) + name = str(po.repoInfo().name()) + try: + repo = filter(lambda r: r.name == name, self.repos)[0] + except IndexError: + repo = None + nocache = repo.nocache if repo else False + if os.path.exists(local): - if self.checkPkg(local) != 0: + if nocache or self.checkPkg(local) !=0: os.unlink(local) else: download_total_size -= int(po.downloadSize()) -- 2.7.4