out = dpkg.communicate()[0]
if dpkg.returncode != 0:
return
for line in out.splitlines():
if not line: continue
# 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() m.update(contents) calculated_md5sum = m.hexdigest()
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'''
try: Popen([ 'dpkg-query' ,'-W',' --showformat= ${Conffiles} ',
package] , stdout= subprocess. PIPE, close_fds=True)
dpkg = subprocess.
except OSError, e:
return 'Error: ' + str(e)
out = dpkg.communicat e()[0]
if dpkg.returncode != 0:
return
for line in out.splitlines():
continue ).split( )[:2]
if not line:
# just take the first two fields, to not stumble over obsolete
# conffiles
path, default_md5sum = line.strip(
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. update( contents)
calculated _md5sum = m.hexdigest()
m = hashlib.md5()
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]'
else: