#NEWLINE# def save_to_filenode( h5file , filename , where , name = None , overwrite = False , title = '' , filters = None ) : #NEWLINE# #INDENT# "Save a file's contents to a filenode inside a PyTables file.\n\n    .. versionadded:: 3.2\n\n    Parameters\n    ----------\n    h5file\n      The PyTables file to be written to; can be either a string\n      giving the file's location or a :class:`File` object.  If a file\n      with name *h5file* already exists, it will be opened in\n      mode ``a``.\n\n    filename\n      Path of the file which shall be stored within the PyTables file.\n\n    where, name\n      Location of the filenode where the data shall be stored.  If\n      *name* is not given, and *where* is either a :class:`Group`\n      object or a string ending on ``/``, the leaf name will be set to\n      the file name of *filename*.  The *name* will be modified to\n      adhere to Python's natural naming convention; the original\n      filename will be preserved in the filenode's *_filename*\n      attribute.\n\n    overwrite\n      Whether or not a possibly existing filenode of the specified\n      name shall be overwritten.\n\n    title\n       A description for this node (it sets the ``TITLE`` HDF5\n       attribute on disk).\n\n    filters\n       An instance of the :class:`Filters` class that provides\n       information about the desired I/O filters to be applied\n       during the life of this object.\n\n    " #NEWLINE# if ( not os . access ( filename , os . R_OK ) ) : #NEWLINE# #INDENT# raise IOError ( ( "The file '%s' could not be read" % filename ) ) #NEWLINE# #UNINDENT# if ( isinstance ( h5file , tables . file . File ) and ( h5file . mode == 'r' ) ) : #NEWLINE# #INDENT# raise IOError ( ( "The file '%s' is opened read-only" % h5file . filename ) ) #NEWLINE# #UNINDENT# if ( name is None ) : #NEWLINE# #INDENT# if isinstance ( where , tables . group . Group ) : #NEWLINE# #INDENT# name = os . path . split ( filename ) [ 1 ] #NEWLINE# #UNINDENT# if isinstance ( where , string_types ) : #NEWLINE# #INDENT# if where . endswith ( '/' ) : #NEWLINE# #INDENT# name = os . path . split ( filename ) [ 1 ] #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# nodepath = where . split ( '/' ) #NEWLINE# where = ( '/' + '/' . join ( nodepath [ : ( - 1 ) ] ) ) #NEWLINE# name = nodepath [ ( - 1 ) ] #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# if ( not tables . path . _python_id_re . match ( name ) ) : #NEWLINE# #INDENT# name = re . sub ( '(?![a-zA-Z0-9_]).' , '_' , re . sub ( '^(?![a-zA-Z_]).' , '_' , name ) ) #NEWLINE# #UNINDENT# new_h5file = ( not isinstance ( h5file , tables . file . File ) ) #NEWLINE# f = ( tables . File ( h5file , 'a' ) if new_h5file else h5file ) #NEWLINE# try : #NEWLINE# #INDENT# n = f . get_node ( where = where , name = name ) #NEWLINE# if ( not overwrite ) : #NEWLINE# #INDENT# if new_h5file : #NEWLINE# #INDENT# f . close ( ) #NEWLINE# #UNINDENT# raise IOError ( ( "Specified node already exists in file '%s'" % f . filename ) ) #NEWLINE# #UNINDENT# #UNINDENT# except tables . NoSuchNodeError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# with open ( where , 'rb' ) as fd : #NEWLINE# #INDENT# data = fd . read ( ) #NEWLINE# #UNINDENT# try : #NEWLINE# #INDENT# f . remove_node ( where = where , name = name ) #NEWLINE# #UNINDENT# except tables . NoSuchNodeError : #NEWLINE# #INDENT# pass #NEWLINE# #UNINDENT# fnode = new_node ( f , where = where , name = name , title = title , filters = filters ) #NEWLINE# fnode . write ( data ) #NEWLINE# fnode . attrs . _filename = os . path . split ( filename ) [ 1 ] #NEWLINE# fnode . close ( ) #NEWLINE# if new_h5file : #NEWLINE# #INDENT# f . close ( )