Merge lp:~jamesh-f/ensoft-sextant/argparse-name-changes into lp:ensoft-sextant

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
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
11. By James Harkin <email address hidden>

Documentation update ready for audit merge.

12. By James Harkin <email address hidden>

diff changes to documentation extra bracket

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
=== modified file 'doc/Program_upload_docs.mkd' (properties changed: -x to +x)
--- doc/Program_upload_docs.mkd 2014-08-12 13:30:24 +0000
+++ doc/Program_upload_docs.mkd 2014-08-22 14:42:47 +0000
@@ -5,5 +5,5 @@
5Optionally, 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.5Optionally, 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.
66
7# Query parameters7# Query parameters
8We 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.8The 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.
9Optional (if specified in config file) `--remote-neo4j`, the location of the Neo4J server (eg. `http://localhost:7474`).9Optional (if specified in config file) `--remote-neo4j`, the location of the Neo4J server (eg. `http://localhost:7474`).
10\ No newline at end of file10\ No newline at end of file
1111
=== modified file 'doc/wiki/Reference' (properties changed: -x to +x)
--- doc/wiki/Reference 2014-08-13 15:18:11 +0000
+++ doc/wiki/Reference 2014-08-22 14:42:47 +0000
@@ -10,31 +10,32 @@
10== File Management ==10== File Management ==
11No more than one program can have the same name in the database.11No more than one program can have the same name in the database.
12=== Uploading a File ===12=== Uploading a File ===
13set-file-name and not-object-file are optional.13{{{ --name-in-db }}} and {{{ --not-object-file }}} are optional.
14{{{14{{{
15sextant 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)>15sextant 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)>
16}}}16}}}
17=== Deleting File ===17=== Deleting File ===
18It is good practice to delete files from the server since having many graphs in the database can lead to negative effects on performance.18It is good practice to wipe files from the server since having many graphs in the database can lead to negative effects on performance.
19{{{19{{{
20sextant delete_program --program name <program name to be deleted as stored in database>20sextant delete-program <program name to be deleted as stored in database>
21}}}21}}}
22== Queries ==22== Queries ==
23=== Command Line ===23=== Command Line ===
24Command line queries produce a text output, either as a list or in GraphML which can be opened in yED.24Command line queries produce a text output, either as a list or in GraphML which can be opened in yED.
25All queries take the form.25All queries take the form.
26{{{26{{{
27sextant 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)>27sextant 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)>
28}}}28}}}
29Here 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.29Regarding 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.
30The options for queries are:30 || {{{ query }}} || {{{ --funcs }}} || {{{ --program }}} || {{{ --suppress-common }}} ||
31 * functions-calling,31 || {{{ functions-calling }}} || *1 || *1 || opt ||
32 * functions-called-by,32 || {{{ functions-called-by }}} || *1 || *1 || opt ||
33 * calls-between,33 || {{{ all-call-paths }}} || *2 || *1 || opt ||
34 * whole-graph,34 || {{{ whole-program }}} || *0 || *1 || opt ||
35 * shortest-path,35 || {{{ shortest-call-path }}} || *2 || *1 || *0 ||
36 * return-all-program-names,36 || {{{ programs }}} || *0 || *0 || *0 ||
37 * return-all-function-names.37 || {{{ functions }}} || *0 || *1 || *0 ||
38A number signifies the number of arguments required, opt means the argument is allowed but is optional.
38For help with queries from the command line and the arguments type:39For help with queries from the command line and the arguments type:
39{{{40{{{
40sextant query -h41sextant query -h
@@ -42,4 +43,6 @@
42=== Web ===43=== Web ===
43To run the web server type44To run the web server type
44{{{ sextant web }}}45{{{ sextant web }}}
45into the command line; then navigate a web browser to the port specified.
46\ No newline at end of file46\ No newline at end of file
47into the command line; then navigate a web browser to the port specified.
48== Audit ==
49To 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.
47\ No newline at end of file50\ No newline at end of file
4851
=== modified file 'resources/sextant/web/interface.html' (properties changed: -x to +x)
--- resources/sextant/web/interface.html 2014-08-19 09:25:06 +0000
+++ resources/sextant/web/interface.html 2014-08-22 14:42:47 +0000
@@ -55,9 +55,9 @@
55 All functions calling specific function</option>55 All functions calling specific function</option>
56 <option value="functions_called_by">56 <option value="functions_called_by">
57 All functions called by a specific function</option>57 All functions called by a specific function</option>
58 <option value="call_paths">58 <option value="all_call_paths">
59 All function call paths between two functions</option>59 All function call paths between two functions</option>
60 <option value="shortest_path">60 <option value="shortest_call_path">
61 Shortest path between two functions</option>61 Shortest path between two functions</option>
62 <option value="function_names">62 <option value="function_names">
63 All function names</option>63 All function names</option>
6464
=== modified file 'resources/sextant/web/queryjavascript.js' (properties changed: -x to +x)
--- resources/sextant/web/queryjavascript.js 2014-08-14 15:23:39 +0000
+++ resources/sextant/web/queryjavascript.js 2014-08-22 14:42:47 +0000
@@ -86,7 +86,7 @@
86 document.getElementById("function_2").style.visibility = "hidden";86 document.getElementById("function_2").style.visibility = "hidden";
87 document.getElementById("function_2").value = null;87 document.getElementById("function_2").value = null;
88 }88 }
89 if (query_list.options[query_list.selectedIndex].value == "call_paths"){89 if (query_list.options[query_list.selectedIndex].value == "all_call_paths"){
90 document.getElementById("argument_1").innerHTML = "Function calling";90 document.getElementById("argument_1").innerHTML = "Function calling";
91 document.getElementById("argument_2").innerHTML = "Function being called";91 document.getElementById("argument_2").innerHTML = "Function being called";
92 document.getElementById("function_1").readOnly = false;92 document.getElementById("function_1").readOnly = false;
@@ -94,7 +94,7 @@
94 document.getElementById("function_1").style.visibility = "visible";94 document.getElementById("function_1").style.visibility = "visible";
95 document.getElementById("function_2").style.visibility = "visible";95 document.getElementById("function_2").style.visibility = "visible";
96 }96 }
97 if (query_list.options[query_list.selectedIndex].value == "shortest_path"){97 if (query_list.options[query_list.selectedIndex].value == "shortest_call_path"){
98 document.getElementById("argument_1").innerHTML = "Function calling";98 document.getElementById("argument_1").innerHTML = "Function calling";
99 document.getElementById("argument_2").innerHTML = "Function being called";99 document.getElementById("argument_2").innerHTML = "Function being called";
100 document.getElementById("function_1").readOnly = false;100 document.getElementById("function_1").readOnly = false;
101101
=== modified file 'src/sextant/__main__.py' (properties changed: -x to +x)
--- src/sextant/__main__.py 2014-08-21 13:03:24 +0000
+++ src/sextant/__main__.py 2014-08-22 14:42:47 +0000
@@ -107,34 +107,37 @@
107107
108# add each subparser in turn to the parsers dictionary108# add each subparser in turn to the parsers dictionary
109109
110parsers['add'] = subparsers.add_parser('add_program', help="add a program to the database")110parsers['add'] = subparsers.add_parser('add-program',
111parsers['add'].add_argument('--input-file', required=True, metavar="FILE_NAME",111 help="add a program to the database")
112parsers['add'].add_argument('input_file', metavar="FILE_NAME",
112 help="name of file to be put into database",113 help="name of file to be put into database",
113 type=str, nargs=1)114 type=str)
114parsers['add'].add_argument('--set-file-name', metavar="FILE_NAME",115parsers['add'].add_argument('--name-in-db', metavar="PROGRAM_NAME",
115 help="string to store this program under", type=str,116 help="string to store this program under", type=str,
116 nargs=1)117 nargs=1)
117parsers['add'].add_argument('--not-object-file',118parsers['add'].add_argument('--not-object-file',
118 help='default False, if the input file is an object to be disassembled',119 help='default False, if the input file is an '
120 'object to be disassembled',
119 action='store_true')121 action='store_true')
120122
121parsers['delete'] = subparsers.add_parser('delete_program',123parsers['delete'] = subparsers.add_parser('delete-program',
122 help="delete a program from the database")124 help="delete a program from the database")
123parsers['delete'].add_argument('--program-name', required=True, metavar="PROG_NAME",125parsers['delete'].add_argument('program_name', metavar="PROG_NAME",
124 help="name of program as stored in the database",126 help="name of program as stored in the database",
125 type=str, nargs=1)127 type=str)
126128
127parsers['query'] = subparsers.add_parser('query',129parsers['query'] = subparsers.add_parser('query',
128 help="make a query of the database")130 help="make a query of the database")
129parsers['query'].add_argument('--program-name', metavar="PROG_NAME",131parsers['query'].add_argument('query', metavar="QUERY",
130 help="name of program as stored in the database",
131 type=str, nargs=1)
132parsers['query'].add_argument('--query', required=True, metavar="QUERY",
133 help="functions-calling, functions-called-by, "132 help="functions-calling, functions-called-by, "
134 "calls-between, whole-graph, shortest-path, "133 "all-call-paths, whole-program, "
135 "return-all-program-names or "134 "shortest-call-path, programs or "
136 "return-all-function-names; if the latter, "135 "functions; if the latter, "
137 "supply argument --program-name",136 "supply argument --program",
137 type=str)
138parsers['query'].add_argument('--program', metavar="PROG_NAME",
139 help="name of program as stored in the database; "
140 "required for all queries except 'programs'",
138 type=str, nargs=1)141 type=str, nargs=1)
139parsers['query'].add_argument('--funcs', metavar='FUNCS',142parsers['query'].add_argument('--funcs', metavar='FUNCS',
140 help='functions to pass to the query',143 help='functions to pass to the query',
@@ -168,15 +171,14 @@
168parsers['web'].set_defaults(func=_start_web)171parsers['web'].set_defaults(func=_start_web)
169172
170def add_file(namespace):173def add_file(namespace):
171
172 try:174 try:
173 alternative_name = namespace.set_file_name[0]175 alternative_name = namespace.name_in_db[0]
174 except TypeError:176 except TypeError:
175 alternative_name = None177 alternative_name = None
176178
177 not_object_file = namespace.not_object_file179 not_object_file = namespace.not_object_file
178 # the default is "yes, this is an object file" if not-object-file was180 # the default is "yes, this is an object file" if not-object-file was
179 # unsupplied181 # unsupplied=
180 try:182 try:
181 update_db.upload_program(namespace.input_file[0],183 update_db.upload_program(namespace.input_file[0],
182 namespace.remote_neo4j,184 namespace.remote_neo4j,
@@ -193,9 +195,8 @@
193 except ValueError as e:195 except ValueError as e:
194 logging.error(e)196 logging.error(e)
195197
196
197def delete_file(namespace):198def delete_file(namespace):
198 update_db.delete_program(namespace.program_name[0],199 update_db.delete_program(namespace.program_name,
199 namespace.remote_neo4j)200 namespace.remote_neo4j)
200201
201parsers['add'].set_defaults(func=add_file)202parsers['add'].set_defaults(func=add_file)
@@ -203,7 +204,6 @@
203204
204205
205def make_query(namespace):206def make_query(namespace):
206
207 arg1 = None207 arg1 = None
208 arg2 = None208 arg2 = None
209 try:209 try:
@@ -211,9 +211,11 @@
211 arg2 = namespace.funcs[1]211 arg2 = namespace.funcs[1]
212 except TypeError:212 except TypeError:
213 pass213 pass
214 except IndexError:
215 pass
214216
215 try:217 try:
216 program_name = namespace.program_name[0]218 program_name = namespace.program[0]
217 except TypeError:219 except TypeError:
218 program_name = None220 program_name = None
219221
@@ -223,7 +225,7 @@
223 suppress_common = False225 suppress_common = False
224226
225 query.query(remote_neo4j=namespace.remote_neo4j,227 query.query(remote_neo4j=namespace.remote_neo4j,
226 input_query=namespace.query[0],228 input_query=namespace.query,
227 program_name=program_name, argument_1=arg1, argument_2=arg2,229 program_name=program_name, argument_1=arg1, argument_2=arg2,
228 suppress_common=suppress_common)230 suppress_common=suppress_common)
229231
230232
=== modified file 'src/sextant/query.py' (properties changed: -x to +x)
--- src/sextant/query.py 2014-08-19 09:20:45 +0000
+++ src/sextant/query.py 2014-08-22 14:42:47 +0000
@@ -42,19 +42,19 @@
42 print('Supply one function name to functions-called-by.')42 print('Supply one function name to functions-called-by.')
43 return 143 return 1
44 prog = db.get_all_functions_called(program_name, argument_1)44 prog = db.get_all_functions_called(program_name, argument_1)
45 elif input_query == 'calls-between':45 elif input_query == 'all-call-paths':
46 if (argument_1 == None and argument_2 == None):46 if (argument_1 == None and argument_2 == None):
47 print('Supply two function names to calls-between.')47 print('Supply two function names to calls-between.')
48 return 148 return 1
49 prog = db.get_call_paths(program_name, argument_1, argument_2)49 prog = db.get_call_paths(program_name, argument_1, argument_2)
50 elif input_query == 'whole-graph':50 elif input_query == 'whole-program':
51 prog = db.get_whole_program(program_name)51 prog = db.get_whole_program(program_name)
52 elif input_query == 'shortest-path':52 elif input_query == 'shortest-call-path':
53 if argument_1 == None and argument_2 == None:53 if argument_1 == None and argument_2 == None:
54 print('Supply two function names to shortest-path.')54 print('Supply two function names to shortest-path.')
55 return 155 return 1
56 prog = db.get_shortest_path_between_functions(program_name, argument_1, argument_2)56 prog = db.get_shortest_path_between_functions(program_name, argument_1, argument_2)
57 elif input_query == 'return-all-function-names':57 elif input_query == 'functions':
58 if program_name != None:58 if program_name != None:
59 func_names = db.get_function_names(program_name)59 func_names = db.get_function_names(program_name)
60 if func_names:60 if func_names:
@@ -73,7 +73,7 @@
73 print('Server %s contains no functions.' % (remote_neo4j))73 print('Server %s contains no functions.' % (remote_neo4j))
74 else:74 else:
75 names_list = func_list75 names_list = func_list
76 elif input_query == 'return-all-program-names':76 elif input_query == 'programs':
77 list_found = list(db.get_program_names())77 list_found = list(db.get_program_names())
78 if not list_found:78 if not list_found:
79 print('No programs were found on server {}.'.format(remote_neo4j))79 print('No programs were found on server {}.'.format(remote_neo4j))
@@ -90,24 +90,5 @@
90 else:90 else:
91 print('Nothing was returned from the query.')91 print('Nothing was returned from the query.')
9292
93
94def main():
95 argumentparser = argparse.ArgumentParser(description="Return GraphML representation or list from graph queries.")
96 argumentparser.add_argument('--remote-neo4j', required=True, metavar="URL", help="URL of neo4j server", type=str, nargs=1)
97 argumentparser.add_argument('--program-name', metavar="PROG_NAME", help="name of program as stored in the database",
98 type=str, nargs=1)
99 argumentparser.add_argument('--query', required=True, metavar="QUERY",
100 help="""functions-calling, functions-called-by, calls-between, whole-graph, shortest-path,
101 return-all-program-names or return-all-function-names; if return-all-function-names,
102 supply argument -program-name""", type=str, nargs=1)
103 argumentparser.add_argument('--funcs', metavar='FUNCS', help='functions to pass to the query', type=str, nargs='+')
104
105 parsed = argumentparser.parse_args()
106 names_list = None
107
108 query(remote_neo4j=parsed.remote_neo4j[0], input_query=parsed.query[0], arguments=parsed.funcs,
109 program_name=parsed.program_name[0])
110
111
112if __name__ == '__main__':93if __name__ == '__main__':
113 main()94 main()
11495
=== modified file 'src/sextant/web/server.py' (properties changed: -x to +x)
--- src/sextant/web/server.py 2014-08-20 09:04:45 +0000
+++ src/sextant/web/server.py 2014-08-22 14:42:47 +0000
@@ -148,7 +148,7 @@
148 defer.returnValue(None)148 defer.returnValue(None)
149 func1 = request.args['func1'][0]149 func1 = request.args['func1'][0]
150 program = yield deferToThread(neo4jconnection.get_all_functions_called, name, func1)150 program = yield deferToThread(neo4jconnection.get_all_functions_called, name, func1)
151 elif query == 'call_paths':151 elif query == 'all_call_paths':
152 if 'func1' not in request.args:152 if 'func1' not in request.args:
153 # raise 400 Bad Request error153 # raise 400 Bad Request error
154 request.setResponseCode(400)154 request.setResponseCode(400)
@@ -165,7 +165,7 @@
165 func1 = request.args['func1'][0]165 func1 = request.args['func1'][0]
166 func2 = request.args['func2'][0]166 func2 = request.args['func2'][0]
167 program = yield deferToThread(neo4jconnection.get_call_paths, name, func1, func2)167 program = yield deferToThread(neo4jconnection.get_call_paths, name, func1, func2)
168 elif query == 'shortest_path':168 elif query == 'shortest_call_path':
169 if 'func1' not in request.args:169 if 'func1' not in request.args:
170 # raise 400 Bad Request error170 # raise 400 Bad Request error
171 request.setResponseCode(400)171 request.setResponseCode(400)

Subscribers

People subscribed via source and target branches