~mvo/apt-clone/lucid-backport

« back to all changes in this revision

Viewing changes to apt_clone.py

  • Committer: Michael Vogt
  • Date: 2011-04-18 13:44:42 UTC
  • Revision ID: michael.vogt@ubuntu.com-20110418134442-665vlrfkx94356z3
* apt_clone.py, tests/test_clone.py: 
  - add _find_modified_conffiles helper and test for that

Show diffs side-by-side

added added

removed removed

Lines of Context:
21
21
import apt_pkg
22
22
import logging
23
23
import glob
 
24
import hashlib
24
25
import os
25
26
import shutil
26
27
import subprocess
481
482
                entry.disabled = True
482
483
        sources.save()
483
484
 
 
485
 
 
486
    def _find_modified_conffiles(self, sourcedir="/"):
 
487
        dpkg_status = sourcedir+apt_pkg.config.find("Dir::State::status")
 
488
        modified = set()
 
489
        # iterate dpkg-status file
 
490
        tag = apt_pkg.TagFile(open(dpkg_status))
 
491
        for entry in tag:
 
492
            if "conffiles" in entry:
 
493
                for line in entry["conffiles"].split("\n"):
 
494
                    obsolete = None
 
495
                    if len(line.split()) == 3:
 
496
                        name, md5sum, obsolete = line.split()
 
497
                    else:
 
498
                        name, md5sum = line.split()
 
499
                    # update
 
500
                    path = sourcedir+name
 
501
                    md5sum = md5sum.strip()
 
502
                    # ignore oboslete conffiles
 
503
                    if obsolete == "obsolete":
 
504
                        continue
 
505
                    # user removed conffile
 
506
                    if not os.path.exists(path):
 
507
                        logging.debug("conffile %s removed" % path)
 
508
                        modified.add(path)
 
509
                        continue
 
510
                    # check content
 
511
                    md5 = hashlib.md5()
 
512
                    md5.update(open(path).read())
 
513
                    if md5.hexdigest() != md5sum:
 
514
                        logging.debug("conffile %s (%s != %s)" % (
 
515
                                path, md5.hexdigest(), md5sum))
 
516
                        modified.add(path)
 
517
        return modified