Merge lp:~jamesh-f/ensoft-sextant/argparse-name-changes into lp:ensoft-sextant
- argparse-name-changes
- Merge into whiteline
Proposed by
James
Status: | Merged |
---|---|
Approved by: | Patrick Stevens |
Approved revision: | 12 |
Merged at revision: | 9 |
Proposed branch: | lp:~jamesh-f/ensoft-sextant/argparse-name-changes |
Merge into: | lp:ensoft-sextant |
Diff against target: |
311 lines (+56/-70) 7 files modified
doc/Program_upload_docs.mkd (+1/-1) doc/wiki/Reference (+18/-15) resources/sextant/web/interface.html (+2/-2) resources/sextant/web/queryjavascript.js (+2/-2) src/sextant/__main__.py (+26/-24) src/sextant/query.py (+5/-24) src/sextant/web/server.py (+2/-2) |
To merge this branch: | bzr merge lp:~jamesh-f/ensoft-sextant/argparse-name-changes |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Patrick Stevens | Approve | ||
Review via email: mp+231854@code.launchpad.net |
Commit message
Change names of command line arguments and format to which they are used.
Description of the change
Change names of command line arguments and format to which they are used. Make this consistent with the web page and documentation.
To post a comment you must log in.
Revision history for this message
Patrick Stevens (patrickas) : | # |
review:
Needs Fixing
- 9. By James Harkin <email address hidden>
-
diff changes I see no merge conflicts though
Revision history for this message
Patrick Stevens (patrickas) : | # |
review:
Needs Fixing
- 10. By James Harkin <email address hidden>
-
merge
Revision history for this message
Patrick Stevens (patrickas) : | # |
review:
Needs Fixing
Revision history for this message
Patrick Stevens (patrickas) : | # |
review:
Approve
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'doc/Program_upload_docs.mkd' (properties changed: -x to +x) |
2 | --- doc/Program_upload_docs.mkd 2014-08-12 13:30:24 +0000 |
3 | +++ doc/Program_upload_docs.mkd 2014-08-22 14:42:47 +0000 |
4 | @@ -5,5 +5,5 @@ |
5 | Optionally, the flag `--ignore-function-pointers` can be provided to `program_upload.py` to cause the parser to pretend function pointer calls simply do not exist. |
6 | |
7 | # Query parameters |
8 | -We take the mandatory `--input-file`, a filepath for a program file whose call graph we wish to upload to the Neo4J server. Optionally we can specify that it is an ``--object-file` to have `objdump` run against it; otherwise, we assume the input was a text file consisting of `objdump`'s output. |
9 | +The first argument to upload a program to the database is "add-program", after which you should specify the file path to the program. We can also if desired set the name of the program when stored in the database ("--names-in-db"). Optionally we can specify that it is not an object file (--not-object-file') so that instead of running `objdump` against it, we assume the input was a text file consisting of `objdump -D`'s output. |
10 | Optional (if specified in config file) `--remote-neo4j`, the location of the Neo4J server (eg. `http://localhost:7474`). |
11 | \ No newline at end of file |
12 | |
13 | === modified file 'doc/wiki/Reference' (properties changed: -x to +x) |
14 | --- doc/wiki/Reference 2014-08-13 15:18:11 +0000 |
15 | +++ doc/wiki/Reference 2014-08-22 14:42:47 +0000 |
16 | @@ -10,31 +10,32 @@ |
17 | == File Management == |
18 | No more than one program can have the same name in the database. |
19 | === Uploading a File === |
20 | -set-file-name and not-object-file are optional. |
21 | +{{{ --name-in-db }}} and {{{ --not-object-file }}} are optional. |
22 | {{{ |
23 | -sextant add_program --input-file <name of file being input> --set-file-name <name file to be stored under in database> --not-object-file <True or False (default is False; pass through Objdump)> |
24 | +sextant add-program <name of file being input> --name-in-db <name file to be stored under in database> --not-object-file <True or False (default is False; pass through Objdump)> |
25 | }}} |
26 | === Deleting File === |
27 | -It is good practice to delete files from the server since having many graphs in the database can lead to negative effects on performance. |
28 | +It is good practice to wipe files from the server since having many graphs in the database can lead to negative effects on performance. |
29 | {{{ |
30 | -sextant delete_program --program name <program name to be deleted as stored in database> |
31 | +sextant delete-program <program name to be deleted as stored in database> |
32 | }}} |
33 | == Queries == |
34 | === Command Line === |
35 | Command line queries produce a text output, either as a list or in GraphML which can be opened in yED. |
36 | All queries take the form. |
37 | {{{ |
38 | -sextant query --program-name <program name> --query <query name> --funcs <One or two functions as the arguments of the query> --suppress-common <True or False (default is False)> |
39 | +sextant query <query name> --program <program name (as stored in db to be queried)> --funcs <One or two functions as the arguments of the query> --suppress-common <True or False (default is False)> |
40 | }}} |
41 | -Here common sense prevails. "return-all-program-names" doesn't have a "--program-name" argument or "--funcs" or "--suppress-common". Similarly whole-graph doesn't take any "--funcs". "--suppress-common" is always optional and can only be used for a GraphML output. |
42 | -The options for queries are: |
43 | - * functions-calling, |
44 | - * functions-called-by, |
45 | - * calls-between, |
46 | - * whole-graph, |
47 | - * shortest-path, |
48 | - * return-all-program-names, |
49 | - * return-all-function-names. |
50 | +Regarding query arguments common sense prevails. {{{ programs }}} doesn't have a {{{ --program }}} argument or {{{ --funcs }}} or {{{ --suppress-common }}}. Similarly whole-program doesn't take any {{{ --funcs }}} . {{{ --suppress-common }}} is always optional and can only be used for a GraphML output when specified in the command line. |
51 | + || {{{ query }}} || {{{ --funcs }}} || {{{ --program }}} || {{{ --suppress-common }}} || |
52 | + || {{{ functions-calling }}} || *1 || *1 || opt || |
53 | + || {{{ functions-called-by }}} || *1 || *1 || opt || |
54 | + || {{{ all-call-paths }}} || *2 || *1 || opt || |
55 | + || {{{ whole-program }}} || *0 || *1 || opt || |
56 | + || {{{ shortest-call-path }}} || *2 || *1 || *0 || |
57 | + || {{{ programs }}} || *0 || *0 || *0 || |
58 | + || {{{ functions }}} || *0 || *1 || *0 || |
59 | +A number signifies the number of arguments required, opt means the argument is allowed but is optional. |
60 | For help with queries from the command line and the arguments type: |
61 | {{{ |
62 | sextant query -h |
63 | @@ -42,4 +43,6 @@ |
64 | === Web === |
65 | To run the web server type |
66 | {{{ sextant web }}} |
67 | -into the command line; then navigate a web browser to the port specified. |
68 | \ No newline at end of file |
69 | +into the command line; then navigate a web browser to the port specified. |
70 | +== Audit == |
71 | +To see a more detailed view of a list of programs on the server type {{{ sextant audit }}} into the command line. This will return a list of programs on the Neo4j server, specified in either the config file of command line, along with their unique program number, who uploaded them, that persons id and the date they were uploaded. |
72 | \ No newline at end of file |
73 | |
74 | === modified file 'resources/sextant/web/interface.html' (properties changed: -x to +x) |
75 | --- resources/sextant/web/interface.html 2014-08-19 09:25:06 +0000 |
76 | +++ resources/sextant/web/interface.html 2014-08-22 14:42:47 +0000 |
77 | @@ -55,9 +55,9 @@ |
78 | All functions calling specific function</option> |
79 | <option value="functions_called_by"> |
80 | All functions called by a specific function</option> |
81 | - <option value="call_paths"> |
82 | + <option value="all_call_paths"> |
83 | All function call paths between two functions</option> |
84 | - <option value="shortest_path"> |
85 | + <option value="shortest_call_path"> |
86 | Shortest path between two functions</option> |
87 | <option value="function_names"> |
88 | All function names</option> |
89 | |
90 | === modified file 'resources/sextant/web/queryjavascript.js' (properties changed: -x to +x) |
91 | --- resources/sextant/web/queryjavascript.js 2014-08-14 15:23:39 +0000 |
92 | +++ resources/sextant/web/queryjavascript.js 2014-08-22 14:42:47 +0000 |
93 | @@ -86,7 +86,7 @@ |
94 | document.getElementById("function_2").style.visibility = "hidden"; |
95 | document.getElementById("function_2").value = null; |
96 | } |
97 | - if (query_list.options[query_list.selectedIndex].value == "call_paths"){ |
98 | + if (query_list.options[query_list.selectedIndex].value == "all_call_paths"){ |
99 | document.getElementById("argument_1").innerHTML = "Function calling"; |
100 | document.getElementById("argument_2").innerHTML = "Function being called"; |
101 | document.getElementById("function_1").readOnly = false; |
102 | @@ -94,7 +94,7 @@ |
103 | document.getElementById("function_1").style.visibility = "visible"; |
104 | document.getElementById("function_2").style.visibility = "visible"; |
105 | } |
106 | - if (query_list.options[query_list.selectedIndex].value == "shortest_path"){ |
107 | + if (query_list.options[query_list.selectedIndex].value == "shortest_call_path"){ |
108 | document.getElementById("argument_1").innerHTML = "Function calling"; |
109 | document.getElementById("argument_2").innerHTML = "Function being called"; |
110 | document.getElementById("function_1").readOnly = false; |
111 | |
112 | === modified file 'src/sextant/__main__.py' (properties changed: -x to +x) |
113 | --- src/sextant/__main__.py 2014-08-21 13:03:24 +0000 |
114 | +++ src/sextant/__main__.py 2014-08-22 14:42:47 +0000 |
115 | @@ -107,34 +107,37 @@ |
116 | |
117 | # add each subparser in turn to the parsers dictionary |
118 | |
119 | -parsers['add'] = subparsers.add_parser('add_program', help="add a program to the database") |
120 | -parsers['add'].add_argument('--input-file', required=True, metavar="FILE_NAME", |
121 | +parsers['add'] = subparsers.add_parser('add-program', |
122 | + help="add a program to the database") |
123 | +parsers['add'].add_argument('input_file', metavar="FILE_NAME", |
124 | help="name of file to be put into database", |
125 | - type=str, nargs=1) |
126 | -parsers['add'].add_argument('--set-file-name', metavar="FILE_NAME", |
127 | + type=str) |
128 | +parsers['add'].add_argument('--name-in-db', metavar="PROGRAM_NAME", |
129 | help="string to store this program under", type=str, |
130 | nargs=1) |
131 | parsers['add'].add_argument('--not-object-file', |
132 | - help='default False, if the input file is an object to be disassembled', |
133 | + help='default False, if the input file is an ' |
134 | + 'object to be disassembled', |
135 | action='store_true') |
136 | |
137 | -parsers['delete'] = subparsers.add_parser('delete_program', |
138 | +parsers['delete'] = subparsers.add_parser('delete-program', |
139 | help="delete a program from the database") |
140 | -parsers['delete'].add_argument('--program-name', required=True, metavar="PROG_NAME", |
141 | +parsers['delete'].add_argument('program_name', metavar="PROG_NAME", |
142 | help="name of program as stored in the database", |
143 | - type=str, nargs=1) |
144 | + type=str) |
145 | |
146 | parsers['query'] = subparsers.add_parser('query', |
147 | help="make a query of the database") |
148 | -parsers['query'].add_argument('--program-name', metavar="PROG_NAME", |
149 | - help="name of program as stored in the database", |
150 | - type=str, nargs=1) |
151 | -parsers['query'].add_argument('--query', required=True, metavar="QUERY", |
152 | +parsers['query'].add_argument('query', metavar="QUERY", |
153 | help="functions-calling, functions-called-by, " |
154 | - "calls-between, whole-graph, shortest-path, " |
155 | - "return-all-program-names or " |
156 | - "return-all-function-names; if the latter, " |
157 | - "supply argument --program-name", |
158 | + "all-call-paths, whole-program, " |
159 | + "shortest-call-path, programs or " |
160 | + "functions; if the latter, " |
161 | + "supply argument --program", |
162 | + type=str) |
163 | +parsers['query'].add_argument('--program', metavar="PROG_NAME", |
164 | + help="name of program as stored in the database; " |
165 | + "required for all queries except 'programs'", |
166 | type=str, nargs=1) |
167 | parsers['query'].add_argument('--funcs', metavar='FUNCS', |
168 | help='functions to pass to the query', |
169 | @@ -168,15 +171,14 @@ |
170 | parsers['web'].set_defaults(func=_start_web) |
171 | |
172 | def add_file(namespace): |
173 | - |
174 | try: |
175 | - alternative_name = namespace.set_file_name[0] |
176 | + alternative_name = namespace.name_in_db[0] |
177 | except TypeError: |
178 | alternative_name = None |
179 | |
180 | not_object_file = namespace.not_object_file |
181 | # the default is "yes, this is an object file" if not-object-file was |
182 | - # unsupplied |
183 | + # unsupplied= |
184 | try: |
185 | update_db.upload_program(namespace.input_file[0], |
186 | namespace.remote_neo4j, |
187 | @@ -193,9 +195,8 @@ |
188 | except ValueError as e: |
189 | logging.error(e) |
190 | |
191 | - |
192 | def delete_file(namespace): |
193 | - update_db.delete_program(namespace.program_name[0], |
194 | + update_db.delete_program(namespace.program_name, |
195 | namespace.remote_neo4j) |
196 | |
197 | parsers['add'].set_defaults(func=add_file) |
198 | @@ -203,7 +204,6 @@ |
199 | |
200 | |
201 | def make_query(namespace): |
202 | - |
203 | arg1 = None |
204 | arg2 = None |
205 | try: |
206 | @@ -211,9 +211,11 @@ |
207 | arg2 = namespace.funcs[1] |
208 | except TypeError: |
209 | pass |
210 | + except IndexError: |
211 | + pass |
212 | |
213 | try: |
214 | - program_name = namespace.program_name[0] |
215 | + program_name = namespace.program[0] |
216 | except TypeError: |
217 | program_name = None |
218 | |
219 | @@ -223,7 +225,7 @@ |
220 | suppress_common = False |
221 | |
222 | query.query(remote_neo4j=namespace.remote_neo4j, |
223 | - input_query=namespace.query[0], |
224 | + input_query=namespace.query, |
225 | program_name=program_name, argument_1=arg1, argument_2=arg2, |
226 | suppress_common=suppress_common) |
227 | |
228 | |
229 | === modified file 'src/sextant/query.py' (properties changed: -x to +x) |
230 | --- src/sextant/query.py 2014-08-19 09:20:45 +0000 |
231 | +++ src/sextant/query.py 2014-08-22 14:42:47 +0000 |
232 | @@ -42,19 +42,19 @@ |
233 | print('Supply one function name to functions-called-by.') |
234 | return 1 |
235 | prog = db.get_all_functions_called(program_name, argument_1) |
236 | - elif input_query == 'calls-between': |
237 | + elif input_query == 'all-call-paths': |
238 | if (argument_1 == None and argument_2 == None): |
239 | print('Supply two function names to calls-between.') |
240 | return 1 |
241 | prog = db.get_call_paths(program_name, argument_1, argument_2) |
242 | - elif input_query == 'whole-graph': |
243 | + elif input_query == 'whole-program': |
244 | prog = db.get_whole_program(program_name) |
245 | - elif input_query == 'shortest-path': |
246 | + elif input_query == 'shortest-call-path': |
247 | if argument_1 == None and argument_2 == None: |
248 | print('Supply two function names to shortest-path.') |
249 | return 1 |
250 | prog = db.get_shortest_path_between_functions(program_name, argument_1, argument_2) |
251 | - elif input_query == 'return-all-function-names': |
252 | + elif input_query == 'functions': |
253 | if program_name != None: |
254 | func_names = db.get_function_names(program_name) |
255 | if func_names: |
256 | @@ -73,7 +73,7 @@ |
257 | print('Server %s contains no functions.' % (remote_neo4j)) |
258 | else: |
259 | names_list = func_list |
260 | - elif input_query == 'return-all-program-names': |
261 | + elif input_query == 'programs': |
262 | list_found = list(db.get_program_names()) |
263 | if not list_found: |
264 | print('No programs were found on server {}.'.format(remote_neo4j)) |
265 | @@ -90,24 +90,5 @@ |
266 | else: |
267 | print('Nothing was returned from the query.') |
268 | |
269 | - |
270 | -def main(): |
271 | - argumentparser = argparse.ArgumentParser(description="Return GraphML representation or list from graph queries.") |
272 | - argumentparser.add_argument('--remote-neo4j', required=True, metavar="URL", help="URL of neo4j server", type=str, nargs=1) |
273 | - argumentparser.add_argument('--program-name', metavar="PROG_NAME", help="name of program as stored in the database", |
274 | - type=str, nargs=1) |
275 | - argumentparser.add_argument('--query', required=True, metavar="QUERY", |
276 | - help="""functions-calling, functions-called-by, calls-between, whole-graph, shortest-path, |
277 | - return-all-program-names or return-all-function-names; if return-all-function-names, |
278 | - supply argument -program-name""", type=str, nargs=1) |
279 | - argumentparser.add_argument('--funcs', metavar='FUNCS', help='functions to pass to the query', type=str, nargs='+') |
280 | - |
281 | - parsed = argumentparser.parse_args() |
282 | - names_list = None |
283 | - |
284 | - query(remote_neo4j=parsed.remote_neo4j[0], input_query=parsed.query[0], arguments=parsed.funcs, |
285 | - program_name=parsed.program_name[0]) |
286 | - |
287 | - |
288 | if __name__ == '__main__': |
289 | main() |
290 | |
291 | === modified file 'src/sextant/web/server.py' (properties changed: -x to +x) |
292 | --- src/sextant/web/server.py 2014-08-20 09:04:45 +0000 |
293 | +++ src/sextant/web/server.py 2014-08-22 14:42:47 +0000 |
294 | @@ -148,7 +148,7 @@ |
295 | defer.returnValue(None) |
296 | func1 = request.args['func1'][0] |
297 | program = yield deferToThread(neo4jconnection.get_all_functions_called, name, func1) |
298 | - elif query == 'call_paths': |
299 | + elif query == 'all_call_paths': |
300 | if 'func1' not in request.args: |
301 | # raise 400 Bad Request error |
302 | request.setResponseCode(400) |
303 | @@ -165,7 +165,7 @@ |
304 | func1 = request.args['func1'][0] |
305 | func2 = request.args['func2'][0] |
306 | program = yield deferToThread(neo4jconnection.get_call_paths, name, func1, func2) |
307 | - elif query == 'shortest_path': |
308 | + elif query == 'shortest_call_path': |
309 | if 'func1' not in request.args: |
310 | # raise 400 Bad Request error |
311 | request.setResponseCode(400) |