~chromium-team/chromium-browser/eoan-stable

558.1.77 by Fabien Tassin
* Add some apport hooks adding useful information to the bugs
1
'''chromium apport hook
2
3
/usr/share/apport/package-hooks/chromium-browser.py
4
5
Copyright (c) 2010, Fabien Tassin <fta@sofaraway.org>
1494.1.1 by Olivier Tilloy
* Upstream release: 75.0.3770.80
6
Copyright (c) 2014-2019, Canonical
558.1.77 by Fabien Tassin
* Add some apport hooks adding useful information to the bugs
7
8
This program is free software; you can redistribute it and/or modify it
9
under the terms of the GNU General Public License as published by the
10
Free Software Foundation; either version 2 of the License, or (at your
11
option) any later version.  See http://www.gnu.org/copyleft/gpl.html for
12
the full text of the license.
13
'''
14
1494.1.1 by Olivier Tilloy
* Upstream release: 75.0.3770.80
15
import hashlib
16
import json
17
import os
18
import os.path
19
import re
558.1.77 by Fabien Tassin
* Add some apport hooks adding useful information to the bugs
20
import apport.hookutils
1494.1.1 by Olivier Tilloy
* Upstream release: 75.0.3770.80
21
22
23
SNAP_USER_DATA = os.path.expanduser('~/snap/chromium/current')
24
558.1.77 by Fabien Tassin
* Add some apport hooks adding useful information to the bugs
25
1052 by Chad MILLER
debian/apport: Significant cleanup.
26
def user_prefs(report, filename):
27
    with open(filename, 'r') as f:
1494.1.1 by Olivier Tilloy
* Upstream release: 75.0.3770.80
28
        prefs = json.load(f)
29
    entries = []
30
    if 'extensions' in prefs:
31
        extensions = prefs['extensions']
32
        if 'theme' in extensions:
33
            theme = extensions['theme']
34
            if 'use_system' in theme:
35
                entries.append('extensions.theme.use_system = {}'.format(
36
                    theme['use_system']))
37
        if 'settings' in extensions:
38
            settings = extensions['settings']
39
            if settings:
40
                entries.append('extensions:')
41
            for key in settings.keys():
42
                extension = settings[key]
43
                entries.append('  {}:'.format(key))
44
                if 'manifest' in extension:
45
                    manifest = extension['manifest']
46
                    for mkey in ('name', 'version', 'key'):
47
                        entries.append('    {} = {}'.format(mkey,
48
                                                            manifest[mkey]))
49
                if 'state' in extension:
50
                    entries.append('    state = {}'.format(extension['state']))
51
    report['Snap.ChromiumPrefs'] = '\n'.join(entries)
52
53
54
def run_cmd(cmd):
55
    return apport.hookutils.command_output(cmd)
56
57
58
def add_info(report, hookui):
59
    for snap in ['core', 'core18', 'chromium', 'gtk-common-themes']:
60
        report['Snap.Info.{}'.format(snap)] = \
61
            run_cmd(['snap', 'info', '--abs-time', snap])
62
1508 by Olivier Tilloy
* debian/apport/chromium-browser.py: update hook to call 'snap connections' instead of the deprecated 'snap interfaces'
63
    report['Snap.Connections'] = run_cmd(['snap', 'connections', 'chromium'])
1494.1.1 by Olivier Tilloy
* Upstream release: 75.0.3770.80
64
1525 by Olivier Tilloy
* debian/apport/chromium-browser.py: add the output of "snap changes --abs-time chromium" to bugs reported by apport
65
    report['Snap.Changes'] = \
66
        run_cmd(['snap', 'changes', '--abs-time', 'chromium'])
67
1494.1.1 by Olivier Tilloy
* Upstream release: 75.0.3770.80
68
    report['Snap.ChromiumVersion'] = \
69
        run_cmd(['snap', 'run', 'chromium', '--version'])
70
    report['Snap.ChromeDriverVersion'] = \
71
        run_cmd(['snap', 'run', 'chromium.chromedriver', '--version'])
72
73
    libsdir = os.path.join(SNAP_USER_DATA, '.local/lib')
74
    if os.path.exists(libsdir):
75
        libs = []
76
        for lib in os.listdir(libsdir):
77
            fp = os.path.join(libsdir, lib)
78
            with open(fp, 'rb') as f:
79
                sha256sum = hashlib.sha256(f.read()).hexdigest()
80
                libs.append('{} ({})'.format(lib, sha256sum))
81
        report['Snap.LocalLibs'] = '\n'.join(libs)
82
83
    flashlib = os.path.join(libsdir, 'libpepflashplayer.so')
84
    if os.path.exists(flashlib):
85
        with open(flashlib, 'rb') as f:
86
            r = re.compile(b'\x00\\.swf\\.playerversion\x00(.*?)\x00')
87
            version = r.findall(f.read())
88
            if len(version) > 0:
89
                report['Snap.FlashPlayerVersion'] = version[0].decode()
90
91
    user_profile_dir = os.path.join(SNAP_USER_DATA, '.config/chromium/Default')
92
    user_prefs(report, os.path.join(user_profile_dir, 'Preferences'))
93
94
    report['DiskUsage'] = \
95
        run_cmd(['df', '-Th', '/home', '/run/shm', SNAP_USER_DATA])
96
97
    apport.hookutils._add_tag(report, 'snap')
1125 by Chad MILLER
debian/apport/chromium-browser.py: Simplify. Use more standard functions
98
99
    apport.hookutils.attach_hardware(report)
1494.1.1 by Olivier Tilloy
* Upstream release: 75.0.3770.80
100
    apport.hookutils.attach_drm_info(report)
1125 by Chad MILLER
debian/apport/chromium-browser.py: Simplify. Use more standard functions
101
    apport.hookutils.attach_dmesg(report)
558.1.77 by Fabien Tassin
* Add some apport hooks adding useful information to the bugs
102
1494.1.1 by Olivier Tilloy
* Upstream release: 75.0.3770.80
103
104
def _test():
558.1.77 by Fabien Tassin
* Add some apport hooks adding useful information to the bugs
105
    report = {}
1494.1.1 by Olivier Tilloy
* Upstream release: 75.0.3770.80
106
    add_info(report, None)
558.1.77 by Fabien Tassin
* Add some apport hooks adding useful information to the bugs
107
    for key in report:
1494.1.1 by Olivier Tilloy
* Upstream release: 75.0.3770.80
108
        print('[{}]\n{}\n'.format(key, report[key]))
109
1052 by Chad MILLER
debian/apport: Significant cleanup.
110
111
if __name__ == '__main__':
1494.1.1 by Olivier Tilloy
* Upstream release: 75.0.3770.80
112
    _test()