Debian Codegraph @

src/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 CtagsThread(sig).apply_fix(self.cmd_str, res, ['<unknown>'])
124
125 return None
126
127 class QueryIdutils(QueryBase):
128 def __init__(self, conf, feat):
129 QueryBase.__init__(self)
130 self.conf = conf
131 self.feat = feat
132
133 def query(self, rquery):
134 if (not self.conf):
135 #or not self.conf.is_ready()):
136 print("pm_query not is_ready")
137 return None
138
139 cmd_str = rquery['cmd']
140 if cmd_str in ['GREP']:
141 return QueryBase.query(self, rquery)
142 req = rquery['req']
143 opt = rquery['opt']
144 if opt == None:
145 opt = []
146
147 pargs = ['lid', '-R', 'grep']
148 if cmd_str == 'FIL':
149 pargs = ['fnid', '-S', 'newline']
150 #elif cmd_str == 'TXT':
151 #pargs += ['-l']
152 elif 'substring' in opt:
153 #req = '.*' + req + '.*'
154 #pargs += ' -s'
155 pass
156 elif cmd_str in ['-->', '<--']:
157 pargs += ['-l']
158
159 if cmd_str != 'FIL':
160 if 'ignorecase' in opt:
161 pargs += ['-i']
162 pargs += [ '--', req ]
163 qsig = IdProcess(self.conf.c_dir, [cmd_str, req]).run_query_process(pargs, req, rquery)
164 return qsig
165
166 def rebuild(self):
167 if (not self.conf.is_ready()):
168 print("pm_query not is_ready")
169 return None
170 pargs = os.getenv('SEASCOPE_IDUTILS_MKID_CMD', '').strip().split()
171 if not len(pargs):
172 pargs = [ 'mkid', '-s' ]
173 qsig = IdProcess(self.conf.c_dir, None).run_rebuild_process(pargs)
174 return qsig
175
176 def query_fl(self):
177 if not os.path.exists(os.path.join(self.conf.c_dir, 'ID')):
178 return []
179 pargs = [ 'fnid', '-S', 'newline', '-f', 'ID' ]
180 qsig = IdProcess(self.conf.c_dir, None).run_query_fl(pargs)
181 return qsig
182
183 def id_is_open(self):
184 return self.conf != None
185 def id_is_ready(self):
186 return self.conf.is_ready()