Merge lp:~ben-hutchings/ensoft-sextant/upload-default-name into lp:ensoft-sextant

Proposed by Ben Hutchings
Status: Merged
Approved by: Robert
Approved revision: 26
Merged at revision: 28
Proposed branch: lp:~ben-hutchings/ensoft-sextant/upload-default-name
Merge into: lp:ensoft-sextant
Diff against target: 98 lines (+16/-22)
2 files modified
src/sextant/__main__.py (+3/-1)
src/sextant/update_db.py (+13/-21)
To merge this branch: bzr merge lp:~ben-hutchings/ensoft-sextant/upload-default-name
Reviewer Review Type Date Requested Status
Robert Approve
Review via email: mp+236344@code.launchpad.net

This proposal supersedes a proposal from 2014-09-26.

Commit message

Change default program name format to include user name; tidy up some logging messages.

Description of the change

Tidied up some logging messages.

To post a comment you must log in.
Revision history for this message
Robert (rjwills) : Posted in a previous version of this proposal
review: Needs Fixing
Revision history for this message
Robert (rjwills) :
review: Approve

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-09-26 11:25:09 +0000
3+++ src/sextant/__main__.py 2014-09-29 14:08:47 +0000
4@@ -17,6 +17,7 @@
5 import requests
6 import contextlib
7 import subprocess
8+import getpass
9
10 try:
11 from urllib import parse
12@@ -102,7 +103,8 @@
13 # unsupplied
14
15 try:
16- update_db.upload_program(file_path=args.input_file,
17+ update_db.upload_program(user_name=getpass.getuser(),
18+ file_path=args.input_file,
19 db_url=args.remote_neo4j,
20 alternative_name=alternative_name,
21 not_object_file=not_object_file,
22
23=== modified file 'src/sextant/update_db.py'
24--- src/sextant/update_db.py 2014-08-26 16:33:20 +0000
25+++ src/sextant/update_db.py 2014-09-29 14:08:47 +0000
26@@ -9,13 +9,13 @@
27
28 from .db_api import SextantConnection, Validator
29 from .objdump_parser import get_parsed_objects
30+from os import path
31
32 import logging
33
34
35-def upload_program(file_path, db_url, display_url='',
36- alternative_name=None,
37- not_object_file=False):
38+def upload_program(user_name, file_path, db_url, display_url='',
39+ alternative_name=None, not_object_file=False):
40 """
41 Uploads a program to the remote database.
42
43@@ -34,19 +34,16 @@
44 if not display_url:
45 display_url = db_url
46
47+ # if no name is specified, use the form "<username>-<binary name>"
48+ name = alternative_name or (user_name + '-' + path.split(file_path)[-1])
49+
50 connection = SextantConnection(db_url)
51
52 program_names = connection.get_program_names()
53- if alternative_name is None:
54- if Validator.sanitise(file_path) in program_names:
55- raise ValueError("There is already a program under this name; "
56- "please delete the previous one with the same name"
57- " and retry, or rename the input file.")
58- else:
59- if Validator.sanitise(alternative_name) in program_names:
60- raise ValueError("There is already a program under this name; "
61- "please delete the previous one with the same name"
62- " and retry, or rename the input file.")
63+ if Validator.sanitise(name) in program_names:
64+ raise ValueError("There is already a program with name {}; "
65+ "please delete the previous one with the same name "
66+ "and retry, or rename the input file.".format(name))
67
68 parsed_objects = get_parsed_objects(filepath=file_path,
69 sections_to_view=['.text'],
70@@ -55,12 +52,7 @@
71
72 logging.info('Objdump has parsed!')
73
74- if alternative_name is None:
75- program_representation = connection.new_program(
76- Validator.sanitise(file_path))
77- else:
78- program_representation = connection.new_program(
79- Validator.sanitise(alternative_name))
80+ program_representation = connection.new_program(Validator.sanitise(name))
81
82 for obj in parsed_objects:
83 for called in obj.what_do_i_call:
84@@ -69,7 +61,7 @@
85
86 logging.info('Sending {} named objects to server {}...'.format(len(parsed_objects), display_url))
87 program_representation.commit()
88- logging.info('Sending complete! Exiting.')
89+ logging.info('Successfully added {}.'.format(name))
90
91
92 def delete_program(program_name, db_url):
93@@ -81,4 +73,4 @@
94 """
95 connection = SextantConnection(db_url)
96 connection.delete_program(program_name)
97- print('Deleted {} successfully.'.format(program_name))
98+ print('Successfully deleted {}.'.format(program_name))

Subscribers

People subscribed via source and target branches