pylorax.imgutils: add debug logging

Add some useful debug logging info to various functions in
pylorax.imgutils.
This commit is contained in:
Will Woods 2012-06-13 18:28:46 -04:00
parent 329432b58e
commit 2aae30e691

View File

@ -41,6 +41,8 @@ def mkcpio(rootdir, outfile, compression="xz", compressargs=["-9"]):
if compression is None: if compression is None:
compression = "cat" # this is a little silly compression = "cat" # this is a little silly
compressargs = [] compressargs = []
logger.debug("mkcpio %s | %s %s > %s", rootdir, compression,
" ".join(compressargs), outfile)
find = Popen(["find", ".", "-print0"], stdout=PIPE, preexec_fn=chdir) find = Popen(["find", ".", "-print0"], stdout=PIPE, preexec_fn=chdir)
cpio = Popen(["cpio", "--null", "--quiet", "-H", "newc", "-o"], cpio = Popen(["cpio", "--null", "--quiet", "-H", "newc", "-o"],
stdin=find.stdout, stdout=PIPE, preexec_fn=chdir) stdin=find.stdout, stdout=PIPE, preexec_fn=chdir)
@ -53,7 +55,9 @@ def mksquashfs(rootdir, outfile, compression="default", compressargs=[]):
'''Make a squashfs image containing the given rootdir.''' '''Make a squashfs image containing the given rootdir.'''
if compression != "default": if compression != "default":
compressargs = ["-comp", compression] + compressargs compressargs = ["-comp", compression] + compressargs
return call(["mksquashfs", rootdir, outfile] + compressargs) cmd = ["mksquashfs", rootdir, outfile] + compressargs
logger.debug(" ".join(cmd))
return call(cmd)
######## Utility functions ############################################### ######## Utility functions ###############################################
@ -106,24 +110,32 @@ def mount(dev, opts="", mnt=None):
raises CalledProcessError if mount fails.''' raises CalledProcessError if mount fails.'''
if mnt is None: if mnt is None:
mnt = tempfile.mkdtemp(prefix="lorax.imgutils.") mnt = tempfile.mkdtemp(prefix="lorax.imgutils.")
logger.debug("make tmp mountdir %s", mnt)
mount = ["mount"] mount = ["mount"]
if opts: if opts:
mount += ["-o", opts] mount += ["-o", opts]
check_call(mount + [dev, mnt]) mount += [dev, mnt]
logger.debug(" ".join(mount))
check_call(mount)
return mnt return mnt
def umount(mnt): def umount(mnt):
'''Unmount the given mountpoint. If the mount was a temporary dir created '''Unmount the given mountpoint. If the mount was a temporary dir created
by mount, it will be deleted. Returns false if the unmount fails.''' by mount, it will be deleted. Returns false if the unmount fails.'''
rv = call(["umount", mnt]) umount = ["umount"]
umount += [mnt]
logger.debug(" ".join(umount))
rv = call(umount)
if 'lorax.imgutils' in mnt: if 'lorax.imgutils' in mnt:
os.rmdir(mnt) os.rmdir(mnt)
logger.debug("remove tmp mountdir %s", mnt)
return (rv == 0) return (rv == 0)
def copytree(src, dest, preserve=True): def copytree(src, dest, preserve=True):
'''Copy a tree of files using cp -a, thus preserving modes, timestamps, '''Copy a tree of files using cp -a, thus preserving modes, timestamps,
links, acls, sparse files, xattrs, selinux contexts, etc. links, acls, sparse files, xattrs, selinux contexts, etc.
If preserve is False, uses cp -R (useful for modeless filesystems)''' If preserve is False, uses cp -R (useful for modeless filesystems)'''
logger.debug("copytree %s %s", src, dest)
chdir = lambda: os.chdir(src) chdir = lambda: os.chdir(src)
cp = ["cp", "-a"] if preserve else ["cp", "-R", "-L"] cp = ["cp", "-a"] if preserve else ["cp", "-R", "-L"]
check_call(cp + [".", os.path.abspath(dest)], preexec_fn=chdir) check_call(cp + [".", os.path.abspath(dest)], preexec_fn=chdir)