From 205f4e2148b6a93a7aa9b8c1978f746e800b726c Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Sun, 21 May 2023 20:54:10 +0200 Subject: [PATCH 1/4] fix bug #34 --- catcli/noder.py | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/catcli/noder.py b/catcli/noder.py index c81dae0..b53e7ee 100644 --- a/catcli/noder.py +++ b/catcli/noder.py @@ -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'): From 226448b334e262a5a8db508484d6c6df83262186 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Sun, 21 May 2023 20:54:22 +0200 Subject: [PATCH 2/4] add test for #34 --- tests-ng/find.sh | 51 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100755 tests-ng/find.sh diff --git a/tests-ng/find.sh b/tests-ng/find.sh new file mode 100755 index 0000000..e8201a9 --- /dev/null +++ b/tests-ng/find.sh @@ -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 From d00964483e8b1674832e7b5e5a44ebaaea210282 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Sun, 21 May 2023 20:54:37 +0200 Subject: [PATCH 3/4] fix tests --- tests-ng/compare.sh | 17 +---------------- tests-ng/update.sh | 17 +---------------- tests.sh | 2 -- 3 files changed, 2 insertions(+), 34 deletions(-) diff --git a/tests-ng/compare.sh b/tests-ng/compare.sh index 32e383c..c7a68b3 100755 --- a/tests-ng/compare.sh +++ b/tests-ng/compare.sh @@ -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)" diff --git a/tests-ng/update.sh b/tests-ng/update.sh index 26964bf..8a93892 100755 --- a/tests-ng/update.sh +++ b/tests-ng/update.sh @@ -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)" diff --git a/tests.sh b/tests.sh index 31bffe3..366d84e 100755 --- a/tests.sh +++ b/tests.sh @@ -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 From a16838299f13bc775c299c8d5fff3092ae838627 Mon Sep 17 00:00:00 2001 From: deadc0de6 Date: Sun, 21 May 2023 20:54:54 +0200 Subject: [PATCH 4/4] debug logs --- catcli/catalog.py | 2 +- catcli/catcli.py | 5 ++++- catcli/nodes.py | 2 +- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/catcli/catalog.py b/catcli/catalog.py index 65993d1..eee2704 100644 --- a/catcli/catalog.py +++ b/catcli/catalog.py @@ -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}') diff --git a/catcli/catcli.py b/catcli/catcli.py index bff10c5..1f2d066 100755 --- a/catcli/catcli.py +++ b/catcli/catcli.py @@ -210,12 +210,15 @@ def cmd_find(args: Dict[str, Any], raw = args['--raw-size'] script = args['--script'] search_for = args[''] + 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 diff --git a/catcli/nodes.py b/catcli/nodes.py index e8f30ba..0f96c45 100644 --- a/catcli/nodes.py +++ b/catcli/nodes.py @@ -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: