Move or rename this node. Moves a node into a new parent group, or changes the name of the node. `newparent` can be a Group object (see :ref:`GroupClassDescr`) or a pathname in string form. If it is not specified or `None`, the current parent group is chosen as the n
(
self,
newparent: Group | str | None = None,
newname: str | None = None,
overwrite: bool = False,
createparents: bool = False,
)
| 601 | self._f_move(newname=newname, overwrite=overwrite) |
| 602 | |
| 603 | def _f_move( |
| 604 | self, |
| 605 | newparent: Group | str | None = None, |
| 606 | newname: str | None = None, |
| 607 | overwrite: bool = False, |
| 608 | createparents: bool = False, |
| 609 | ) -> None: |
| 610 | """Move or rename this node. |
| 611 | |
| 612 | Moves a node into a new parent group, or changes the name of the |
| 613 | node. `newparent` can be a Group object (see :ref:`GroupClassDescr`) |
| 614 | or a pathname in string form. If it is not specified or `None`, the |
| 615 | current parent group is chosen as the new parent. newname must be |
| 616 | a string with a new name. |
| 617 | If it is not specified or None, the current name is chosen as the |
| 618 | new name. If `createparents` is true, the needed groups for the |
| 619 | given new parent group path to exist will be created. |
| 620 | |
| 621 | Moving a node across databases is not allowed, nor it is moving a node |
| 622 | *into* itself. These result in a NodeError. However, moving a node |
| 623 | *over* itself is allowed and simply does nothing. Moving over another |
| 624 | existing node is similarly not allowed, unless the optional overwrite |
| 625 | argument is true, in which case that node is recursively removed before |
| 626 | moving. |
| 627 | |
| 628 | Usually, only the first argument will be used, effectively moving the |
| 629 | node to a new location without changing its name. Using only the |
| 630 | second argument is equivalent to renaming the node in place. |
| 631 | |
| 632 | """ |
| 633 | self._g_check_open() |
| 634 | file_ = self._v_file |
| 635 | oldparent = self._v_parent |
| 636 | oldname = self._v_name |
| 637 | |
| 638 | # Set default arguments. |
| 639 | if newparent is None and newname is None: |
| 640 | raise NodeError( |
| 641 | "you should specify at least " |
| 642 | "a ``newparent`` or a ``newname`` parameter" |
| 643 | ) |
| 644 | if newparent is None: |
| 645 | newparent = oldparent |
| 646 | if newname is None: |
| 647 | newname = oldname |
| 648 | |
| 649 | # Get destination location. |
| 650 | if hasattr(newparent, "_v_file"): # from node |
| 651 | newfile = newparent._v_file |
| 652 | newpath = newparent._v_pathname |
| 653 | elif hasattr(newparent, "startswith"): # from path |
| 654 | newfile = file_ |
| 655 | newpath = newparent |
| 656 | else: |
| 657 | raise TypeError( |
| 658 | f"new parent is not a node nor a path: {newparent!r}" |
| 659 | ) |
| 660 |
no test coverage detected