mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-03-13 08:01:09 +00:00
questions
This commit is contained in:
parent
1558b91dde
commit
ea74634e93
@ -16,10 +16,15 @@
|
|||||||
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
# ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
||||||
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
# OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import tempfile
|
import tempfile
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import sys
|
import sys
|
||||||
|
if sys.version_info[0] < 3:
|
||||||
|
input = raw_input
|
||||||
|
|
||||||
|
|
||||||
import ubuntutools.subprocess
|
import ubuntutools.subprocess
|
||||||
|
|
||||||
@ -56,9 +61,9 @@ class Question(object):
|
|||||||
selected = None
|
selected = None
|
||||||
while selected not in self.options:
|
while selected not in self.options:
|
||||||
try:
|
try:
|
||||||
selected = raw_input(question).strip().lower()
|
selected = input(question).strip().lower()
|
||||||
except (EOFError, KeyboardInterrupt):
|
except (EOFError, KeyboardInterrupt):
|
||||||
print '\nAborting as requested.'
|
print('\nAborting as requested.')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
if selected == "":
|
if selected == "":
|
||||||
selected = default
|
selected = default
|
||||||
@ -68,8 +73,8 @@ class Question(object):
|
|||||||
if selected == option[0]:
|
if selected == option[0]:
|
||||||
selected = option
|
selected = option
|
||||||
if selected not in self.options:
|
if selected not in self.options:
|
||||||
print "Please answer the question with " + \
|
print("Please answer the question with " + \
|
||||||
self.get_options() + "."
|
self.get_options() + ".")
|
||||||
return selected
|
return selected
|
||||||
|
|
||||||
|
|
||||||
@ -86,9 +91,9 @@ def input_number(question, min_number, max_number, default=None):
|
|||||||
selected = None
|
selected = None
|
||||||
while selected < min_number or selected > max_number:
|
while selected < min_number or selected > max_number:
|
||||||
try:
|
try:
|
||||||
selected = raw_input(question).strip()
|
selected = input(question).strip()
|
||||||
except (EOFError, KeyboardInterrupt):
|
except (EOFError, KeyboardInterrupt):
|
||||||
print '\nAborting as requested.'
|
print('\nAborting as requested.')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
if default and selected == "":
|
if default and selected == "":
|
||||||
selected = default
|
selected = default
|
||||||
@ -96,10 +101,10 @@ def input_number(question, min_number, max_number, default=None):
|
|||||||
try:
|
try:
|
||||||
selected = int(selected)
|
selected = int(selected)
|
||||||
if selected < min_number or selected > max_number:
|
if selected < min_number or selected > max_number:
|
||||||
print "Please input a number between %i and %i." % \
|
print("Please input a number between %i and %i." % \
|
||||||
(min_number, max_number)
|
(min_number, max_number))
|
||||||
except ValueError:
|
except ValueError:
|
||||||
print "Please input a number."
|
print("Please input a number.")
|
||||||
assert type(selected) == int
|
assert type(selected) == int
|
||||||
return selected
|
return selected
|
||||||
|
|
||||||
@ -113,9 +118,9 @@ def confirmation_prompt(message=None, action=None):
|
|||||||
action = 'continue'
|
action = 'continue'
|
||||||
message = 'Press [Enter] to %s. Press [Ctrl-C] to abort now.' % action
|
message = 'Press [Enter] to %s. Press [Ctrl-C] to abort now.' % action
|
||||||
try:
|
try:
|
||||||
raw_input(message)
|
input(message)
|
||||||
except (EOFError, KeyboardInterrupt):
|
except (EOFError, KeyboardInterrupt):
|
||||||
print '\nAborting as requested.'
|
print('\nAborting as requested.')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
|
|
||||||
@ -129,9 +134,9 @@ class EditFile(object):
|
|||||||
|
|
||||||
def edit(self, optional=False):
|
def edit(self, optional=False):
|
||||||
if optional:
|
if optional:
|
||||||
print "\n\nCurrently the %s looks like:" % self.description
|
print("\n\nCurrently the %s looks like:" % self.description)
|
||||||
with open(self.filename, 'r') as f:
|
with open(self.filename, 'r') as f:
|
||||||
print f.read()
|
print(f.read())
|
||||||
if YesNoQuestion().ask("Edit", "no") == "no":
|
if YesNoQuestion().ask("Edit", "no") == "no":
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -150,12 +155,12 @@ class EditFile(object):
|
|||||||
placeholders_present = True
|
placeholders_present = True
|
||||||
|
|
||||||
if placeholders_present:
|
if placeholders_present:
|
||||||
print ("Placeholders still present in the %s. "
|
print("Placeholders still present in the %s. "
|
||||||
"Please replace them with useful information."
|
"Please replace them with useful information."
|
||||||
% self.description)
|
% self.description)
|
||||||
confirmation_prompt(action='edit again')
|
confirmation_prompt(action='edit again')
|
||||||
elif not modified:
|
elif not modified:
|
||||||
print "The %s was not modified" % self.description
|
print("The %s was not modified" % self.description)
|
||||||
if YesNoQuestion().ask("Edit again", "yes") == "no":
|
if YesNoQuestion().ask("Edit again", "yes") == "no":
|
||||||
done = True
|
done = True
|
||||||
elif self.check_edit():
|
elif self.check_edit():
|
||||||
@ -189,8 +194,8 @@ class EditBugReport(EditFile):
|
|||||||
report = f.read().decode('utf-8')
|
report = f.read().decode('utf-8')
|
||||||
|
|
||||||
if self.split_re.match(report) is None:
|
if self.split_re.match(report) is None:
|
||||||
print ("The %s doesn't start with 'Summary:' and 'Description:' "
|
print("The %s doesn't start with 'Summary:' and 'Description:' "
|
||||||
"blocks" % self.description)
|
"blocks" % self.description)
|
||||||
confirmation_prompt('edit again')
|
confirmation_prompt('edit again')
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
Loading…
x
Reference in New Issue
Block a user