def main():
    options, days_old = _parse_args()

    if not os.path.exists(BASE):
        print >> sys.stderr, "error: '%s' doesn't exist. Make sure you're"\
                             " running this on the dom0." % BASE
        sys.exit(1)

    lockpaths_removed = 0
    nspaths_removed = 0

    for nsname in os.listdir(BASE)[:options.limit]:
        nspath = os.path.join(BASE, nsname)

        if not os.path.isdir(nspath):
            continue

        # Remove old lockfiles
        removed = 0
        locknames = os.listdir(nspath)
        for lockname in locknames:
            lockpath = os.path.join(nspath, lockname)
            lock_age_days = _get_age_days(os.path.getmtime(lockpath))
            if lock_age_days > days_old:
                lockpaths_removed += 1
                removed += 1

                if options.verbose:
                    print 'Removing old lock: %03d %s' % (lock_age_days,
                                                          lockpath)

                if not options.dry_run:
                    os.unlink(lockpath)

        # Remove empty namespace paths
        if len(locknames) == removed:
            nspaths_removed += 1

            if options.verbose:
                print 'Removing empty namespace: %s' % nspath

            if not options.dry_run:
                try:
                    os.rmdir(nspath)
                except __HOLE__, e:
                    if e.errno == errno.ENOTEMPTY:
                        print >> sys.stderr, "warning: directory '%s'"\
                                             " not empty" % nspath
                    else:
                        raise

    if options.dry_run:
        print "** Dry Run **"

    print "Total locks removed: ", lockpaths_removed
    print "Total namespaces removed: ", nspaths_removed
dataset/ETHPy150Open BU-NU-CLOUD-SP16/Trusted-Platform-Module-nova/tools/xenserver/cleanup_sm_locks.py/main