Merge lp:~ben-hutchings/ensoft-sextant/query-fix into lp:ensoft-sextant

Proposed by Ben Hutchings
Status: Superseded
Proposed branch: lp:~ben-hutchings/ensoft-sextant/query-fix
Merge into: lp:ensoft-sextant
Prerequisite: lp:~ben-hutchings/ensoft-sextant/wierd-names-clean
Diff against target: 210 lines (+38/-53)
5 files modified
src/sextant/__main__.py (+16/-22)
src/sextant/db_api.py (+8/-1)
src/sextant/export.py (+3/-5)
src/sextant/query.py (+11/-24)
src/sextant/web/server.py (+0/-1)
To merge this branch: bzr merge lp:~ben-hutchings/ensoft-sextant/query-fix
Reviewer Review Type Date Requested Status
Robert Pending
Review via email: mp+244598@code.launchpad.net

This proposal has been superseded by a proposal from 2014-12-18.

Commit message

Fixed the 'sextant query ...' commands and updated so that it is possible to limit to internal calls/specify the maximum call depth from the commandline. Output can look quite pretty in yEd.

Description of the change

Fixed the 'sextant query ...' commands and updated so that it is possible to limit to internal calls/specify the maximum call depth from the commandline. Output can look quite pretty in yEd.

To post a comment you must log in.

Unmerged revisions

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'src/sextant/__main__.py'
--- src/sextant/__main__.py 2014-11-18 16:54:17 +0000
+++ src/sextant/__main__.py 2014-12-12 14:44:29 +0000
@@ -158,28 +158,18 @@
158 try:158 try:
159 arg1 = args.funcs[0]159 arg1 = args.funcs[0]
160 arg2 = args.funcs[1]160 arg2 = args.funcs[1]
161 except TypeError:161 except (TypeError, IndexError):
162 pass162 pass
163 except IndexError:163
164 pass164 query.query(connection,
165
166 try:
167 program_name = args.program[0]
168 except TypeError:
169 program_name = None
170
171 try:
172 suppress_common = args.suppress_common[0]
173 except TypeError:
174 suppress_common = False
175
176 query.query(remote_neo4j=args.remote_neo4j,
177 display_neo4j=_displayable_url(args),165 display_neo4j=_displayable_url(args),
178 input_query=args.query,166 input_query=args.query,
179 program_name=program_name,167 program_name=args.program,
180 argument_1=arg1,168 argument_1=arg1,
181 argument_2=arg2,169 argument_2=arg2,
182 suppress_common=suppress_common)170 suppress_common=args.suppress_common,
171 limit_internal=args.limit_internal,
172 limit_call_depth=args.limit_call_depth)
183173
184# End of functions which invoke Sextant174# End of functions which invoke Sextant
185175
@@ -243,13 +233,17 @@
243 parsers['query'].add_argument('--program', metavar="PROG_NAME",233 parsers['query'].add_argument('--program', metavar="PROG_NAME",
244 help="name of program as stored in the database; "234 help="name of program as stored in the database; "
245 "required for all queries except 'programs'",235 "required for all queries except 'programs'",
246 type=str, nargs=1)236 type=str)
247 parsers['query'].add_argument('--funcs', metavar='FUNCS',237 parsers['query'].add_argument('--funcs', metavar='FUNCS',
248 help='functions to pass to the query',238 help='functions to pass to the query',
249 type=str, nargs='+')239 type=str, nargs='+')
250 parsers['query'].add_argument('--suppress-common', metavar='BOOL',240 parsers['query'].add_argument('--suppress-common', action='store_true',
251 help='suppress commonly called functions (True or False)',241 help='suppress commonly called functions (True or False)')
252 type=str, nargs=1)242 parsers['query'].add_argument('--limit-internal', action='store_true',
243 help='limit call graph walking to internal function calls')
244 parsers['query'].add_argument('--limit-call-depth', metavar='CALL_DEPTH',
245 type=int, help='limit the maximum call depth, 0 for unlimited',
246 default=0)
253247
254 parsers['web'] = subparsers.add_parser('web', help="start the web server")248 parsers['web'] = subparsers.add_parser('web', help="start the web server")
255 parsers['web'].add_argument('--port', metavar='PORT', type=int,249 parsers['web'].add_argument('--port', metavar='PORT', type=int,
256250
=== modified file 'src/sextant/db_api.py'
--- src/sextant/db_api.py 2014-12-12 14:44:29 +0000
+++ src/sextant/db_api.py 2014-12-12 14:44:29 +0000
@@ -293,7 +293,14 @@
293 self.call_writer.file_iter()))293 self.call_writer.file_iter()))
294294
295 for path in file_paths: 295 for path in file_paths:
296 os.remove(path)296 try:
297 os.remove(path)
298 except OSError as e:
299 # If the file doesn't exist just keep going.
300 if e.errno == os.errno.ENOENT:
301 pass
302 else:
303 raise
297304
298 try_rmdir(self._tmp_dir)305 try_rmdir(self._tmp_dir)
299 try_rmdir(TMP_DIR)306 try_rmdir(TMP_DIR)
300307
=== modified file 'src/sextant/export.py'
--- src/sextant/export.py 2014-11-19 11:37:11 +0000
+++ src/sextant/export.py 2014-12-12 14:44:29 +0000
@@ -111,7 +111,7 @@
111 display_func = ProgramConverter.get_display_name(func)111 display_func = ProgramConverter.get_display_name(func)
112 if func.type == "stub":112 if func.type == "stub":
113 colour = "#ff00ff"113 colour = "#ff00ff"
114 elif func.type == "function_pointer":114 elif func.type == "pointer":
115 colour = "#99ffff"115 colour = "#99ffff"
116 elif func.is_common:116 elif func.is_common:
117 colour = "#00FF00"117 colour = "#00FF00"
@@ -141,7 +141,6 @@
141 </node>\n""".format(func.name, 20, len(display_func)*8, colour, display_func)141 </node>\n""".format(func.name, 20, len(display_func)*8, colour, display_func)
142142
143 functions_called = func.functions_i_call143 functions_called = func.functions_i_call
144 print(functions_called)
145 if remove_self_calls is True:144 if remove_self_calls is True:
146 #remove calls where a function calls itself145 #remove calls where a function calls itself
147 for func_called, is_internal, in functions_called:146 for func_called, is_internal, in functions_called:
@@ -149,18 +148,17 @@
149 functions_called.remove(func_called)148 functions_called.remove(func_called)
150149
151 for callee, is_internal in functions_called:150 for callee, is_internal in functions_called:
152 print(callee, is_internal)
153 color = "#000000" if is_internal else "#ff0000"151 color = "#000000" if is_internal else "#ff0000"
154 if callee not in commonly_called:152 if callee not in commonly_called:
155 if not(suppress_common_nodes and callee.is_common):153 if not(suppress_common_nodes and callee.is_common):
156 output_str += """<edge source="{}" target="{}"> <data key="d9">154 output_str += """<edge source="{}" target="{}"> <data key="d9">
157 <y:PolyLineEdge>155 <y:PolyLineEdge>
158 <y:LineStyle color="#ff0000" type="line" width="1.0"/>156 <y:LineStyle color="{}" type="line" width="1.0"/>
159 <y:Arrows source="none" target="standard"/>157 <y:Arrows source="none" target="standard"/>
160 <y:BendStyle smoothed="false"/>158 <y:BendStyle smoothed="false"/>
161 </y:PolyLineEdge>159 </y:PolyLineEdge>
162 </data>160 </data>
163 </edge>\n""".format(func.name, callee.name)161 </edge>\n""".format(func.name, callee.name, color)
164162
165 output_str += '</graph>\n<data key="d0"> <y:Resources/> </data>\n</graphml>'163 output_str += '</graph>\n<data key="d0"> <y:Resources/> </data>\n</graphml>'
166 return output_str164 return output_str
167165
=== modified file 'src/sextant/query.py'
--- src/sextant/query.py 2014-10-10 16:34:37 +0000
+++ src/sextant/query.py 2014-12-12 14:44:29 +0000
@@ -14,8 +14,9 @@
14from .export import ProgramConverter14from .export import ProgramConverter
1515
1616
17def query(connection, display_neo4j='', program_name=None,17def query(connection, input_query, display_neo4j='', program_name=None,
18 argument_1=None, argument_2=None, suppress_common=False):18 argument_1=None, argument_2=None, suppress_common=False,
19 limit_internal=False, limit_call_depth=0):
19 """20 """
20 Run a query against the database at remote_neo4j.21 Run a query against the database at remote_neo4j.
2122
@@ -36,24 +37,6 @@
3637
37 """38 """
3839
39 # if display_neo4j:
40 # display_url = display_neo4j
41 # else:
42 # display_url = remote_neo4j
43
44 # try:
45 # db = db_api.SextantConnection(remote_neo4j)
46 # except requests.exceptions.ConnectionError as err:
47 # logging.error("Could not connect to Neo4J server {}. Are you sure it is running?".format(display_url))
48 # logging.error(str(err))
49 # return 2
50 # #Not supported in python 2
51 # #except (urllib.exceptions.MaxRetryError):
52 # # logging.error("Connection was refused to {}. Are you sure the server is running?".format(remote_neo4j))
53 # # return 2
54 # except Exception as err:
55 # logging.exception(str(err))
56 # return 2
5740
58 prog = None41 prog = None
59 names_list = None42 names_list = None
@@ -66,24 +49,28 @@
66 if argument_1 is None:49 if argument_1 is None:
67 print('Supply one function name to functions-calling.')50 print('Supply one function name to functions-calling.')
68 return 151 return 1
69 prog = connection.get_all_functions_calling(program_name, argument_1)52 prog = connection.get_all_functions_calling(program_name, argument_1,
53 limit_internal, limit_call_depth)
70 elif input_query == 'functions-called-by':54 elif input_query == 'functions-called-by':
71 if argument_1 is None:55 if argument_1 is None:
72 print('Supply one function name to functions-called-by.')56 print('Supply one function name to functions-called-by.')
73 return 157 return 1
74 prog = connection.get_all_functions_called(program_name, argument_1)58 prog = connection.get_all_functions_called(program_name, argument_1,
59 limit_internal, limit_call_depth)
75 elif input_query == 'all-call-paths':60 elif input_query == 'all-call-paths':
76 if argument_1 is None and argument_2 is None:61 if argument_1 is None and argument_2 is None:
77 print('Supply two function names to calls-between.')62 print('Supply two function names to calls-between.')
78 return 163 return 1
79 prog = connection.get_call_paths(program_name, argument_1, argument_2)64 prog = connection.get_call_paths(program_name, argument_1, argument_2,
65 limit_internal, limit_call_depth)
80 elif input_query == 'whole-program':66 elif input_query == 'whole-program':
81 prog = connection.get_whole_program(program_name)67 prog = connection.get_whole_program(program_name)
82 elif input_query == 'shortest-call-path':68 elif input_query == 'shortest-call-path':
83 if argument_1 is None and argument_2 is None:69 if argument_1 is None and argument_2 is None:
84 print('Supply two function names to shortest-path.')70 print('Supply two function names to shortest-path.')
85 return 171 return 1
86 prog = connection.get_shortest_path_between_functions(program_name, argument_1, argument_2)72 prog = connection.get_shortest_path_between_functions(program_name, argument_1, argument_2,
73 limit_internal, limit_call_depth)
87 elif input_query == 'functions':74 elif input_query == 'functions':
88 if program_name is not None:75 if program_name is not None:
89 func_names = connection.get_function_names(program_name)76 func_names = connection.get_function_names(program_name)
9077
=== modified file 'src/sextant/web/server.py'
--- src/sextant/web/server.py 2014-12-02 14:00:57 +0000
+++ src/sextant/web/server.py 2014-12-12 14:44:29 +0000
@@ -209,7 +209,6 @@
209 res_code = RESPONSE_CODE_BAD_REQUEST209 res_code = RESPONSE_CODE_BAD_REQUEST
210 res_msg = "{}".format(e)210 res_msg = "{}".format(e)
211 print('\tfailed {}'.format(datetime.now()))211 print('\tfailed {}'.format(datetime.now()))
212 raise
213 212
214 213
215 if res_code is RESPONSE_CODE_OK:214 if res_code is RESPONSE_CODE_OK:

Subscribers

People subscribed via source and target branches