- Use cache dir to cache downloads, hardlink to destdir
This commit is contained in:
parent
a41dfc13bd
commit
d3415e63fc
@ -91,16 +91,21 @@ class Gather(yum.YumBase):
|
|||||||
downloads.append(pkg.name)
|
downloads.append(pkg.name)
|
||||||
self.logger.info("Download list: %s" % downloads)
|
self.logger.info("Download list: %s" % downloads)
|
||||||
|
|
||||||
|
pkgdir = os.path.join(self.opts.destdir, 'tree') # Package location within destdir, name subject to change/config
|
||||||
|
if not os.path.exists(pkgdir):
|
||||||
|
os.makedirs(pkgdir)
|
||||||
|
|
||||||
for pkg in self.polist:
|
for pkg in self.polist:
|
||||||
repo = self.repos.getRepo(pkg.repoid)
|
repo = self.repos.getRepo(pkg.repoid)
|
||||||
remote = pkg.returnSimple('relativepath')
|
remote = pkg.returnSimple('relativepath')
|
||||||
local = os.path.basename(remote)
|
local = os.path.basename(remote)
|
||||||
local = os.path.join(self.opts.destdir, local)
|
local = os.path.join(self.opts.cachedir, local)
|
||||||
if (os.path.exists(local) and
|
if (os.path.exists(local) and
|
||||||
str(os.path.getsize(local)) == pkg.returnSimple('packagesize')):
|
str(os.path.getsize(local)) == pkg.returnSimple('packagesize')):
|
||||||
|
|
||||||
if not self.opts.quiet:
|
if not self.opts.quiet:
|
||||||
self.logger.info("%s already exists and appears to be complete" % local)
|
self.logger.info("%s already exists and appears to be complete" % local)
|
||||||
|
os.link(local, os.path.join(pkgdir, os.path.basename(remote)))
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Disable cache otherwise things won't download
|
# Disable cache otherwise things won't download
|
||||||
@ -109,6 +114,7 @@ class Gather(yum.YumBase):
|
|||||||
self.logger.info('Downloading %s' % os.path.basename(remote))
|
self.logger.info('Downloading %s' % os.path.basename(remote))
|
||||||
pkg.localpath = local # Hack: to set the localpath to what we want.
|
pkg.localpath = local # Hack: to set the localpath to what we want.
|
||||||
repo.getPackage(pkg)
|
repo.getPackage(pkg)
|
||||||
|
os.link(local, os.path.join(pkgdir, os.path.basename(remote)))
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
@ -120,7 +126,7 @@ def main():
|
|||||||
|
|
||||||
if not os.path.exists(opts.destdir):
|
if not os.path.exists(opts.destdir):
|
||||||
try:
|
try:
|
||||||
os.mkdirs(opts.destdir)
|
os.makedirs(opts.destdir)
|
||||||
except OSError, e:
|
except OSError, e:
|
||||||
print >> sys.stderr, "Error: Cannot destination cache dir %s" % opts.destdir
|
print >> sys.stderr, "Error: Cannot destination cache dir %s" % opts.destdir
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
@ -149,7 +155,6 @@ if __name__ == '__main__':
|
|||||||
help='destination directory (defaults to current directory)')
|
help='destination directory (defaults to current directory)')
|
||||||
parser.add_option("--cachedir", default="./cache", dest="cachedir",
|
parser.add_option("--cachedir", default="./cache", dest="cachedir",
|
||||||
help='cache directory (defaults to cache subdir of current directory)')
|
help='cache directory (defaults to cache subdir of current directory)')
|
||||||
parser.add_option("--comps", default="comps.xml", dest="comps",
|
|
||||||
parser.add_option("--comps", default="comps.xml", dest="comps",
|
parser.add_option("--comps", default="comps.xml", dest="comps",
|
||||||
help='comps file to use')
|
help='comps file to use')
|
||||||
parser.add_option("--yumconf", default="yum.conf", dest="yumconf",
|
parser.add_option("--yumconf", default="yum.conf", dest="yumconf",
|
||||||
|
Loading…
Reference in New Issue
Block a user