#!/usr/bin/python -tt

import mic.chroot as achroot
import shutil
import sys
import os

if len(sys.argv) < 2:
    print "Usage: %s <chroot-dir>"
    sys.exit(1)

chrootdirs = sys.argv[1:]
for chrootdir in chrootdirs:
    if os.path.isdir(chrootdir):
        ret = achroot.cleanup_mounts(chrootdir)
        if ret == 0:
            shutil.rmtree(chrootdir, ignore_errors = True)
        else:
            print "Failed to rm %s because of the above error. please ensure there isn't any other process accessing some directories under %s" % (chrootdir, chrootdir)
