~ubuntu-branches/ubuntu/natty/apport/natty-proposed

« back to all changes in this revision

Viewing changes to apport_python_hook.py

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2011-02-04 15:46:40 UTC
  • mfrom: (148.1.35)
  • Revision ID: package-import@ubuntu.com-20110204154640-g7qilc3jix7fv9nr
Tags: 1.17.2-0ubuntu1
* New upstream bug fix release:
  - Be more Python 3 compatible (not fully working with Python 3 yet,
    though).
  - apt/dpkg backend: Drop support for pre-0.7.9 python-apt API.
  - Add --tag option to add extra tags to reports. (LP: #572504)
  - hookutils.py, attach_dmesg(): Do not overwrite already existing dmesg.
  - hookutils.py: Be more robust against file permission errors.
    (LP: #444678)
  - ui.py: Do not show all the options in --help when invoked as *-bug.
    (LP: #665953)
  - launchpad.py: Adapt test cases to current standard_title() behaviour.
* debian/control: Bump python-apt dependency to >= 0.7.9 to ensure that we
  have the current API. Trunk dropped support for the old API.
* data/general-hooks/ubuntu.py: Ignore obsolete packages when filing bugs
  against update-manager. (LP: #397519)
* data/general-hooks/ubuntu.py: Do not file a package install failure if
  DpkgTerminalLog doesn't have any data. (LP: #695887)
* Add debian/apport.postinst: Create /var/crash. This directory is required
  for package failures even if apport is disabled and thus the upstart job
  does not run. (LP: #683367)

Show diffs side-by-side

added added

removed removed

Lines of Context:
48
48
        if not enabled():
49
49
            return
50
50
 
51
 
        from cStringIO import StringIO
 
51
        try:
 
52
            from cStringIO import StringIO
 
53
        except ImportError:
 
54
            from io import StringIO
 
55
 
52
56
        import re, tempfile, traceback
53
57
        from apport.fileutils import likely_packaged
54
58
 
102
106
                # don't clobber existing report
103
107
                return
104
108
        report_file = os.fdopen(os.open(pr_filename,
105
 
            os.O_WRONLY|os.O_CREAT|os.O_EXCL, 0600), 'w')
 
109
            os.O_WRONLY|os.O_CREAT|os.O_EXCL, 0o600), 'w')
106
110
        try:
107
111
            pr.write(report_file)
108
112
        finally:
154
158
func(42)
155
159
''' % extracode)
156
160
                os.close(fd)
157
 
                os.chmod(script, 0755)
 
161
                os.chmod(script, 0o755)
158
162
 
159
163
                p = subprocess.Popen([script, 'testarg1', 'testarg2'],
160
164
                    stdout=subprocess.PIPE, stderr=subprocess.PIPE)
161
165
                err = p.communicate()[1]
162
166
                self.assertEqual(p.returncode, 1,
163
167
                    'crashing test python program exits with failure code')
164
 
                self.assert_('Exception: This should happen.' in err)
 
168
                self.assertTrue('Exception: This should happen.' in err)
165
169
                self.failIf('OSError' in err, err)
166
170
            finally:
167
171
                os.unlink(script)
179
183
            try:
180
184
                self.assertEqual(len(reports), 1, 'crashed Python program produced a report')
181
185
                self.assertEqual(stat.S_IMODE(os.stat(reports[0]).st_mode),
182
 
                    0600, 'report has correct permissions')
 
186
                    0o600, 'report has correct permissions')
183
187
 
184
188
                pr = problem_report.ProblemReport()
185
189
                pr.load(open(reports[0]))
192
196
                'Traceback', 'ProblemType', 'ProcEnviron', 'ProcStatus',
193
197
                'ProcCmdline', 'Date', 'ExecutablePath', 'ProcMaps',
194
198
                'UserGroups']
195
 
            self.assert_(set(expected_keys).issubset(set(pr.keys())),
 
199
            self.assertTrue(set(expected_keys).issubset(set(pr.keys())),
196
200
                'report has necessary fields')
197
 
            self.assert_('bin/python' in pr['InterpreterPath'])
 
201
            self.assertTrue('bin/python' in pr['InterpreterPath'])
198
202
            self.assertEqual(pr['ExecutablePath'], script)
199
203
            self.assertEqual(pr['PythonArgs'], "['%s', 'testarg1', 'testarg2']" % script)
200
 
            self.assert_(pr['Traceback'].startswith('Traceback'))
201
 
            self.assert_("func\n    raise Exception, 'This should happen." in pr['Traceback'])
 
204
            self.assertTrue(pr['Traceback'].startswith('Traceback'))
 
205
            self.assertTrue("func\n    raise Exception, 'This should happen." in pr['Traceback'])
202
206
 
203
207
        def test_existing(self):
204
208
            '''Python crash hook overwrites seen existing files.'''
212
216
                to_del.update(reports)
213
217
                self.assertEqual(len(reports), 1, 'crashed Python program produced a report')
214
218
                self.assertEqual(stat.S_IMODE(os.stat(reports[0]).st_mode),
215
 
                    0600, 'report has correct permissions')
 
219
                    0o600, 'report has correct permissions')
216
220
 
217
221
                # touch report -> "seen" case
218
222
                apport.fileutils.mark_report_seen(reports[0])
246
250
            try:
247
251
                self.assertEqual(len(reports), 1, 'crashed Python program produced a report')
248
252
                self.assertEqual(stat.S_IMODE(os.stat(reports[0]).st_mode),
249
 
                    0600, 'report has correct permissions')
 
253
                    0o600, 'report has correct permissions')
250
254
 
251
255
                pr = problem_report.ProblemReport()
252
256
                pr.load(open(reports[0]))
259
263
                'Traceback', 'ProblemType', 'ProcEnviron', 'ProcStatus',
260
264
                'ProcCmdline', 'Date', 'ExecutablePath', 'ProcMaps',
261
265
                'UserGroups']
262
 
            self.assert_(set(expected_keys).issubset(set(pr.keys())),
 
266
            self.assertTrue(set(expected_keys).issubset(set(pr.keys())),
263
267
                'report has necessary fields')
264
 
            self.assert_('bin/python' in pr['InterpreterPath'])
265
 
            self.assert_(pr['Traceback'].startswith('Traceback'))
 
268
            self.assertTrue('bin/python' in pr['InterpreterPath'])
 
269
            self.assertTrue(pr['Traceback'].startswith('Traceback'))
266
270
 
267
271
        def _assert_no_reports(self):
268
272
            '''Assert that there are no crash reports.'''
310
314
func(42)
311
315
''')
312
316
                os.close(fd)
313
 
                os.chmod(script, 0755)
 
317
                os.chmod(script, 0o755)
314
318
 
315
319
                # move aside current ignore file
316
320
                if os.path.exists(ifpath):
328
332
                err = p.communicate()[1]
329
333
                self.assertEqual(p.returncode, 1,
330
334
                    'crashing test python program exits with failure code')
331
 
                self.assert_('Exception: This should happen.' in err)
 
335
                self.assertTrue('Exception: This should happen.' in err)
332
336
 
333
337
            finally:
334
338
                os.unlink(script)