summaryrefslogtreecommitdiffstats
path: root/scripts/yumcache
diff options
context:
space:
mode:
authorPaul Nasrat <pnasrat@redhat.com>2005-10-18 15:54:00 +0000
committerPaul Nasrat <pnasrat@redhat.com>2005-10-18 15:54:00 +0000
commit8edeec4702506d5679cdd469c7f466e39b9eecb6 (patch)
treedd8935c8c40d7e15d1c15eb75a8764df17863647 /scripts/yumcache
parent1e6c2089631b3b03b6e72c344f1537cde3bd45dc (diff)
downloadanaconda-8edeec4702506d5679cdd469c7f466e39b9eecb6.tar.gz
anaconda-8edeec4702506d5679cdd469c7f466e39b9eecb6.tar.xz
anaconda-8edeec4702506d5679cdd469c7f466e39b9eecb6.zip
Create yum cache
Diffstat (limited to 'scripts/yumcache')
-rwxr-xr-xscripts/yumcache80
1 files changed, 80 insertions, 0 deletions
diff --git a/scripts/yumcache b/scripts/yumcache
new file mode 100755
index 000000000..50ff0ba13
--- /dev/null
+++ b/scripts/yumcache
@@ -0,0 +1,80 @@
+#!/usr/bin/python
+
+from optparse import OptionParser
+
+import os
+import glob
+import shutil
+import sys
+import tempfile
+import yum
+
+class CacheConf:
+ """Dynamic yum configuration"""
+
+ def __init__( self, repopath):
+ self.fd, self.name = tempfile.mkstemp(".conf", "yum-", "/tmp")
+ self.cachedir = tempfile.mkdtemp("", "yum-cache-", "/tmp")
+ self.repopath = repopath
+
+ self.yumconfstr = """
+[main]
+distroverpkg=redhat-release
+cachedir=%s
+gpgcheck=0
+
+[cache]
+baseurl=file://%s
+enabled=1
+""" % (self.cachedir, self.repopath)
+
+ os.write(self.fd, self.yumconfstr)
+ os.close(self.fd)
+
+class YumCacheGenerator(yum.YumBase):
+ def __init__(self, repopath):
+ yum.YumBase.__init__(self)
+ self.repopath = repopath
+ self.config = CacheConf(repopath)
+ self.doConfigSetup(self.config.name)
+ os.unlink(self.config.name)
+
+ def log(self, level, msg):
+ pass
+
+ def errorlog(self, level, msg):
+ pass
+
+ def filelog(self, level, msg):
+ pass
+
+ def write(self):
+ self.repos.disableRepo('*')
+ self.repos.enableRepo('cache')
+ self.doRepoSetup()
+ self.repos.populateSack(with='metadata', pickleonly=1)
+ self.repos.populateSack(with='filelists', pickleonly=1)
+ for cache in glob.glob("%s/cache/*.sqlite" %( self.config.cachedir,)):
+ shutil.move(cache, "%s/repodata" % (self.config.repopath))
+
+ shutil.rmtree(self.config.cachedir)
+
+
+def usage():
+ print "yumcache <toppath>"
+
+if __name__ == "__main__":
+ parser = OptionParser()
+ (options, args) = parser.parse_args()
+
+ if len(args) != 1:
+ usage()
+ sys.exit(1)
+ repopath = args[0]
+
+ if not os.path.exists("%s/repodata/repomd.xml" % (repopath)):
+ sys.stderr.write("No metadata found in %s" % (repopath,))
+ sys.exit(2)
+
+ y = YumCacheGenerator(repopath)
+ y.write()