예제 #1
0
def to_hdf(node, filename):
    """ Writes the report in HDF format. """
    tables = get_tables()
    tmp_filename = filename + '.active'
    filters = tables.Filters(complevel=9, shuffle=False,
                            fletcher32=True, complib='zlib')
    hf = tables.openFile(tmp_filename, 'w', filters=filters)
    node_to_hdf(hf, hf.root, node)    

    hf.close()
    os.rename(tmp_filename, filename)
예제 #2
0
def to_hdf(node, filename):
    """ Writes the report in HDF format. """
    tables = get_tables()
    tmp_filename = filename + ".active"
    filters = tables.Filters(
        complevel=9, shuffle=False, fletcher32=True, complib="zlib"
    )
    hf = tables.openFile(tmp_filename, "w", filters=filters)
    node_to_hdf(hf, hf.root, node)

    hf.close()
    os.rename(tmp_filename, filename)
예제 #3
0
def write_python_data(parent, name, mime, data):
    tables = get_tables()
    from tables.flavor import flavor_of

    hf = parent._v_file
    group = hf.createGroup(parent, name)
    hf.createArray(group, "mime", mime)
    try:
        flavor_of(data)
        ok_pytables = True
    except:
        ok_pytables = False

    # 2014-01-02 XXX this is a hack
    if data == []:
        ok_pytables = False

    if ok_pytables:
        try:
            hf.createArray(group, "value", data)
        except:
            msg = "Error while writing python data"
            msg += "\n parent: %s" % parent
            msg += "\n name: %s" % name
            msg += "\n mime: %s" % mime
            msg += "\n data: %s" % describe_type(data)
            msg += "\n       %s" % describe_value(data)
            msg += "\n flavor: %s" % flavor_of(data)
            msg += "\nraw:\n%s" % data.__repr__()
            logger.error(msg)
            raise
        serialized = "pytables"
    else:
        serialized = "pickle"
        s = StringIO()
        cPickle.dump(data, s, protocol=2)
        hf.createVLArray(group, "pickle", tables.VLStringAtom(), filters=None)
        group.pickle.append(s.getvalue())
    group._v_attrs["reprep_data_format"] = serialized
예제 #4
0
def write_python_data(parent, name, mime, data):
    tables = get_tables()
    from tables.flavor import flavor_of
    hf = parent._v_file
    group = hf.createGroup(parent, name)
    hf.createArray(group, 'mime', mime)
    try:
        flavor_of(data)
        ok_pytables = True
    except:
        ok_pytables = False
    
    # 2014-01-02 XXX this is a hack
    if data == []:
        ok_pytables = False
        
    if ok_pytables: 
        try:
            hf.createArray(group, 'value', data)
        except:
            msg = 'Error while writing python data'
            msg += '\n parent: %s' % parent
            msg += '\n name: %s' % name
            msg += '\n mime: %s' % mime
            msg += '\n data: %s' % describe_type(data)
            msg += '\n       %s' % describe_value(data)
            msg += '\n flavor: %s' % flavor_of(data)
            msg += '\nraw:\n%s' % data.__repr__()
            logger.error(msg)
            raise
        serialized = 'pytables'
    else:
        serialized = 'pickle'
        s = StringIO()
        cPickle.dump(data, s, protocol=2)
        hf.createVLArray(group, 'pickle', tables.VLStringAtom(), filters=None)
        group.pickle.append(s.getvalue())    
    group._v_attrs['reprep_data_format'] = serialized