コード例 #1
0
ファイル: fileWriteTest.py プロジェクト: belenix/celeste
            "ContentType" : "text/plain",
            "ReplicationParameters" : replicationParams
        }
        celestefs.create(path, attrs=fileAttrs)

    #
    # Repeatedly ingest and fill the file, read it back to compare it with the
    # original, and truncate it.  (If profiling is enabled, each repetition
    # will append information to timingsFile.)
    #
    remainingRepetitions = repetitions
    while repetitions <= 0 or remainingRepetitions > 0:
        pCat = Popen(["/bin/cat", localFile], stdout=PIPE)
        pWrite = celestefs.pwrite(path, 0, stdin=pCat.stdout)
        pWrite.communicate()

        pRead = celestefs.pread(path, 0, -1, stdout=PIPE)
        pCmp = Popen(["/usr/bin/cmp", localFile, "-"], stdin=pRead.stdout,
            stdout=PIPE)
        pCmp.communicate()[0]

        if pCmp.returncode != 0:
            print "%s does not compare identical to %s; exiting" % \
                (path, localFile)

        celestefs.setLength(path, 0)

        remainingRepetitions = remainingRepetitions - 1

    sys.exit(0)
コード例 #2
0
ファイル: celestefsExample.py プロジェクト: belenix/celeste
    statOutput = celestefs.stat(celesteFilePath2, options=["-s"])
    fileSize = int(statOutput.split()[1])
    print >> stderr, "file size: %d" % fileSize

    if fileSize == 0:
        celestefs.write(inFileName, celesteFilePath2, 0, bufferSize=134217728)

        statOutput = celestefs.stat(celesteFilePath2, options=["-s"])
        fileSize = int(statOutput.split()[1])
        print >> stderr, "file size now: %d" % fileSize

    #
    # Read the file and compare it to the local file we used to initialize
    # it.
    #
    pRead = celestefs.pread(celesteFilePath2, 0, -1, stdout=PIPE)
    pCmp = Popen(["/usr/bin/cmp", inFileName, "-"], stdin=pRead.stdout,
        stdout=PIPE)
    print pCmp.communicate()[0]

    #
    # Write the file's contents if necessary.
    #
    statOutput = celestefs.stat(celesteFilePath, options=["-s"])
    fileSize = int(statOutput.split()[1])
    print >> stderr, "file size: %d" % fileSize

    if fileSize == 0:
        pCat = Popen(["/bin/cat", inFileName], stdout=PIPE)
        pWrite = celestefs.pwrite(celesteFilePath, 0, stdin=pCat.stdout,
            bufferSize=134217728)
コード例 #3
0
ファイル: offsetTest.py プロジェクト: belenix/celeste
        c.create(filename, contentType="text/plain", attrs=createAttrs)
    else:
        c.setLength(filename, 0)

    #
    # Write a sequence of characters that give clues to their offsets in the
    # file.
    #
    p = c.pwrite(filename)
    p.stdin.write("0123456789012345678901234567890123456789")
    p.communicate()

    #
    # See what we have so far.
    #
    p = c.pread(filename)
    output = p.communicate()[0]
    print '%s\'s contents: "%s"' % (filename, output)

    #
    # Now for the test proper.  Overwrite some of the data in the middle with
    # something else.
    #
    p = c.pwrite(filename, offset=5)
    p.stdin.write("@five?")
    p.communicate()

    #
    # Report on the results.
    #
    p = c.pread(filename)