vfind, supporting shell expansions and regexp
This commit is contained in:
@ -1,6 +1,7 @@
|
||||
import time
|
||||
|
||||
import re
|
||||
import fnmatch
|
||||
|
||||
from src.colors import RED, YELLOW, GREEN, CYAN , BLUE, PURPLE
|
||||
from src.tree import NerdTree
|
||||
@ -15,6 +16,11 @@ class NerdTreeFind(NerdTree):
|
||||
def __init__(self, startpath, opts={}, find_opts={}):
|
||||
self.item_name = ''
|
||||
self.re_item_name = None
|
||||
'''
|
||||
re_item_name is a regexp python object, can be
|
||||
1. a regular expression, specifying in the command line -re option
|
||||
2. a string that supports the shell expansion
|
||||
'''
|
||||
self.results = []
|
||||
self.start_time = time.time()
|
||||
self.end_time = None
|
||||
@ -137,14 +143,24 @@ class NerdTreeFind(NerdTree):
|
||||
self.compute_aggregate_recursively(tree_struct)
|
||||
return tree_struct
|
||||
|
||||
def get_reobj_find(self, item_name):
|
||||
if not self.find_opts['use_regular_expression']:
|
||||
regex = fnmatch.translate(item_name)
|
||||
reobj = re.compile(regex)
|
||||
return reobj
|
||||
|
||||
reobj = re.compile(r'^%s$' % (item_name,))
|
||||
return reobj
|
||||
|
||||
def reset(self, new_item_name, new_opts):
|
||||
self.find_opts = new_opts
|
||||
self.results = []
|
||||
self.item_name = new_item_name
|
||||
print('Starting from path: %s' % CYAN(self.startpath,))
|
||||
print('Regexp: %s' % CYAN(new_item_name,))
|
||||
print('Use regexp: %s' % (CYAN(self.find_opts['use_regular_expression'])))
|
||||
print('pattern: %s' % CYAN(new_item_name,))
|
||||
try:
|
||||
self.re_item_name = re.compile(r'^%s$' % (new_item_name,))
|
||||
self.re_item_name = self.get_reobj_find(new_item_name)
|
||||
except re.error:
|
||||
raise Exception('Can\'t compile regexp %s, exit' % (new_item_name,))
|
||||
self.json_tree_find = {}
|
||||
|
Reference in New Issue
Block a user