From 001c03ca28a9dc543518b85e8986f1293fdb56c5 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Sat, 22 Jul 2023 22:48:20 +0200 Subject: [PATCH] fix casting --- catcli/noder.py | 6 +++--- catcli/nodes.py | 52 ++++++++++++------------------------------------- 2 files changed, 15 insertions(+), 43 deletions(-) diff --git a/catcli/noder.py b/catcli/noder.py index 68eb1b3..cfd21da 100644 --- a/catcli/noder.py +++ b/catcli/noder.py @@ -87,8 +87,8 @@ class Noder: try: bpath = os.path.basename(path) the_node = resolv.get(top, bpath) - node = typcast_node(the_node) - return cast(NodeAny, node) + typcast_node(the_node) + return cast(NodeAny, the_node) except anytree.resolver.ChildResolverError: if not quiet: Logger.err(f'No node at path \"{bpath}\"') @@ -298,7 +298,7 @@ class Noder: """remove any node not flagged and clean flags""" cnt = 0 for node in anytree.PreOrderIter(top): - node = typcast_node(node) + typcast_node(node) if node.type not in [nodes.TYPE_DIR, nodes.TYPE_FILE]: continue if self._clean(node): diff --git a/catcli/nodes.py b/catcli/nodes.py index d2a2772..b622410 100644 --- a/catcli/nodes.py +++ b/catcli/nodes.py @@ -21,48 +21,20 @@ NAME_TOP = 'top' NAME_META = 'meta' -def typcast_node(node: Any) -> Any: +def typcast_node(node: Any) -> None: """typecast node to its sub type""" if node.type == TYPE_TOP: - return NodeTop(node.name, node.children) - if node.type == TYPE_FILE: - return NodeFile(node.name, - node.relpath, - node.nodesize, - node.md5, - node.maccess, - node.parent, - node.children) - if node.type == TYPE_DIR: - return NodeDir(node.name, - node.relpath, - node.nodesize, - node.maccess, - node.parent, - node.children) - if node.type == TYPE_ARCHIVED: - return NodeArchived(node.name, - node.relpath, - node.nodesize, - node.md5, - node.archive, - node.parent, - node.children) - if node.type == TYPE_STORAGE: - return NodeStorage(node.name, - node.free, - node.total, - node.nodesize, - node.ts, - node.attr, - node.parent, - node.children) - if node.type == TYPE_META: - return NodeMeta(node.name, - node.attr, - node.parent, - node.children) - return node + node.__class__ = NodeTop + elif node.type == TYPE_FILE: + node.__class__ = NodeFile + elif node.type == TYPE_DIR: + node.__class__ = NodeDir + elif node.type == TYPE_ARCHIVED: + node.__class__ = NodeArchived + elif node.type == TYPE_STORAGE: + node.__class__ = NodeStorage + elif node.type == TYPE_META: + node.__class__ = NodeMeta class NodeAny(NodeMixin): # type: ignore