cleanup_sm_locks.py 文件源码

python
阅读 23 收藏 0 点赞 0 评论 0

项目:Trusted-Platform-Module-nova 作者: BU-NU-CLOUD-SP16 项目源码 文件源码
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 OSError, 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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号