294
294
If a pid is given on the command line, the report will contain runtime
295
debug information. Either a package or a pid must be specified.
295
debug information. Either a package or a pid must be specified; if none
296
is given, show a list of symptoms.
297
298
If a symptom script is given, this will be run first (used by
300
if not self.options.package and not self.options.pid and not symptom_script:
301
self.ui_error_message(_('No package specified'),
302
_('You need to specify a package or a PID. See --help for more information.'))
301
if not self.options.package and not self.options.pid and \
303
if self.run_symptoms():
306
self.ui_error_message(_('No package specified'),
307
_('You need to specify a package or a PID. See --help for more information.'))
304
310
self.report = apport.Report('Bug')
306
312
# if PID is given, add info
374
def run_symptoms(self):
375
'''Report a bug from a list of available symptoms.
377
Return False if no symptoms are available.
379
scripts = glob.glob(os.path.join(symptom_script_dir, '*.py'))
382
symptom_descriptions = []
383
for script in scripts:
386
execfile(script, symb)
388
print >> sys.stderr, 'symptom script %s is invalid' % script
389
traceback.print_exc()
391
symptom_names.append(os.path.splitext(os.path.basename(script))[0])
392
symptom_descriptions.append(symb.get('description', symptom_names[-1]))
394
if not symptom_names:
397
symptom_names.append(None)
398
symptom_descriptions.append('Other problem')
400
ch = self.ui_question_choice(_('What kind of problem do you want to report?'),
401
symptom_descriptions, False)
404
symptom = symptom_names[ch[0]]
406
self.run_report_bug(os.path.join(symptom_script_dir, symptom + '.py'))
368
412
def run_symptom(self):
369
413
'''Report a bug with a symptom script.'''
408
452
optparser = optparse.OptionParser('%prog [options]')
409
453
optparser.add_option('-f', '--file-bug',
410
help='Start in bug filing mode. Requires --package and an optional --pid, or just a --pid',
454
help='Start in bug filing mode. Requires --package and an optional --pid, or just a --pid. If neither is given, display a list of known symptoms.',
411
455
action='store_true', dest='filebug', default=False)
412
456
optparser.add_option('-s', '--symptom', metavar='SYMPTOM',
413
457
help='File a bug report about a symptom.', dest='symptom')
1124
1169
def ui_question_choice(self, text, options, multiple):
1125
1170
self.msg_text = text
1171
self.msg_choices = options
1126
1172
return self.question_choice_response
1128
1174
def ui_question_file(self, text):
2052
2098
self.assertEqual(self.ui.report['ProblemType'], 'Bug')
2053
2099
self.assertEqual(self.ui.report['q'], 'True')
2101
def test_run_report_bug_list_symptoms(self):
2102
'''run_report_bug() without specifying arguments and available symptoms.'''
2104
f = open(os.path.join(symptom_script_dir, 'foo.py'), 'w')
2105
print >> f, '''description = 'foo does not work'
2106
def run(report, ui):
2110
f = open(os.path.join(symptom_script_dir, 'bar.py'), 'w')
2111
print >> f, 'def run(report, ui):\n return "coreutils"'
2114
sys.argv = ['ui-test', '-f']
2115
self.ui = _TestSuiteUserInterface()
2117
self.ui.question_choice_response = None
2118
self.assertEqual(self.ui.run_argv(), True)
2119
self.assertEqual(self.ui.msg_severity, None)
2120
self.assert_('kind of problem' in self.ui.msg_text)
2121
self.assertEqual(self.ui.msg_choices,
2122
['bar', 'foo does not work', 'Other problem'])
2125
self.assertEqual(self.ui.ic_progress_pulses, 0)
2126
self.assertEqual(self.ui.report, None)
2128
# now, choose foo -> bash report
2129
self.ui.question_choice_response = [1]
2130
self.assertEqual(self.ui.run_argv(), True)
2131
self.assertEqual(self.ui.msg_severity, None)
2132
self.assert_(self.ui.ic_progress_pulses > 0)
2133
self.assert_(self.ui.report['Package'].startswith('bash'))
2055
2135
unittest.main()