Debian Codegraph @

src/web/backend/plugins/idutils/IdutilsProject.py

raw symbols SCIP
1 #!/usr/bin/env python3
2
3 # Copyright (c) 2010 Anil Kumar
4 # All rights reserved.
5 #
6 # License: BSD
7
8 import sys, os, string, re
9
10 from ..PluginBase import PluginFeatureBase, ProjectBase, ConfigBase, QueryBase
11 from ..PluginBase import PluginProcess
12 from ..CtagsCache import CtagsThread
13
14
15 class IdutilsFeature(PluginFeatureBase):
16 def __init__(self):
17 PluginFeatureBase.__init__(self)
18
19 self.feat_desc = [
20 ['REF', ''],
21 ['DEF', ''],
22 #['<--', '2'],
23 ['-->', '3'],
24 #['TXT', '4'],
25 ['GREP', ''],
26 ['FIL', ''],
27 ['INC', '8'],
28
29 ['QDEF', ''],
30 ['CTREE', '12'],
31
32 ['CLGRAPH', '13'],
33 ['CLGRAPHD','14'],
34 ['FFGRAPH', '14'],
35
36 ['UPD', '25'],
37 ]
38
39 self.ctree_query_args = [
40 ['-->', '--> F', 'Calling tree' ],
41 #['<--', 'F -->', 'Called tree' ],
42 ['REF', '==> F', 'Advanced calling tree' ],
43 ]
44
45 def query_dlg_cb(self, req, cmd_str, in_opt):
46 opt = []
47 if cmd_str != 'TXT' and req != '' and in_opt['substring']:
48 opt.append('substring')
49 if cmd_str == 'FIL':
50 req = '*' + req + '*'
51 else:
52 req = '.*' + req + '.*'
53 if in_opt['ignorecase']:
54 opt.append('ignorecase')
55
56 res = (cmd_str, req, opt)
57 return res
58
59
60
61 class ConfigIdutils(ConfigBase):
62 def __init__(self):
63 ConfigBase.__init__(self, 'idutils')
64
65 class ProjectIdutils(ProjectBase):
66 def __init__(self):
67 ProjectBase.__init__(self)
68
69 @staticmethod
70 def _prj_new_or_open(conf):
71 prj = ProjectIdutils()
72 prj.feat = IdutilsFeature()
73 prj.conf = conf
74 prj.qry = QueryIdutils(prj.conf, prj.feat)
75 return (prj)
76
77 @staticmethod
78 def prj_new(proj_args):
79 d = proj_args[0]
80 prj = ProjectIdutils.prj_open(d)
81 return prj
82
83 @staticmethod
84 def prj_open(proj_path):
85 conf = ConfigIdutils()
86 conf.proj_open(proj_path)
87 prj = ProjectIdutils._prj_new_or_open(conf)
88 return (prj)
89
90
91 class IdProcess(PluginProcess):
92 def __init__(self, wdir, rq):
93 PluginProcess.__init__(self, wdir, rq)
94 self.name = 'idutils process'
95
96 def parse_result(self, text, sig):
97 if self.cmd_str in ['GREP']:
98 return PluginProcess.parse_result(self, text, sig)
99
100 #from datetime import datetime
101 #t1 = datetime.now()
102
103 text = re.split(r'\r?\n', text)
104
105 #t2 = datetime.now()
106 #print 'parse-split', t2 - t1
107
108 if self.cmd_str == 'FIL':
109 res = [ ['', os.path.join(self.wdir, line), '', '' ] for line in text if line != '' ]
110 return res
111
112 res = []
113 for line in text:
114 if line == '':
115 continue
116 line = line.split(':', 2)
117 line = ['<unknown>', os.path.join(self.wdir, line[0]), line[1], line[2]]
118 res.append(line)
119
120 #t3 = datetime.now()
121 #print 'parse-loop', t3 - t2
122
123 res = CtagsThread(sig).apply_fix(self.cmd_str, res, ['<unknown>'])
124
125 return res
126
127 idutils_lid_cmd = os.getenv('SEASCOPE_IDUTILS_LID_CMD', 'lid')
128
129 class QueryIdutils(QueryBase):
130 def __init__(self, conf, feat):
131 QueryBase.__init__(self)
132 self.conf = conf
133 self.feat = feat
134
135 def query(self, rquery):
136 if (not self.conf):
137 #or not self.conf.is_ready()):
138 print("pm_query not is_ready")
139 return None
140
141 cmd_str = rquery['cmd']
142 if cmd_str in ['GREP']:
143 return QueryBase.query(self, rquery)
144 req = rquery['req']
145 opt = rquery['opt']
146 if opt == None:
147 opt = []
148
149 pargs = [idutils_lid_cmd, '-R', 'grep']
150 if cmd_str == 'FIL':
151 pargs = ['fnid', '-S', 'newline']
152 #elif cmd_str == 'TXT':
153 #pargs += ['-l']
154 elif cmd_str in ['-->', '<--']:
155 pargs += ['-l']
156
157 if 'substring' in opt:
158 if cmd_str == 'FIL':
159 req = '*' + req + '*'
160 else:
161 req = '.*' + req + '.*'
162 #pargs += ' -s'
163 if 'ignorecase' in opt:
164 if cmd_str == 'FIL':
165 pass
166 else:
167 pargs += ['-i']
168
169 pargs += [ '--', req ]
170 qsig = IdProcess(self.conf.c_dir, [cmd_str, req]).run_query_process(pargs, req, rquery)
171 return qsig
172
173 def rebuild(self):
174 if (not self.conf.is_ready()):
175 print("pm_query not is_ready")
176 return None
177 pargs = os.getenv('SEASCOPE_IDUTILS_MKID_CMD', '').strip().split()
178 if not len(pargs):
179 pargs = [ 'mkid', '-s' ]
180 qsig = IdProcess(self.conf.c_dir, None).run_rebuild_process(pargs)
181 return qsig
182
183 def query_fl(self):
184 if not os.path.exists(os.path.join(self.conf.c_dir, 'ID')):
185 return []
186 pargs = [ 'fnid', '-S', 'newline', '-f', 'ID' ]
187 qsig = IdProcess(self.conf.c_dir, None).run_query_fl(pargs)
188 return qsig
189
190 def id_is_open(self):
191 return self.conf != None
192 def id_is_ready(self):
193 return self.conf.is_ready()