Merge pull request #40 from deadc0de6/fix-39

Fix 39
pull/47/head
deadc0de 9 months ago committed by GitHub
commit 1c2d5f378e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -14,7 +14,8 @@ import anytree # type: ignore
# local imports
from catcli import nodes
from catcli.nodes import NodeAny, NodeStorage, \
NodeTop, NodeFile, NodeArchived, NodeDir, NodeMeta
NodeTop, NodeFile, NodeArchived, NodeDir, NodeMeta, \
typcast_node
from catcli.utils import size_to_str, epoch_to_str, md5sum, fix_badchars
from catcli.logger import Logger
from catcli.nodeprinter import NodePrinter
@ -86,6 +87,7 @@ class Noder:
try:
bpath = os.path.basename(path)
the_node = resolv.get(top, bpath)
typcast_node(the_node)
return cast(NodeAny, the_node)
except anytree.resolver.ChildResolverError:
if not quiet:
@ -296,6 +298,7 @@ class Noder:
"""remove any node not flagged and clean flags"""
cnt = 0
for node in anytree.PreOrderIter(top):
typcast_node(node)
if node.type not in [nodes.TYPE_DIR, nodes.TYPE_FILE]:
continue
if self._clean(node):

@ -21,6 +21,22 @@ NAME_TOP = 'top'
NAME_META = 'meta'
def typcast_node(node: Any) -> None:
"""typecast node to its sub type"""
if node.type == TYPE_TOP:
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
"""generic node"""

@ -123,7 +123,7 @@ class TestUpdate(unittest.TestCase):
noder.print_tree(top)
# explore the top node to find all nodes
self.assertTrue(len(top.children) == 1)
self.assertEqual(len(top.children), 1)
storage = top.children[0]
self.assertTrue(len(storage.children) == 8)

Loading…
Cancel
Save