Copy a leaf node.
(
srcfile,
dstfile,
srcnode,
dstnode,
title,
filters,
copyuserattrs,
overwritefile,
overwrtnodes,
stats,
start,
stop,
step,
chunkshape,
sortby,
check_CSI, # noqa: N803
propindexes,
upgradeflavors,
allow_padding,
)
| 72 | |
| 73 | |
| 74 | def copy_leaf( |
| 75 | srcfile, |
| 76 | dstfile, |
| 77 | srcnode, |
| 78 | dstnode, |
| 79 | title, |
| 80 | filters, |
| 81 | copyuserattrs, |
| 82 | overwritefile, |
| 83 | overwrtnodes, |
| 84 | stats, |
| 85 | start, |
| 86 | stop, |
| 87 | step, |
| 88 | chunkshape, |
| 89 | sortby, |
| 90 | check_CSI, # noqa: N803 |
| 91 | propindexes, |
| 92 | upgradeflavors, |
| 93 | allow_padding, |
| 94 | ): |
| 95 | """Copy a leaf node.""" |
| 96 | # Open the source file |
| 97 | srcfileh = tb.open_file(srcfile, "r", allow_padding=allow_padding) |
| 98 | # Get the source node (that should exist) |
| 99 | srcnode = srcfileh.get_node(srcnode) |
| 100 | |
| 101 | # Get the destination node and its parent |
| 102 | last_slash = dstnode.rindex("/") |
| 103 | if last_slash == len(dstnode) - 1: |
| 104 | # print("Detected a trailing slash in destination node. " |
| 105 | # "Interpreting it as a destination group.") |
| 106 | dstgroup = dstnode[:-1] |
| 107 | elif last_slash > 0: |
| 108 | dstgroup = dstnode[:last_slash] |
| 109 | else: |
| 110 | dstgroup = "/" |
| 111 | dstleaf = dstnode[last_slash + 1 :] |
| 112 | if dstleaf == "": |
| 113 | dstleaf = srcnode.name |
| 114 | # Check whether the destination group exists or not |
| 115 | if Path(dstfile).is_file() and not overwritefile: |
| 116 | dstfileh = tb.open_file( |
| 117 | dstfile, |
| 118 | "a", |
| 119 | pytables_sys_attrs=createsysattrs, |
| 120 | allow_padding=allow_padding, |
| 121 | ) |
| 122 | try: |
| 123 | dstgroup = dstfileh.get_node(dstgroup) |
| 124 | except Exception: |
| 125 | # The dstgroup does not seem to exist. Try creating it. |
| 126 | dstgroup = newdst_group(dstfileh, dstgroup, title, filters) |
| 127 | else: |
| 128 | # The node exists, but it is really a group? |
| 129 | if not isinstance(dstgroup, tb.group.Group): |
| 130 | # No. Should we overwrite it? |
| 131 | if overwrtnodes: |
no test coverage detected