features-42
deadc0de6 4 months ago
parent 340ab62d77
commit ea0cb2f9da

@ -170,14 +170,15 @@ def cmd_du(args: Dict[str, Any],
top: NodeTop) -> List[NodeAny]:
"""du action"""
path = path_to_search_all(args['<path>'])
found = noder.du(top,
path,
raw=args['--raw-size'])
found = noder.diskusage(top,
path,
raw=args['--raw-size'])
if not found:
path = args['<path>']
Logger.err(f'\"{path}\": nothing found')
return found
def cmd_ls(args: Dict[str, Any],
noder: Noder,
top: NodeTop) -> List[NodeAny]:
@ -253,6 +254,7 @@ def cmd_fixsizes(top: NodeTop,
recursively their size
"""
noder.fixsizes(top)
catalog.save(top)
Logger.info('sizes fixed')

@ -517,6 +517,7 @@ class Noder:
def _callback_find_name(self, term: str, only_dir: bool) -> Any:
"""callback for finding files"""
def find_name(node: NodeAny) -> bool:
typcast_node(node)
path = node.get_fullpath()
if node.type == nodes.TYPE_STORAGE:
# ignore storage nodes
@ -549,6 +550,7 @@ class Noder:
# fixsizes
###############################################################
def fixsizes(self, top: NodeTop) -> None:
"""fix node sizes"""
typcast_node(top)
rend = anytree.RenderTree(top)
for _, _, thenode in rend:
@ -582,14 +584,15 @@ class Noder:
else:
# we have a canonical path
self._debug('get ls...')
found = resolv.get(top, path)
typcast_node(found)
if found and found.may_have_children():
foundone = resolv.get(top, path)
cast(NodeAny, foundone)
typcast_node(foundone)
if foundone and foundone.may_have_children():
# let's find its children as well
modpath = os.path.join(path, '*')
found = resolv.glob(top, modpath)
else:
found = [found]
found = [foundone]
if len(found) < 1:
# nothing found
@ -625,12 +628,13 @@ class Noder:
###############################################################
# du
###############################################################
def du(self, top: NodeTop,
path: str,
raw: bool = False) -> List[NodeAny]:
def diskusage(self, top: NodeTop,
path: str,
raw: bool = False) -> List[NodeAny]:
"""disk usage"""
self._debug(f'du walking path: \"{path}\" from \"{top.name}\"')
resolv = anytree.resolver.Resolver('name')
found = []
found: NodeAny
try:
# we have a canonical path
self._debug('get du...')
@ -691,7 +695,7 @@ class Noder:
if thenode.type == nodes.TYPE_DIR:
thenodes.append(thenode)
else:
[thenodes.append(x) for _, _, x in rend]
thenodes = [x for _, _, x in rend]
return sorted(thenodes, key=os_sort_keygen(self._sort))
def _sort_tree(self,

@ -46,10 +46,14 @@ class NodeAny(NodeMixin): # type: ignore
"""generic node"""
def __init__(self, # type: ignore[no-untyped-def]
name=None,
size=None,
parent=None,
children=None):
"""build generic node"""
super().__init__()
self.name = name
self.nodesize = size
self.parent = parent
if children:
self.children = children
@ -76,7 +80,7 @@ class NodeAny(NodeMixin): # type: ignore
typcast_node(self.parent)
ppath = self.parent.get_fullpath()
path = os.path.join(ppath, path)
return path
return str(path)
def get_rec_size(self) -> int:
"""recursively traverse tree and return size"""

@ -6,7 +6,6 @@ Class for printing nodes in csv format
"""
import sys
import os
from typing import List
from catcli.nodes import NodeAny, NodeStorage, TYPE_DIR

@ -1,6 +1,6 @@
"github","storage","","1662","","","","3","0","0",""
"FUNDING.yml","file","github/","17","","","0c6407a84d412c514007313fb3bca4de","","","",""
"codecov.yml","file","github/","104","","","4203204f75b43cd4bf032402beb3359d","","","",""
"workflows","dir","github/","0","","","","2","","",""
"pypi-release.yml","file","github/","691","","","57699a7a6a03e20e864f220e19f8e197","","","",""
"testing.yml","file","github/","850","","","691df1a4d2f254b5cd04c152e7c6ccaf","","","",""
"github","storage","","4865","","","","3","0","0",""
"FUNDING.yml","file","github/FUNDING.yml","17","","","0c6407a84d412c514007313fb3bca4de","","","",""
"codecov.yml","file","github/codecov.yml","104","","","4203204f75b43cd4bf032402beb3359d","","","",""
"workflows","dir","github/workflows","3082","","","","2","","",""
"pypi-release.yml","file","github/workflows/pypi-release.yml","691","","","57699a7a6a03e20e864f220e19f8e197","","","",""
"testing.yml","file","github/workflows/testing.yml","850","","","691df1a4d2f254b5cd04c152e7c6ccaf","","","",""

@ -36,7 +36,7 @@
],
"maccess": 1704320727.2641916,
"name": "workflows",
"size": 0,
"size": 1541,
"type": "dir"
}
],
@ -44,20 +44,22 @@
"name": "github",
"size": 1662,
"total": 0,
"ts": 1704913782,
"ts": 1704922075,
"type": "storage"
},
{
"attr": {
"access": 1704913782,
"access": 1704922075,
"access_version": "0.9.6",
"created": 1704913782,
"created": 1704922075,
"created_version": "0.9.6"
},
"name": "meta",
"size": null,
"type": "meta"
}
],
"name": "top",
"size": null,
"type": "top"
}

@ -1,7 +1,7 @@
top
└── storage: github [nbfiles:3|totsize:1662|free:0.0%|du:0/0|date:2023-03-09 16:20:59]
└── storage: github [nbfiles:3|totsize:4865|free:0.0%|du:0/0|date:2023-03-09 16:20:59]
├── FUNDING.yml 17 2022-10-19 21:00:37 [md5:0c6407a84d412c514007313fb3bca4de]
├── codecov.yml 104 2024-01-03 23:25:10 [md5:4203204f75b43cd4bf032402beb3359d]
└── workflows 0 2024-01-03 23:25:27 [nbfiles:2]
└── workflows 3082 2024-01-03 23:25:27 [nbfiles:2]
├── pypi-release.yml 691 2022-10-19 21:00:37 [md5:57699a7a6a03e20e864f220e19f8e197]
└── testing.yml 850 2024-01-04 22:26:09 [md5:691df1a4d2f254b5cd04c152e7c6ccaf]

Loading…
Cancel
Save