Compare commits

...

5 Commits

Author SHA1 Message Date
Amber 41113119cc .gitignore 2024-01-31 12:04:11 +01:00
Amber 02b1d3916f vfind command --exclude 2024-01-31 12:02:13 +01:00
Amber 8e174308a3 human number representation 2024-01-31 12:01:46 +01:00
Amber 179b2ab3f9 command line parser add --exclude 2024-01-31 12:00:38 +01:00
Amber a92c6e8327 remove constant ITEMS_TO_EXCLUDE 2024-01-31 12:00:01 +01:00
8 changed files with 29 additions and 19 deletions

1
.gitignore vendored Normal file
View File

@ -0,0 +1 @@
**/__pycache__

Binary file not shown.

View File

@ -11,6 +11,8 @@ cmd_parser.add_argument("path")
cmd_parser.add_argument("pattern") cmd_parser.add_argument("pattern")
# if -s is found in the command line cmd_args.show_children_nodes is True # 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") cmd_parser.add_argument("-s", "--show-children-nodes", action="store_true")
## more than one occurrencies of -e option are appended in a list
cmd_parser.add_argument("-e", "--exclude", action="append")
# start the command line parsing # start the command line parsing
cmd_args = cmd_parser.parse_args() cmd_args = cmd_parser.parse_args()

View File

@ -114,7 +114,7 @@ class NerdTree():
d.setdefault('not_readable', 1) d.setdefault('not_readable', 1)
for item in items: for item in items:
if item in _tree_repr.ITEMS_TO_EXCLUDE: if item in self.opts.get('items_to_exclude') or []:
continue continue
abs_path_item = startpath+item abs_path_item = startpath+item
@ -205,8 +205,8 @@ class NerdTree():
items = rootnode.get('children') or [] items = rootnode.get('children') or []
for n, item in enumerate(items): for n, item in enumerate(items):
if item['name'] in _tree_repr.ITEMS_TO_EXCLUDE: # if item['name'] in _tree_repr.ITEMS_TO_EXCLUDE:
continue # continue
islast = (n==len(items) -1) islast = (n==len(items) -1)

View File

@ -11,7 +11,8 @@ CHILD_CONNECTOR = '├── '
LAST_CHILD_CONNECTOR = '└── ' LAST_CHILD_CONNECTOR = '└── '
### is the length of child connector and last_child_connector ### is the length of child connector and last_child_connector
LEVEL_INDENT = 4 LEVEL_INDENT = 4
ITEMS_TO_EXCLUDE = ['__pycache__'] # ITEMS_TO_EXCLUDE = ['__pycache__']
ITEMS_TO_EXCLUDE = []
KB = 1024 KB = 1024
MB = 1024*1024 MB = 1024*1024
@ -51,19 +52,19 @@ def produce_treeline(prec_seps, lsep):
return tree_line.rstrip() return tree_line.rstrip()
def format(num, unit=None): def format(num, unit=None):
# if num/GB >=1: if num/GB >=1 or unit == 'G':
# unit = 'GB' unit = 'G'
# human_number = round(num/GB, 2) human_number = round(num/GB, 2)
# elif num/MB >=1: elif num/MB >=1 or unit == 'M':
# unit = 'MB' unit = 'M'
# human_number = round(num/MB, 2) human_number = round(num/MB, 2)
# elif num/KB >=1: elif num/KB >=1 or unit == 'K':
# unit = 'kB' unit = 'K'
# human_number = round(num/KB, 2) human_number = round(num/KB, 2)
# else: else:
unit = 'B'
human_number = num
# unit = 'b' # unit = 'b'
# human_number = num # human_number = num
unit = 'b'
human_number = num
return human_number, unit return human_number, unit

View File

@ -10,9 +10,15 @@ if __name__ == '__main__':
pattern = cmd_args.pattern pattern = cmd_args.pattern
show_children_nodes = cmd_args.show_children_nodes show_children_nodes = cmd_args.show_children_nodes
# opts for generatign the tree
opts = {
'items_to_exclude' : cmd_args.exclude or [],
}
# opts for find
find_opts = { find_opts = {
'dont_show_children_nodes': not show_children_nodes 'dont_show_children_nodes': not show_children_nodes
} }
ntree = NerdTreeFind(path) ntree = NerdTreeFind(path, opts=opts)
ntree.find(pattern, opts=find_opts) ntree.find(pattern, opts=find_opts)