MCPcopy Create free account
hub / github.com/PyTables/PyTables / copy_file

Method copy_file

tables/file.py:2116–2190  ·  view source on GitHub ↗

Copy the contents of this file to dstfilename. Parameters ---------- dstfilename : str A path string indicating the name of the destination file. If it already exists, the copy will fail with an IOError, unless the overwrite argument is tr

(
        self, dstfilename: str, overwrite: bool = False, **kwargs
    )

Source from the content-addressed store, hash-verified

2114 )
2115
2116 def copy_file(
2117 self, dstfilename: str, overwrite: bool = False, **kwargs
2118 ) -> None:
2119 """Copy the contents of this file to dstfilename.
2120
2121 Parameters
2122 ----------
2123 dstfilename : str
2124 A path string indicating the name of the destination file. If
2125 it already exists, the copy will fail with an IOError, unless
2126 the overwrite argument is true.
2127 overwrite : bool, optional
2128 If true, the destination file will be overwritten if it already
2129 exists. In this case, the destination file must be closed, or
2130 errors will occur. Defaults to False.
2131 kwargs
2132 Additional keyword arguments discussed below.
2133
2134 Notes
2135 -----
2136 Additional keyword arguments may be passed to customize the
2137 copying process. For instance, title and filters may be changed,
2138 user attributes may be or may not be copied, data may be
2139 sub-sampled, stats may be collected, etc. Arguments unknown to
2140 nodes are simply ignored. Check the documentation for copying
2141 operations of nodes to see which options they support.
2142
2143 In addition, it recognizes the names of parameters present in
2144 :file:`tables/parameters.py` as additional keyword arguments.
2145 See :ref:`parameter_files` for a detailed info on the supported
2146 parameters.
2147
2148 Copying a file usually has the beneficial side effect of
2149 creating a more compact and cleaner version of the original
2150 file.
2151
2152 """
2153 self._check_open()
2154
2155 # Check that we are not treading our own shoes
2156 if Path(self.filename).resolve() == Path(dstfilename).resolve():
2157 raise OSError("You cannot copy a file over itself")
2158
2159 # Compute default arguments.
2160 # These are *not* passed on.
2161 filters = kwargs.pop("filters", None)
2162 if filters is None:
2163 # By checking the HDF5 attribute, we avoid setting filters
2164 # in the destination file if not explicitly set in the
2165 # source file. Just by assigning ``self.filters`` we would
2166 # not be able to tell.
2167 filters = getattr(self.root._v_attrs, "FILTERS", None)
2168 copyuserattrs = kwargs.get("copyuserattrs", True)
2169 title = kwargs.pop("title", self.title)
2170
2171 if Path(dstfilename).is_file() and not overwrite:
2172 raise OSError(
2173 f"file ``{dstfilename}`` already exists; you may want to "

Callers 9

copy_fileFunction · 0.80
setUpMethod · 0.80
test01Method · 0.80
test00_overwriteMethod · 0.80
test00b_firstclassMethod · 0.80
test01_copyMethod · 0.80
test02_AttrsMethod · 0.80
_test_copyFileMethod · 0.80
copy2Function · 0.80

Calls 7

_check_openMethod · 0.95
open_fileFunction · 0.85
popMethod · 0.80
_f_copy_childrenMethod · 0.80
getMethod · 0.45
_f_copyMethod · 0.45
closeMethod · 0.45

Tested by 7

setUpMethod · 0.64
test01Method · 0.64
test00_overwriteMethod · 0.64
test00b_firstclassMethod · 0.64
test01_copyMethod · 0.64
test02_AttrsMethod · 0.64
_test_copyFileMethod · 0.64