示例#1
0
def deltree(*dirs):
    """Delete each one of a list of directories, along with all of its
       contents."""
    global _WAIT_FOR_KIDS
    #print "deltree(%r)"%dirs
    if _WAIT_FOR_KIDS:
        print "Waiting for shred processes to finish."
        waitForChildren()
        _WAIT_FOR_KIDS = 0
    for d in dirs:
        #print "Considering",d
        if os.path.isdir(d):
            #print "deleting from %s: %s" % (d, os.listdir(d))
            for fn in os.listdir(d):
                loc = os.path.join(d,fn)
                if os.path.isdir(loc):
                    #print "deleting (I)",loc
                    deltree(loc)
                else:
                    #print "unlinking (I)",loc
                    os.unlink(loc)
            #ld = os.listdir(d)
            #if ld: print "remaining in %s: %s" % (d, ld)
            if os.listdir(d):
                print "os.listdir(%r)==(%r)"%(d,os.listdir(d))
            os.rmdir(d)
        elif os.path.exists(d):
            #print "Unlinking", d
            os.unlink(d)
        else:
            pass #print "DNE", d
示例#2
0
def deltree(*dirs):
    """Delete each one of a list of directories, along with all of its
       contents."""
    global _WAIT_FOR_KIDS
    #print "deltree(%r)"%dirs
    if _WAIT_FOR_KIDS:
        print "Waiting for shred processes to finish."
        waitForChildren()
        _WAIT_FOR_KIDS = 0
    for d in dirs:
        #print "Considering",d
        if os.path.isdir(d):
            #print "deleting from %s: %s" % (d, os.listdir(d))
            for fn in os.listdir(d):
                loc = os.path.join(d, fn)
                if os.path.isdir(loc):
                    #print "deleting (I)",loc
                    deltree(loc)
                else:
                    #print "unlinking (I)",loc
                    os.unlink(loc)
            #ld = os.listdir(d)
            #if ld: print "remaining in %s: %s" % (d, ld)
            if os.listdir(d):
                print "os.listdir(%r)==(%r)" % (d, os.listdir(d))
            os.rmdir(d)
        elif os.path.exists(d):
            #print "Unlinking", d
            os.unlink(d)
        else:
            pass  #print "DNE", d
示例#3
0
def fileOpsTiming():
    print "#================= File ops ====================="
    installSIGCHLDHandler()
    dname = mix_mktemp(".d")

    os.mkdir(dname)

    lockfile = Lockfile(os.path.join("dname"))
    t1 = time()
    for _ in xrange(2000):
        lockfile.acquire(blocking=1)
        lockfile.release()
    t = time()-t1
    print "Lockfile: lock+unlock", timestr(t/2000.)

    for i in xrange(200):
        f = open(os.path.join(dname, str(i)), 'wb')
        f.write(s32K)
        f.close()
    lst = [os.path.join(dname,str(i)) for i in range(100) ]
    t1 = time()
    secureDelete(lst)
    t = time()-t1
    print "secureDelete (100x32)", timestr(t)

    waitForChildren()
    t = time()-t1
    print "               (sync)", timestr(t)

    lst = [ os.path.join(dname,str(i)) for i in range(100,200) ]
    t1 = time()
    for fname in lst:
        secureDelete(fname)
    t = time()-t1
    print "secureDelete (1)", timestr(t/100)

    waitForChildren()
    t = time()-t1
    print "          (sync)", timestr(t/100)