vfind command

This commit is contained in:
Amber 2024-01-29 14:07:09 +01:00
parent bd2eef0cf7
commit 60ccd874df
9 changed files with 50 additions and 7 deletions

Binary file not shown.

Binary file not shown.

24
src/cmdline_parser.py Normal file
View File

@ -0,0 +1,24 @@
import argparse
from pathlib import Path
cmd_parser = argparse.ArgumentParser(
prog='vfind',
description='A visual version of unix find command in which the results are shown in a tree',
epilog="Thanks for using it! :)",
)
cmd_parser.add_argument("path")
cmd_parser.add_argument("pattern")
# if -s is found in the command line cmd_args.show_children_nodes is True
cmd_parser.add_argument("-s", "--show-children-nodes", action="store_true")
# start the command line parsing
cmd_args = cmd_parser.parse_args()
p = cmd_args.path
path = Path(p)
if not path.exists():
print(f'Path: {p} dont\' exists')
raise SystemExit(1)

View File

@ -1,7 +1,7 @@
import os
from colors import RED, YELLOW, GREEN, CYAN , BLUE, PURPLE
from src.colors import RED, YELLOW, GREEN, CYAN , BLUE, PURPLE
import tree_repr as _tree_repr
import src.tree_repr as _tree_repr
class NerdTree():
'''

View File

@ -1,5 +1,5 @@
from colors import RED, YELLOW, GREEN, CYAN , BLUE, PURPLE
from tree import NerdTree
from src.colors import RED, YELLOW, GREEN, CYAN , BLUE, PURPLE
from src.tree import NerdTree
class NerdTreeFind(NerdTree):
'''
@ -8,11 +8,12 @@ class NerdTreeFind(NerdTree):
@param opts dict: the opts for the tree representation
'''
def __init__(self, startpath, opts={}):
def __init__(self, startpath, opts={}, find_opts={}):
self.item_name = ''
self.results = []
## computed tree for find
self.json_tree_find = {}
self.find_opts = find_opts
NerdTree.__init__(self, startpath, opts=opts)
def find_node_recursively(self, node):
@ -63,7 +64,7 @@ class NerdTreeFind(NerdTree):
'''
results = self.find_node()
dont_show_children_nodes = self.find_opts['dont_show_children_nodes'] if self.find_opts.get('dont_show_children_nodes') else False
dont_show_children_nodes = self.find_opts['dont_show_children_nodes'] if self.find_opts.get('dont_show_children_nodes') is not None else False
if not results:
return {}

View File

@ -1,6 +1,6 @@
import os
from colors import RED, YELLOW, GREEN, CYAN , BLUE, PURPLE
# from colors import RED, YELLOW, GREEN, CYAN , BLUE, PURPLE
EMPTY_TREE_LINE_LENGTH = 160
EMPTY_TREE_LINE = ' ' * EMPTY_TREE_LINE_LENGTH

18
vfind.py Executable file
View File

@ -0,0 +1,18 @@
#!/usr/bin/env python
from src.cmdline_parser import cmd_args
from src.tree_find import NerdTreeFind
if __name__ == '__main__':
print(cmd_args.path)
print(cmd_args.show_children_nodes)
path = cmd_args.path
pattern = cmd_args.pattern
show_children_nodes = cmd_args.show_children_nodes
find_opts = {
'dont_show_children_nodes': not show_children_nodes
}
ntree = NerdTreeFind(path)
ntree.find(pattern, opts=find_opts)