Did I find the right examples for you? yes no      Crawl my project      Python Jobs

All Samples(1)  |  Call(1)  |  Derive(0)  |  Import(0)
Convert a non-BlockFile to a BlockFile, with an optional nodeID/metadata
pair to add.  The file represented by fname will be a BlockFile upon
successful return.
nodeIdAndMeta should be a tuple.  The first element is the nodeID, the
second the metadata.  Metadata should be a dict (client can send arbitrary
dict, but the purpose is to have a key/value pair where the key is the
crc32 checksum of the full metadata, and the value is the chunk of metadata
being stored with this BlockFile)

        def convert(fname, nodeIDandMeta=None):
    """
    Convert a non-BlockFile to a BlockFile, with an optional nodeID/metadata
    pair to add.  The file represented by fname will be a BlockFile upon
    successful return.
    nodeIdAndMeta should be a tuple.  The first element is the nodeID, the
    second the metadata.  Metadata should be a dict (client can send arbitrary
    dict, but the purpose is to have a key/value pair where the key is the
    crc32 checksum of the full metadata, and the value is the chunk of metadata
    being stored with this BlockFile)
    """
    tname = tempfile.mktemp()
    f1 = __builtin__.open(fname, 'rb')
    f2 = __builtin__.open(tname, 'wb')
    size = os.stat(fname)[stat.ST_SIZE]
    f2.write(struct.pack('=Q',size))
    while 1:
        buf = f1.read()
        if buf == "":
            break
        f2.write(buf)
    if nodeIDandMeta == None:
        l = {} 
    else:
        if len(nodeIDandMeta) != 2:
            raise IOError("invalid nodeID/metadata pair")
        nodeID = nodeIDandMeta[0]
        meta = nodeIDandMeta[1]
        if not isinstance(meta, dict):
            raise IOError("invalid metadata (should be a dict)")
        l = {} 
        l[nodeID] = meta
    f2.write(fencode(l))
    f2.close()
    f1.close()
    os.rename(tname, fname)
        


src/f/l/flud-HEAD/flud/protocol/ServerPrimitives.py   flud(Download)
                    loggerstor.debug("storing %s" % fname)
                    os.rename(tmpfile, fname)
                    BlockFile.convert(fname, (int(nodeID,16), {metakey: meta}))
 
        loggerstor.debug("successful STORE for %s" % filekey)