# Ensure all data is flushed to _outdir
runner.quiet('sync')
+ misc.check_space_pre_cp(self._outdir, destdir)
for f in os.listdir(self._outdir):
shutil.move(os.path.join(self._outdir, f),
os.path.join(destdir, f))
from baseimager import BaseImageCreator
from mic import msger
-from mic.utils import runner
+from mic.utils import runner, misc
from mic.utils.fs_related import *
from subprocess import call
if self._img_compression_method == None:
fsdir = os.path.join(destdir, self.name)
+ misc.check_space_pre_cp(self._instroot, destdir)
msger.info("Copying %s to %s ..." % (self._instroot, fsdir))
runner.show(['cp', "-af", self._instroot, fsdir])
RPM_FMT = "%(name)s.%(arch)s %(ver_rel)s"
SRPM_RE = re.compile("(.*)-(\d+.*)-(\d+\.\d+).src.rpm")
+def human_size(size):
+ # make Bytes size readable by human
+ import math
+ measure = ['B', 'K', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y']
+ expo = int(math.log(size, 1024))
+ mant = float(size/math.pow(1024, expo))
+ return "{0:.1f}{1:s}".format(mant, measure[expo])
+
+def check_space_pre_cp(src, dst):
+ # check whether space is enough before 'cp'
+ srcsize = get_file_size(src) * 1024 * 1024
+ dstsize = get_filesystem_avail(dst)
+ if srcsize > dstsize:
+ raise CreatorError("Space on %s (%s) is not enough than needed (%s)"
+ % (dst, human_size(dstsize), human_size(srcsize)))
+
def get_md5sum(fpath):
blksize = 65536 # should be optimized enough