vfind command
This commit is contained in:
parent
bd2eef0cf7
commit
60ccd874df
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -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)
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
import os
|
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():
|
class NerdTree():
|
||||||
'''
|
'''
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
from colors import RED, YELLOW, GREEN, CYAN , BLUE, PURPLE
|
from src.colors import RED, YELLOW, GREEN, CYAN , BLUE, PURPLE
|
||||||
from tree import NerdTree
|
from src.tree import NerdTree
|
||||||
|
|
||||||
class NerdTreeFind(NerdTree):
|
class NerdTreeFind(NerdTree):
|
||||||
'''
|
'''
|
||||||
|
@ -8,11 +8,12 @@ class NerdTreeFind(NerdTree):
|
||||||
@param opts dict: the opts for the tree representation
|
@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.item_name = ''
|
||||||
self.results = []
|
self.results = []
|
||||||
## computed tree for find
|
## computed tree for find
|
||||||
self.json_tree_find = {}
|
self.json_tree_find = {}
|
||||||
|
self.find_opts = find_opts
|
||||||
NerdTree.__init__(self, startpath, opts=opts)
|
NerdTree.__init__(self, startpath, opts=opts)
|
||||||
|
|
||||||
def find_node_recursively(self, node):
|
def find_node_recursively(self, node):
|
||||||
|
@ -63,7 +64,7 @@ class NerdTreeFind(NerdTree):
|
||||||
'''
|
'''
|
||||||
results = self.find_node()
|
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:
|
if not results:
|
||||||
return {}
|
return {}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
import os
|
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_LENGTH = 160
|
||||||
EMPTY_TREE_LINE = ' ' * EMPTY_TREE_LINE_LENGTH
|
EMPTY_TREE_LINE = ' ' * EMPTY_TREE_LINE_LENGTH
|
||||||
|
|
|
@ -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)
|
Loading…
Reference in New Issue