Merge pull request #35 from deadc0de6/fix-34

Fix 34
fix-36
deadc0de 12 months ago committed by GitHub
commit 6321d04417
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -94,7 +94,7 @@ class Catalog:
def _restore_json(self, string: str) -> Optional[NodeTop]:
"""restore the tree from json"""
imp = JsonImporter()
self._debug(f'import from string: {string}')
self._debug('import from string...')
root = imp.import_(string)
self._debug(f'Catalog imported from json \"{self.path}\"')
self._debug(f'root imported: {root}')

@ -210,12 +210,15 @@ def cmd_find(args: Dict[str, Any],
raw = args['--raw-size']
script = args['--script']
search_for = args['<term>']
if args['--verbose']:
Logger.debug(f'search for \"{search_for}\" under \"{top.name}\"')
found = noder.find_name(top, search_for,
script=script,
startnode=startpath,
only_dir=directory,
parentfromtree=fromtree,
fmt=fmt, raw=raw)
fmt=fmt,
raw=raw)
return found

@ -582,8 +582,7 @@ class Noder:
start = self.get_node(top, startnode)
filterfunc = self._callback_find_name(key, only_dir)
found = anytree.findall(start, filter_=filterfunc)
nbfound = len(found)
self._debug(f'found {nbfound} node(s)')
self._debug(f'found {len(found)} node(s)')
# compile found nodes
paths = {}
@ -591,10 +590,14 @@ class Noder:
item.name = fix_badchars(item.name)
if hasattr(item, 'relpath'):
item.relpath = fix_badchars(item.relpath)
storage = self._get_storage(item)
if parentfromtree:
paths[self._get_parents(item)] = item
parent = self._get_parents(item)
key = f'{storage}/{parent}/{item.relpath}'
paths[parent] = item
else:
paths[item.relpath] = item
key = f'{storage}/{item.path}'
paths[key] = item
# handle fzf mode
if fmt.startswith('fzf'):

@ -38,7 +38,7 @@ class NodeAny(NodeMixin): # type: ignore
if self.children:
ret += '\n'
for child in self.children:
ret += ' child => ' + str(child)
ret += f' child => {child}\n'
return ret
def __str__(self) -> str:

@ -2,30 +2,15 @@
# author: deadc0de6 (https://github.com/deadc0de6)
# Copyright (c) 2023, deadc0de6
# exit on first error
set -e
# get current path
rl="readlink -f"
if ! ${rl} "${0}" >/dev/null 2>&1; then
rl="realpath"
if ! command -v ${rl}; then
echo "\"${rl}\" not found !" && exit 1
fi
fi
cur=$(dirname "$(${rl} "${0}")")
# pivot
cur=$(cd "$(dirname "${0}")" && pwd)
prev="${cur}/.."
cd "${prev}"
# coverage
#export PYTHONPATH=".:${PYTHONPATH}"
bin="python3 -m catcli.catcli"
if command -v coverage 2>/dev/null; then
bin="coverage run -p --source=catcli -m catcli.catcli"
#bin="coverage run -p --source=${prev}/catcli -m catcli.catcli"
fi
echo "current dir: $(pwd)"

@ -0,0 +1,51 @@
#!/usr/bin/env bash
# author: deadc0de6 (https://github.com/deadc0de6)
# Copyright (c) 2023, deadc0de6
set -e
cur=$(cd "$(dirname "${0}")" && pwd)
prev="${cur}/.."
cd "${prev}"
# coverage
bin="python3 -m catcli.catcli"
if command -v coverage 2>/dev/null; then
bin="coverage run -p --source=catcli -m catcli.catcli"
fi
echo "current dir: $(pwd)"
echo "pythonpath: ${PYTHONPATH}"
echo "bin: ${bin}"
${bin} --version
# get the helpers
# shellcheck source=tests-ng/helper
source "${cur}"/helper
echo -e "$(tput setaf 6)==> RUNNING $(basename "${BASH_SOURCE[0]}") <==$(tput sgr0)"
##########################################################
# the test
##########################################################
# create temp dirs
tmpd=$(mktemp -d)
clear_on_exit "${tmpd}"
catalog="${tmpd}/catalog"
# index
${bin} -B index -c -f --catalog="${catalog}" github1 .github
${bin} -B index -c -f --catalog="${catalog}" github2 .github
#cat "${catalog}"
echo ""
${bin} -B find --catalog="${catalog}" testing.yml
cnt=$(${bin} -B find --catalog="${catalog}" testing.yml | wc -l)
[ "${cnt}" != "2" ] && echo "should return 2!" && exit 1
# the end
echo ""
echo "test \"$(basename "$0")\" success"
cd "${cur}"
exit 0

@ -2,30 +2,15 @@
# author: deadc0de6 (https://github.com/deadc0de6)
# Copyright (c) 2021, deadc0de6
# exit on first error
set -e
# get current path
rl="readlink -f"
if ! ${rl} "${0}" >/dev/null 2>&1; then
rl="realpath"
if ! command -v ${rl}; then
echo "\"${rl}\" not found !" && exit 1
fi
fi
cur=$(dirname "$(${rl} "${0}")")
# pivot
cur=$(cd "$(dirname "${0}")" && pwd)
prev="${cur}/.."
cd "${prev}"
# coverage
#export PYTHONPATH=".:${PYTHONPATH}"
bin="python3 -m catcli.catcli"
if command -v coverage 2>/dev/null; then
bin="coverage run -p --source=catcli -m catcli.catcli"
#bin="coverage run -p --source=${prev}/catcli -m catcli.catcli"
fi
echo "current dir: $(pwd)"

@ -45,8 +45,6 @@ pylint -sn \
--disable=R0022 \
catcli/
# R0801: Similar lines in 2 files
# W0212: Access to a protected member
# R0914: Too many local variables

Loading…
Cancel
Save