Skip to content
This repository has been archived by the owner on Jul 11, 2024. It is now read-only.

Commit

Permalink
linting
Browse files Browse the repository at this point in the history
  • Loading branch information
deadc0de6 committed Jan 10, 2024
1 parent 340ab62 commit ea0cb2f
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 26 deletions.
8 changes: 5 additions & 3 deletions catcli/catcli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down Expand Up @@ -253,6 +254,7 @@ def cmd_fixsizes(top: NodeTop,
recursively their size
"""
noder.fixsizes(top)
catalog.save(top)
Logger.info('sizes fixed')


Expand Down
22 changes: 13 additions & 9 deletions catcli/noder.py
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,7 @@ def find(self, top: NodeTop,
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
Expand Down Expand Up @@ -549,6 +550,7 @@ def find_name(node: NodeAny) -> bool:
# fixsizes
###############################################################
def fixsizes(self, top: NodeTop) -> None:
"""fix node sizes"""
typcast_node(top)
rend = anytree.RenderTree(top)
for _, _, thenode in rend:
Expand Down Expand Up @@ -582,14 +584,15 @@ def list(self, top: NodeTop,
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
Expand Down Expand Up @@ -625,12 +628,13 @@ def list(self, top: NodeTop,
###############################################################
# 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...')
Expand Down Expand Up @@ -691,7 +695,7 @@ def _get_entire_tree(self, start: NodeAny,
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,
Expand Down
6 changes: 5 additions & 1 deletion catcli/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -76,7 +80,7 @@ def get_fullpath(self) -> str:
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"""
Expand Down
1 change: 0 additions & 1 deletion catcli/printer_csv.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
"""

import sys
import os
from typing import List

from catcli.nodes import NodeAny, NodeStorage, TYPE_DIR
Expand Down
12 changes: 6 additions & 6 deletions tests-ng/assets/github.catalog.csv.txt
Original file line number Diff line number Diff line change
@@ -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","","","",""
10 changes: 6 additions & 4 deletions tests-ng/assets/github.catalog.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,28 +36,30 @@
],
"maccess": 1704320727.2641916,
"name": "workflows",
"size": 0,
"size": 1541,
"type": "dir"
}
],
"free": 0,
"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"
}
4 changes: 2 additions & 2 deletions tests-ng/assets/github.catalog.native.txt
Original file line number Diff line number Diff line change
@@ -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]

0 comments on commit ea0cb2f

Please sign in to comment.