-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfind.py
More file actions
89 lines (79 loc) · 2.93 KB
/
find.py
File metadata and controls
89 lines (79 loc) · 2.93 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
# coding=utf-8
import os
import re
import auxiliar
# permite el mostrar por pantalla un elemento encontrado
def aux_print(name_file, text_temp):
print ">>Found in " + name_file + ":\n"
if auxiliar.multiple_replace(auxiliar.styles, text_temp, "find"):
print auxiliar.multiple_replace(auxiliar.styles, text_temp, "find")
else:
print text_temp
# la funcion se encarga de buscar segun lo espeficado
def op_find(order):
anything_find = False
text_temp = ""
ready = False
# permite encontrar algunas de las palabras espeficadas, solo admite
# letras del alfabeto
if re.search("some", order):
exclude = re.compile(r'\W+')
wanted = re.findall(r'"([A-Za-z]+)"', order)
filelist = [f for f in os.listdir(os.getcwd()) if f.endswith('.lpy')]
for name_file in filelist:
tmp = open(name_file)
for line in tmp:
line = line.split()
for word in line:
if '\n' in word:
filtred_word = exclude.sub('', word)
if filtred_word in wanted:
text_temp += '\033[46m' + word + '\033[49m' + '\n'
ready = True
else:
text_temp += word + " "
else:
filtred_word = exclude.sub('', word)
if filtred_word in wanted:
text_temp += '\033[46m' + word + '\033[49m' + " "
ready = True
else:
text_temp += word + " "
if ready:
anything_find = True
aux_print(name_file, text_temp)
text_temp = ""
ready = False
print "\033[0;39m"
else:
text_temp = ""
tmp.close()
# permite encontrar la frase exacta en un texto
elif re.search("exact", order):
filelist = [f for f in os.listdir(os.getcwd()) if f.endswith('.lpy')]
for name_file in filelist:
tmp = open(name_file)
for line in tmp:
find = re.search(r'"(.+)"', order).group(1)
find = " " + find + " "
line = " " + line
if re.search(find, line):
text_temp += re.sub(find, '\033[46m' + find + '\033[49m', line)
ready = True
else:
text_temp += line
if ready:
anything_find = True
aux_print(name_file, text_temp)
text_temp = ""
ready = False
print "\033[0;39m"
else:
text_temp = ""
tmp.close()
else:
anything_find = True
print "Error: Incorrect Command"
if not anything_find:
print "Nothing was found.."
return