Fix size estimation in splittree.

This while file needs a major rework, but this gets us correct
size estimations when building up discs.
This commit is contained in:
Jesse Keating 2009-02-12 11:26:48 -08:00
parent 923a0c9392
commit bdf3b118aa

View File

@ -26,6 +26,7 @@ import getopt
import time import time
import types import types
import rpm import rpm
import subprocess
global _ts global _ts
_ts = None _ts = None
@ -105,21 +106,19 @@ self.reserve_size : Additional size needed to be reserved on the first disc.
self.logfile = [] self.logfile = []
def getSize(self, path, blocksize=None):
"""Gets the size as reported by du -sL"""
if blocksize: def getIsoSize(self, path):
p = os.popen("du -slL --block-size=1 %s" % path, 'r') """Gets the size that a path would take in iso form"""
thesize = p.read()
p.close() call = ['/usr/bin/genisoimage', '-U', '-J', '-R', '-T', '-m',
thesize = long(string.split(thesize)[0]) 'repoview', '-m', 'images/boot.iso', '-print-size',
return thesize '-quiet', path]
else:
p = os.popen("du -slLh %s" % path, 'r') isosize = int(subprocess.Popen(call,
thesize = p.read() stdout=subprocess.PIPE,
p.close() stderr=subprocess.PIPE).communicate()[0])
thesize = string.split(thesize)[0]
return thesize return isosize * 2048
@ -131,7 +130,7 @@ self.reserve_size : Additional size needed to be reserved on the first disc.
if lastpkg: if lastpkg:
self.logfile.append("Last package on disc%d : %s" % (disc, lastpkg)) self.logfile.append("Last package on disc%d : %s" % (disc, lastpkg))
discsize = self.getSize("%s-disc%d" % (self.dist_dir, disc)) discsize = self.getIsoSize("%s-disc%d" % (self.dist_dir, disc))
self.logfile.append("%s-disc%d size: %s" % (self.arch, disc, discsize)) self.logfile.append("%s-disc%d size: %s" % (self.arch, disc, discsize))
@ -295,8 +294,8 @@ self.reserve_size : Additional size needed to be reserved on the first disc.
if not packages.has_key(rpm_nvr): if not packages.has_key(rpm_nvr):
continue continue
for file_name in packages[rpm_nvr]: for file_name in packages[rpm_nvr]:
curused = self.getSize("%s-disc%s" % (self.dist_dir, disc), blocksize=1) curused = self.getIsoSize("%s-disc%s" % (self.dist_dir, disc))
filesize = self.getSize("%s/%s/%s" % (self.dist_dir, pkgdir, file_name), blocksize=1) filesize = os.stat("%s/%s/%s" % (self.dist_dir, pkgdir, file_name)).st_size
newsize = filesize + curused newsize = filesize + curused
# compensate for the size of the comps package which has yet to be created # compensate for the size of the comps package which has yet to be created
@ -346,7 +345,7 @@ self.reserve_size : Additional size needed to be reserved on the first disc.
sizes = [] sizes = []
for i in range(0, len(self.src_list)): for i in range(0, len(self.src_list)):
sizes.append([self.getSize("%s-disc%d" % (self.dist_dir, self.src_list[i]), blocksize=1), self.src_list[i]]) sizes.append([self.getIsoSize("%s-disc%d" % (self.dist_dir, self.src_list[i])), self.src_list[i]])
sizes.sort() sizes.sort()
return sizes[0] return sizes[0]
@ -364,7 +363,7 @@ self.reserve_size : Additional size needed to be reserved on the first disc.
for srpm in os.listdir("%s" % self.src_dir): for srpm in os.listdir("%s" % self.src_dir):
if not srpm.endswith('.rpm'): if not srpm.endswith('.rpm'):
continue continue
srpm_size = self.getSize("%s/%s" % (self.src_dir, srpm), blocksize=1) srpm_size = os.stat("%s/%s" % (self.src_dir, srpm)).st_size
srpm_list.append([srpm_size, srpm]) srpm_list.append([srpm_size, srpm])
srpm_list.sort() srpm_list.sort()
@ -375,12 +374,12 @@ self.reserve_size : Additional size needed to be reserved on the first disc.
# if it isn't, pull it out of the list. If there's only # if it isn't, pull it out of the list. If there's only
# one disk make loud noises over the overflow # one disk make loud noises over the overflow
for disc in self.src_list: for disc in self.src_list:
if self.getSize("%s-disc%s" % (self.dist_dir, disc), blocksize=1) > self.target_size: if self.getIsoSize("%s-disc%s" % (self.dist_dir, disc)) > self.target_size:
if len(self.src_list) < 2: if len(self.src_list) < 2:
self.logfile.append("Overflowing %s on disc%d" % (srpm_list[i][1], disc)) self.logfile.append("Overflowing %s on disc%d" % (srpm_list[i][1], disc))
break break
else: else:
discsize = self.getSize("%s-disc%d" % (self.dist_dir, disc)) discsize = self.getIsoSize("%s-disc%d" % (self.dist_dir, disc))
self.logfile.append("%s-disc%d size: %s" % (self.arch, disc, discsize)) self.logfile.append("%s-disc%d size: %s" % (self.arch, disc, discsize))
self.src_list.pop(self.src_list.index(disc)) self.src_list.pop(self.src_list.index(disc))
os.link("%s/%s" % (self.src_dir, srpm_list[i][1]), os.link("%s/%s" % (self.src_dir, srpm_list[i][1]),