Skip to content

Instantly share code, notes, and snippets.

@chihchun
Created July 23, 2019 13:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save chihchun/579cae9893b6fb38c4fb8c5db11e0482 to your computer and use it in GitHub Desktop.
Save chihchun/579cae9893b6fb38c4fb8c5db11e0482 to your computer and use it in GitHub Desktop.
from apport.hookutils import *
from glob import glob
from io import BytesIO
import zipfile
from problem_report import CompressedValue
description = 'ODM testing'
opt_debug = False
# Apport helper routines
def debug(text):
if opt_debug:
sys.stderr.write("%s\n" %(text))
def attach_command_output(report, command_list, key):
debug(" %s" %(' '.join(command_list)))
log = command_output(command_list)
if not log or log[:5] == "Error":
return
report[key] = log
def attach_pathglob_as_tgz(report, pathglob, key):
"""Use zip file here because tarfile module in linux can't
properly handle file size 0 with contaent in /sys directory like
edid file. zipfile module works fine here. So we use it."""
filelist = []
for pg in pathglob:
for file in glob(pg):
filelist.append(file)
zipf = BytesIO()
zipobj = zipfile.ZipFile(zipf, mode='w')
for f in filelist:
zipobj.write(f)
zipobj.close()
cvalue = CompressedValue()
cvalue.set_value(zipf.getbuffer())
report[key + ".zip"] = cvalue
def run(report, ui):
# Check if the DCD file is exist in the installer.
attach_command_output(report, ['ubuntu-report', 'show'], 'UbuntuReport')
attach_file_if_exists(report, '/etc/buildstamp', 'BuildStamp')
# Basic hardare information
attach_hardware(report)
attach_alsa(report)
attach_wifi(report)
# related packages
packages = ['apt', 'grub2']
# display
packages.append('xorg')
packages.append('gnome-shell')
# audio
packages.append('alsa-base')
# hotkey and hotplugs
packages.append('udev')
# networking issues
packages.append('network-manager')
# FIXME: should be included in xorg
attach_pathglob_as_tgz(report, ['/sys/devices/*/*/drm/card?/*/edid'], "EDID")
# FIXME: shold be inclued in thermald
attach_pathglob_as_tgz(report, [
"/etc/thermald/*",
"/sys/devices/virtual/thermal/*",
"/sys/class/thermal/*"
], "THERMALD")
# FIXME: should includes all kernel and system messages
# FIXME: debug information for suspend or hibernate
attach_related_packages(report, packages)
# some base packages that must preloaded with OEM image.
return "dpkg"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment