/usr/share/pyshared/seascope/backend/plugins/CtagsCache.py is in seascope 0.7-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 | # Copyright (c) 2010 Anil Kumar
# All rights reserved.
#
# License: BSD
from PyQt4.QtCore import *
from datetime import datetime
import re
#class CtagsInfo:
#def __init__(self):
#pass
#@staticmethod
#def lang_suffixes():
#cmd = 'ctags --list-maps'
#args = cmd.split()
#import subprocess
#proc = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
#(out_data, err_data) = proc.communicate()
#res = re.split('\r?\n', out_data)
# res = out_data
#res = [ line.split(None, 1) for line in res if line != '' ]
#d = {}
#for line in res:
#import fnmatch
#fn_pats = line[1] .split()
#print line[0], fn_pats
#re_pats = '|'.join(fnmatch.translate(p) for p in fn_pats)
#print line[0], re_pats
#d[line[0]] = re_pats
#print d
#print 'ctag.lang'
#CtagsInfo.lang_suffixes()
class CtagsThread(QThread):
thread_list = []
def __init__(self, sig):
QThread.__init__(self)
self.sig = sig
self.ct_dict = {}
self.finished.connect(self._finished_cb)
CtagsThread.thread_list.append(self)
def _finished_cb(self):
#print 'CtagsThread.finished', len(self.ct_dict)
CtagsThread.thread_list.remove(self)
for k in self.ct_dict:
ct_cache[k] = self.ct_dict[k]
self.res = self.parse_result(self.res, self.sig)
if self.res != None:
self.sig.emit_result(self.res)
def ctags_bsearch(self, ct, n):
x = -1
y = len(ct) - 1
#print f, n
while x < y:
m = (x + y + 1) / 2
#print '(', x, y, m, ')'
if ct[m][1] > n:
#print 'y: m -1', ct[m][1]
m = m - 1
y = m
continue
if ct[m][1] < n:
#print 'x: m', ct[m][1]
x = m
continue
break
if y == -1:
return y
#assert x == m or y == m or ct[m][1] == n
return m
def _ctags_fix(self, line):
f = line[1]
n = int(line[2])
ct = self.ct_dict[f]
m = self.ctags_bsearch(ct, n)
if m == -1:
return True
if ct[m][1] != n:
if ct[m][2] in ['variable']:
#line[0] = '***** SMART *****'
#print line
return True
if f.endswith('.py'):
while m > 0 and (ct[m][2] in ['namespace']):
m = m - 1
if m == - 1:
return True
if ct[m][1] == n:
if self.cmd_str == 'DEF':
x = m
y = m
while x > 1 and ct[x - 1][1] == n:
x = x - 1
while y < len(ct) - 1 and ct[y + 1][1] == n:
y = y + 1
if x < y:
for m in range(x, y + 1):
if re.match(self.sig.sym, ct[m][0]):
break
else:
if self.cmd_str == 'DEF':
return False
line[0] = ct[m][0]
return True
def _run_ctags(self):
cmd = 'ctags -n -u --fields=+K -L - -f -'
args = cmd.split()
import subprocess
proc = subprocess.Popen(args, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
(out_data, err_data) = proc.communicate('\n'.join(self.file_list))
out_data = re.split('\r?\n', out_data)
for line in out_data:
if line == '':
continue
line = line.split('\t')
f = line[1]
num = line[2].split(';', 1)[0]
line = [line[0], int(num), line[3]]
self.ct_dict[f].append(line)
def prepare_file_list(self):
#t1 = datetime.now()
flist = set()
for line in self.res:
if line[0] in self.cond_list:
if line[1] not in ct_cache:
flist.add(line[1])
else:
self.ct_dict[line[1]] = ct_cache[line[1]]
for f in flist:
self.ct_dict[f] = []
#t2 = datetime.now()
#print ' ', len(flist), 'flist', t2 - t1
self.file_list = flist
def apply_fix(self, cmd_str, res, cond_list):
self.cmd_str = cmd_str
self.res = res
self.cond_list = cond_list
self.prepare_file_list()
self.start()
def run(self):
#t2 = datetime.now()
self._run_ctags()
#t3 = datetime.now()
#print ' ct', t3 - t2
res = []
for line in self.res:
if line[0] not in self.cond_list:
continue
if not self._ctags_fix(line):
continue
res.append(line)
self.res = res
#t4 = datetime.now()
#print ' fix', t4 - t3
#print ' total', t4 - t2
def _filter_res(self, res, sig):
req = sig.sym
out_res = []
if self.cmd_str == 'DEF':
import_re = re.compile('^\s*import\s+')
for line in res:
if not re.match(req, line[0]):
continue
if import_re.search(line[3]) and line[1].endswith('.py'):
continue
out_res.append(line)
return out_res
if self.cmd_str == '-->':
call_re = re.compile('\\b%s\\b\s*\(' % req)
extern_re = re.compile('^\s*extern\s+')
comment_re = re.compile('^\s*(\*\s|/\*|\*/|//\s|# )')
func_ptr_re = re.compile('\\b(\w+)\s*(=|:)\s*%s\s*[,;:)]' % req)
func_as_arg_re = re.compile('(^\s*|[(,]\s*)(\w+(\.|->))*%s\s*[,)]' % req);
for line in res:
if line[0] == req:
if not re.search('(\.|->)%s\\b' % req, line[3]):
continue
elif call_re.search(line[3]):
if extern_re.search(line[3]):
continue
else:
grp = func_ptr_re.search(line[3])
if grp:
line[0] = grp.group(1)
else:
if not func_as_arg_re.search(line[3]):
continue
if line[0] == '<unknown>':
continue
if comment_re.search(line[3]):
continue
out_res.append(line)
return out_res
if self.cmd_str == '<--':
return res
if self.cmd_str == 'INC':
inc_re = re.compile('^\s*(#\s*include|(from\s+[^\s]+\s+)?import)\s+.*%s.*' % req)
for line in res:
if not inc_re.search(line[3]):
continue
out_res.append(line)
return out_res
return res
ct_cache = {}
def flush():
#print 'flushing ctags cache...'
global ct_cache
ct_cache = {}
|