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
1=== modified file 'src/sextant/__main__.py'
2--- src/sextant/__main__.py 2014-11-18 16:54:17 +0000
3+++ src/sextant/__main__.py 2014-12-12 14:44:29 +0000
4@@ -158,28 +158,18 @@
5 try:
6 arg1 = args.funcs[0]
7 arg2 = args.funcs[1]
8- except TypeError:
9- pass
10- except IndexError:
11- pass
12-
13- try:
14- program_name = args.program[0]
15- except TypeError:
16- program_name = None
17-
18- try:
19- suppress_common = args.suppress_common[0]
20- except TypeError:
21- suppress_common = False
22-
23- query.query(remote_neo4j=args.remote_neo4j,
24+ except (TypeError, IndexError):
25+ pass
26+
27+ query.query(connection,
28 display_neo4j=_displayable_url(args),
29 input_query=args.query,
30- program_name=program_name,
31+ program_name=args.program,
32 argument_1=arg1,
33 argument_2=arg2,
34- suppress_common=suppress_common)
35+ suppress_common=args.suppress_common,
36+ limit_internal=args.limit_internal,
37+ limit_call_depth=args.limit_call_depth)
38
39 # End of functions which invoke Sextant
40
41@@ -243,13 +233,17 @@
42 parsers['query'].add_argument('--program', metavar="PROG_NAME",
43 help="name of program as stored in the database; "
44 "required for all queries except 'programs'",
45- type=str, nargs=1)
46+ type=str)
47 parsers['query'].add_argument('--funcs', metavar='FUNCS',
48 help='functions to pass to the query',
49 type=str, nargs='+')
50- parsers['query'].add_argument('--suppress-common', metavar='BOOL',
51- help='suppress commonly called functions (True or False)',
52- type=str, nargs=1)
53+ parsers['query'].add_argument('--suppress-common', action='store_true',
54+ help='suppress commonly called functions (True or False)')
55+ parsers['query'].add_argument('--limit-internal', action='store_true',
56+ help='limit call graph walking to internal function calls')
57+ parsers['query'].add_argument('--limit-call-depth', metavar='CALL_DEPTH',
58+ type=int, help='limit the maximum call depth, 0 for unlimited',
59+ default=0)
60
61 parsers['web'] = subparsers.add_parser('web', help="start the web server")
62 parsers['web'].add_argument('--port', metavar='PORT', type=int,
63
64=== modified file 'src/sextant/db_api.py'
65--- src/sextant/db_api.py 2014-12-12 14:44:29 +0000
66+++ src/sextant/db_api.py 2014-12-12 14:44:29 +0000
67@@ -293,7 +293,14 @@
68 self.call_writer.file_iter()))
69
70 for path in file_paths:
71- os.remove(path)
72+ try:
73+ os.remove(path)
74+ except OSError as e:
75+ # If the file doesn't exist just keep going.
76+ if e.errno == os.errno.ENOENT:
77+ pass
78+ else:
79+ raise
80
81 try_rmdir(self._tmp_dir)
82 try_rmdir(TMP_DIR)
83
84=== modified file 'src/sextant/export.py'
85--- src/sextant/export.py 2014-11-19 11:37:11 +0000
86+++ src/sextant/export.py 2014-12-12 14:44:29 +0000
87@@ -111,7 +111,7 @@
88 display_func = ProgramConverter.get_display_name(func)
89 if func.type == "stub":
90 colour = "#ff00ff"
91- elif func.type == "function_pointer":
92+ elif func.type == "pointer":
93 colour = "#99ffff"
94 elif func.is_common:
95 colour = "#00FF00"
96@@ -141,7 +141,6 @@
97 </node>\n""".format(func.name, 20, len(display_func)*8, colour, display_func)
98
99 functions_called = func.functions_i_call
100- print(functions_called)
101 if remove_self_calls is True:
102 #remove calls where a function calls itself
103 for func_called, is_internal, in functions_called:
104@@ -149,18 +148,17 @@
105 functions_called.remove(func_called)
106
107 for callee, is_internal in functions_called:
108- print(callee, is_internal)
109 color = "#000000" if is_internal else "#ff0000"
110 if callee not in commonly_called:
111 if not(suppress_common_nodes and callee.is_common):
112 output_str += """<edge source="{}" target="{}"> <data key="d9">
113 <y:PolyLineEdge>
114- <y:LineStyle color="#ff0000" type="line" width="1.0"/>
115+ <y:LineStyle color="{}" type="line" width="1.0"/>
116 <y:Arrows source="none" target="standard"/>
117 <y:BendStyle smoothed="false"/>
118 </y:PolyLineEdge>
119 </data>
120- </edge>\n""".format(func.name, callee.name)
121+ </edge>\n""".format(func.name, callee.name, color)
122
123 output_str += '</graph>\n<data key="d0"> <y:Resources/> </data>\n</graphml>'
124 return output_str
125
126=== modified file 'src/sextant/query.py'
127--- src/sextant/query.py 2014-10-10 16:34:37 +0000
128+++ src/sextant/query.py 2014-12-12 14:44:29 +0000
129@@ -14,8 +14,9 @@
130 from .export import ProgramConverter
131
132
133-def query(connection, display_neo4j='', program_name=None,
134- argument_1=None, argument_2=None, suppress_common=False):
135+def query(connection, input_query, display_neo4j='', program_name=None,
136+ argument_1=None, argument_2=None, suppress_common=False,
137+ limit_internal=False, limit_call_depth=0):
138 """
139 Run a query against the database at remote_neo4j.
140
141@@ -36,24 +37,6 @@
142
143 """
144
145- # if display_neo4j:
146- # display_url = display_neo4j
147- # else:
148- # display_url = remote_neo4j
149-
150- # try:
151- # db = db_api.SextantConnection(remote_neo4j)
152- # except requests.exceptions.ConnectionError as err:
153- # logging.error("Could not connect to Neo4J server {}. Are you sure it is running?".format(display_url))
154- # logging.error(str(err))
155- # return 2
156- # #Not supported in python 2
157- # #except (urllib.exceptions.MaxRetryError):
158- # # logging.error("Connection was refused to {}. Are you sure the server is running?".format(remote_neo4j))
159- # # return 2
160- # except Exception as err:
161- # logging.exception(str(err))
162- # return 2
163
164 prog = None
165 names_list = None
166@@ -66,24 +49,28 @@
167 if argument_1 is None:
168 print('Supply one function name to functions-calling.')
169 return 1
170- prog = connection.get_all_functions_calling(program_name, argument_1)
171+ prog = connection.get_all_functions_calling(program_name, argument_1,
172+ limit_internal, limit_call_depth)
173 elif input_query == 'functions-called-by':
174 if argument_1 is None:
175 print('Supply one function name to functions-called-by.')
176 return 1
177- prog = connection.get_all_functions_called(program_name, argument_1)
178+ prog = connection.get_all_functions_called(program_name, argument_1,
179+ limit_internal, limit_call_depth)
180 elif input_query == 'all-call-paths':
181 if argument_1 is None and argument_2 is None:
182 print('Supply two function names to calls-between.')
183 return 1
184- prog = connection.get_call_paths(program_name, argument_1, argument_2)
185+ prog = connection.get_call_paths(program_name, argument_1, argument_2,
186+ limit_internal, limit_call_depth)
187 elif input_query == 'whole-program':
188 prog = connection.get_whole_program(program_name)
189 elif input_query == 'shortest-call-path':
190 if argument_1 is None and argument_2 is None:
191 print('Supply two function names to shortest-path.')
192 return 1
193- prog = connection.get_shortest_path_between_functions(program_name, argument_1, argument_2)
194+ prog = connection.get_shortest_path_between_functions(program_name, argument_1, argument_2,
195+ limit_internal, limit_call_depth)
196 elif input_query == 'functions':
197 if program_name is not None:
198 func_names = connection.get_function_names(program_name)
199
200=== modified file 'src/sextant/web/server.py'
201--- src/sextant/web/server.py 2014-12-02 14:00:57 +0000
202+++ src/sextant/web/server.py 2014-12-12 14:44:29 +0000
203@@ -209,7 +209,6 @@
204 res_code = RESPONSE_CODE_BAD_REQUEST
205 res_msg = "{}".format(e)
206 print('\tfailed {}'.format(datetime.now()))
207- raise
208
209
210 if res_code is RESPONSE_CODE_OK:

Subscribers

People subscribed via source and target branches