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

« back to all changes in this revision

Viewing changes to data/general-hooks/ubuntu.py

  • Committer: Package Import Robot
  • Author(s): Martin Pitt
  • Date: 2011-01-26 11:44:00 UTC
  • Revision ID: package-import@ubuntu.com-20110126114400-9xbtl47qxbcyx51p
Tags: 1.17.1-0ubuntu3
* data/general-hooks/ubuntu.py: Add some __main__ code for easy testing,
  which will update a .crash file with that hook's data.
* data/general-hooks/ubuntu.py: Trim DpkgTerminaLog to the most recent
  install session; not only is this much easier to read, but it also avoids
  confusing the tests further down which check for particular strings in the
  log. (LP: #580419)

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
    except IOError:
29
29
        return None
30
30
 
 
31
def trim_dpkg_log(report):
 
32
    '''Trim DpkgTerminalLog to the most recent installation session.'''
 
33
 
 
34
    if 'DpkgTerminalLog' not in report:
 
35
        return
 
36
    lines = []
 
37
    trim_re = re.compile('^\(.* ... \d+ .*\)$')
 
38
    for line in report['DpkgTerminalLog'].splitlines():
 
39
        if trim_re.match(line):
 
40
            lines = []
 
41
            continue
 
42
        lines.append(line)
 
43
    report['DpkgTerminalLog'] = '\n'.join(lines)
 
44
 
31
45
def add_info(report):
32
46
    add_tags = []
33
47
 
66
80
    # There are enough of these now that it is probably worth refactoring...
67
81
    # -mdz
68
82
    if report['ProblemType'] == 'Package':
 
83
        trim_dpkg_log(report)
 
84
 
69
85
        if report['Package'] not in ['grub', 'grub2']:
70
86
            # linux-image postinst emits this when update-grub fails
71
87
            # https://wiki.ubuntu.com/KernelTeam/DebuggingUpdateErrors
173
189
            report['Tags'] += ' ' + ' '.join(add_tags)
174
190
        else:
175
191
            report['Tags'] = ' '.join(add_tags)
 
192
 
 
193
if __name__ == '__main__':
 
194
    import sys
 
195
 
 
196
    # for testing: update report file given on command line
 
197
    if len(sys.argv) != 2:
 
198
        print >> sys.stderr, 'Usage for testing this hook: %s <report file>' % sys.argv[0]
 
199
        sys.exit(1)
 
200
 
 
201
    r = apport.Report()
 
202
    r.load(open(sys.argv[1]))
 
203
    add_info(r)
 
204
    f = open(sys.argv[1], 'w')
 
205
    r.write(f)
 
206
    f.close()