Merge lp:~rackspace-titan/glance/glance-user-confirm into lp:~hudson-openstack/glance/trunk

Proposed by Brian Waldon
Status: Merged
Approved by: Jay Pipes
Approved revision: 127
Merged at revision: 124
Proposed branch: lp:~rackspace-titan/glance/glance-user-confirm
Merge into: lp:~hudson-openstack/glance/trunk
Diff against target: 53 lines (+21/-7)
1 file modified
bin/glance (+21/-7)
To merge this branch: bzr merge lp:~rackspace-titan/glance/glance-user-confirm
Reviewer Review Type Date Requested Status
Jay Pipes (community) Approve
Dan Prince (community) Approve
Vish Ishaya (community) Approve
Review via email: mp+58822@code.launchpad.net

Description of the change

Expanding user confirmation default behavior.

To post a comment you must log in.
Revision history for this message
Vish Ishaya (vishvananda) wrote :

37 + answer = raw_input("%s %s " % (prompt,prompt_default))

missed a space. Pep8 it?

Otherwise lgtm.

review: Approve
125. By Brian Waldon

docstring and exception handling

126. By Brian Waldon

pep8 fixes

Revision history for this message
Brian Waldon (bcwaldon) wrote :

> 37 + answer = raw_input("%s %s " % (prompt,prompt_default))
>
>
> missed a space. Pep8 it?
>
> Otherwise lgtm.

Got it. Also made one small functional change when an exception is caught.

Revision history for this message
Brian Waldon (bcwaldon) wrote :

> Got it. Also made one small functional change when an exception is caught.

Thinking about it more, it doesn't make sense to "return default" in an exception-case. Would "return not default" make sense? I don't want a delete to succeed when something legitimately wrong occurred.

Revision history for this message
Vish Ishaya (vishvananda) wrote :

no i don't like return not default. I actually think it might be a little excessive to try to catch an exception here and continue. Perhaps it is to handle the case when there is no tty? In that case i suppose return default would make sense. Otherwise I prefer just letting the exception bubble up.

Revision history for this message
Dan Prince (dan-prince) wrote :

You could let the exception trickle up? (not handle it).

I don't think returning 'not default' makes sense and could be dangerous.

Revision history for this message
Brian Waldon (bcwaldon) wrote :

Ok. I removed the except block. Should be good to go, now.

127. By Brian Waldon

removing excessive exception handling

Revision history for this message
Dan Prince (dan-prince) wrote :

Works great. Approve.

review: Approve
Revision history for this message
Jay Pipes (jaypipes) wrote :

yup, lgtm.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'bin/glance'
2--- bin/glance 2011-04-20 23:58:10 +0000
3+++ bin/glance 2011-04-22 15:16:29 +0000
4@@ -317,7 +317,7 @@
5 return FAILURE
6
7 if not options.force and \
8- not user_confirm("Delete image %s?" % (image_id,)):
9+ not user_confirm("Delete image %s?" % (image_id,), default=False):
10 print 'Not deleting image %s' % (image_id,)
11 return FAILURE
12
13@@ -434,7 +434,8 @@
14 %(prog)s clear [options]
15
16 Deletes all images from a Glance server"""
17- if not options.force and not user_confirm("Delete all images?"):
18+ if not options.force and \
19+ not user_confirm("Delete all images?", default=False):
20 print 'Not deleting any images'
21 return FAILURE
22
23@@ -546,12 +547,25 @@
24 print COMMANDS[command].__doc__ % {'prog': os.path.basename(sys.argv[0])}
25
26
27-def user_confirm(prompt):
28- try:
29- answer = raw_input("%s [Y/n] " % (prompt,))
30+def user_confirm(prompt, default=False):
31+ """Yes/No question dialog with user.
32+
33+ :param prompt: question/statement to present to user (string)
34+ :param default: boolean value to return if empty string
35+ is received as response to prompt
36+
37+ """
38+ if default:
39+ prompt_default = "[Y/n]"
40+ else:
41+ prompt_default = "[y/N]"
42+
43+ answer = raw_input("%s %s " % (prompt, prompt_default))
44+
45+ if answer == "":
46+ return default
47+ else:
48 return answer.lower() in ("yes", "y")
49- except Exception:
50- return False
51
52
53 if __name__ == '__main__':

Subscribers

People subscribed via source and target branches