File: source_brz.py

package info (click to toggle)
breezy 3.3.21-1
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 40,760 kB
  • sloc: python: 279,676; ansic: 1,093; makefile: 367; sh: 284; lisp: 107
file content (56 lines) | stat: -rw-r--r-- 1,477 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
"""apport package hook for Breezy."""

# Copyright (c) 2009, 2010 Canonical Ltd.
# Author: Matt Zimmerman <mdz@canonical.com>
#         and others

import os

from apport.hookutils import *  # noqa: F403

brz_log = os.path.expanduser("~/.brz.log")
dot_brz = os.path.expanduser("~/.config/breezy")


def _add_log_tail(report):
    # may have already been added in-process
    if "BrzLogTail" in report:
        return

    with open(brz_log) as f:
        brz_log_lines = f.readlines()
    brz_log_lines.reverse()

    brz_log_tail = []
    blanks = 0
    for line in brz_log_lines:
        if line == "\n":
            blanks += 1
        brz_log_tail.append(line)
        if blanks >= 2:
            break

    brz_log_tail.reverse()
    report["BrzLogTail"] = "".join(brz_log_tail)


def add_info(report):
    _add_log_tail(report)
    if "BrzPlugins" not in report:
        # may already be present in-process
        report["BrzPlugins"] = command_output(["brz", "plugins", "-v"])

    # by default assume brz crashes are upstream bugs; this relies on
    # having a brz entry under /etc/apport/crashdb.conf.d/
    report["CrashDB"] = "brz"

    # these may contain some sensitive info (smtp_passwords)
    # TODO: strip that out and attach the rest

    # attach_file_if_exists(report,
    # os.path.join(dot_brz, 'breezy.conf', 'BrzConfig')
    # attach_file_if_exists(report,
    # os.path.join(dot_brz, 'locations.conf', 'BrzLocations')


# vim: expandtab shiftwidth=4