Comment 1 for bug 803963

Revision history for this message
Brian Murray (brian-murray) wrote :

This is actually done already in apport for all apport-package bug reports:

def attach_conffiles(report, package, conffiles=None):
    '''Attach information about any modified or deleted conffiles'''

       dpkg = subprocess.Popen(['dpkg-query','-W','--showformat=${Conffiles}',
           package], stdout=subprocess.PIPE, close_fds=True)
    except OSError, e:
       return 'Error: ' + str(e)

    out = dpkg.communicate()[0]
    if dpkg.returncode != 0:

    for line in out.splitlines():
        if not line:
        # just take the first two fields, to not stumble over obsolete
        # conffiles
        path, default_md5sum = line.strip().split()[:2]

        if conffiles and path not in conffiles: continue

        key = 'modified.conffile.' + path_to_key(path)

        if os.path.exists(path):
            contents = open(path).read()
            m = hashlib.md5()
            calculated_md5sum = m.hexdigest()

            if calculated_md5sum != default_md5sum:
                report[key] = contents
                statinfo = os.stat(path)
                mtime = datetime.datetime.fromtimestamp(statinfo.st_mtime)
                mtime_key = 'mtime.conffile.' + path_to_key(path)
                report[mtime_key] = mtime.isoformat()
            report[key] = '[deleted]'