~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/lp/archiveuploader/nascentuploadfile.py

  • Committer: Raphael Badin
  • Date: 2012-01-06 08:27:55 UTC
  • mfrom: (14513.5.4 builder-history-lfa)
  • mto: This revision was merged to the branch mainline in revision 14654.
  • Revision ID: raphael.badin@canonical.com-20120106082755-95a0eh6nakv5hj3b
Merge devel.

Show diffs side-by-side

added added

removed removed

Lines of Context:
58
58
from lp.soyuz.model.files import SourceFileMixin
59
59
 
60
60
 
61
 
apt_pkg.InitSystem()
 
61
apt_pkg.init_system()
62
62
 
63
63
 
64
64
class UploadError(Exception):
86
86
        self.future_files = {}
87
87
        self.ancient_files = {}
88
88
 
89
 
    def callback(self, kind, name, link, mode, uid, gid, size, mtime,
90
 
                 major, minor):
91
 
        """Callback designed to cope with apt_inst.debExtract.
 
89
    def callback(self, member, data):
 
90
        """Callback designed to cope with apt_inst.TarFile.go.
92
91
 
93
92
        It check and store timestamp details of the extracted DEB.
94
93
        """
95
 
        self.check_cutoff(name, mtime)
 
94
        self.check_cutoff(member.name, member.mtime)
96
95
 
97
96
    def check_cutoff(self, name, mtime):
98
97
        """Check the timestamp details of the supplied file.
529
528
                yield error
530
529
 
531
530
    def extractAndParseControl(self):
532
 
        """Extract and parse tcontrol information."""
533
 
        deb_file = open(self.filepath, "r")
 
531
        """Extract and parse control information."""
534
532
        try:
535
 
            control_file = apt_inst.debExtractControl(deb_file)
536
 
            control_lines = apt_pkg.ParseSection(control_file)
 
533
            deb_file = apt_inst.DebFile(self.filepath)
 
534
            control_file = deb_file.control.extractdata("control")
 
535
            control_lines = apt_pkg.TagSection(control_file)
537
536
        except (SystemExit, KeyboardInterrupt):
538
537
            raise
539
538
        except:
540
 
            deb_file.close()
541
539
            yield UploadError(
542
 
                "%s: debExtractControl() raised %s, giving up."
 
540
                "%s: extracting control file raised %s, giving up."
543
541
                 % (self.filename, sys.exc_type))
544
542
            return
545
543
 
546
544
        for mandatory_field in self.mandatory_fields:
547
 
            if control_lines.Find(mandatory_field) is None:
 
545
            if control_lines.find(mandatory_field) is None:
548
546
                yield UploadError(
549
547
                    "%s: control file lacks mandatory field %r"
550
548
                     % (self.filename, mandatory_field))
551
549
        control = {}
552
550
        for key in control_lines.keys():
553
 
            control[key] = control_lines.Find(key)
 
551
            control[key] = control_lines.find(key)
554
552
        self.parseControl(control)
555
553
 
556
554
    def parseControl(self, control):
718
716
        if data_tar == "data.tar.xz":
719
717
            parsed_deps = []
720
718
            try:
721
 
                parsed_deps = apt_pkg.ParseDepends(
 
719
                parsed_deps = apt_pkg.parse_depends(
722
720
                    self.control['Pre-Depends'])
723
721
            except (ValueError, TypeError):
724
722
                yield UploadError(
739
737
                    # VersionCompare returns values similar to cmp;
740
738
                    # negative if first < second, zero if first ==
741
739
                    # second and positive if first > second.
742
 
                    if apt_pkg.VersionCompare(
 
740
                    if apt_pkg.version_compare(
743
741
                        version, XZ_REQUIRED_DPKG_VER) >= 0:
744
742
                        # Pre-Depends dpkg is fine.
745
743
                        return
765
763
        tar_checker = TarFileDateChecker(future_cutoff, past_cutoff)
766
764
        tar_checker.reset()
767
765
        try:
768
 
            deb_file = open(self.filepath, "rb")
769
 
            apt_inst.debExtract(deb_file, tar_checker.callback,
770
 
                                "control.tar.gz")
771
 
            # Only one of these files is present in the archive, so loop
772
 
            # until we find one of them, otherwise fail.
773
 
            data_files = ("data.tar.gz", "data.tar.bz2", "data.tar.lzma",
774
 
                          "data.tar.xz")
775
 
            for file in data_files:
776
 
                deb_file.seek(0)
777
 
                try:
778
 
                    apt_inst.debExtract(deb_file, tar_checker.callback, file)
779
 
                except SystemError:
780
 
                    continue
781
 
                else:
782
 
                    deb_file.close()
783
 
 
784
 
                    future_files = tar_checker.future_files.keys()
785
 
                    if future_files:
786
 
                        first_file = future_files[0]
787
 
                        timestamp = time.ctime(
788
 
                            tar_checker.future_files[first_file])
789
 
                        yield UploadError(
790
 
                            "%s: has %s file(s) with a time stamp too "
791
 
                            "far into the future (e.g. %s [%s])."
792
 
                             % (self.filename, len(future_files), first_file,
793
 
                                timestamp))
794
 
 
795
 
                    ancient_files = tar_checker.ancient_files.keys()
796
 
                    if ancient_files:
797
 
                        first_file = ancient_files[0]
798
 
                        timestamp = time.ctime(
799
 
                            tar_checker.ancient_files[first_file])
800
 
                        yield UploadError(
801
 
                            "%s: has %s file(s) with a time stamp too "
802
 
                            "far in the past (e.g. %s [%s])."
803
 
                             % (self.filename, len(ancient_files), first_file,
804
 
                                timestamp))
805
 
                    return
806
 
 
807
 
            deb_file.close()
808
 
            yield UploadError(
809
 
                "Could not find data tarball in %s" % self.filename)
810
 
 
 
766
            deb_file = apt_inst.DebFile(self.filepath)
 
767
        except SystemError, error:
 
768
            # We get an error from the constructor if the .deb does not
 
769
            # contain all the expected top-level members (debian-binary,
 
770
            # control.tar.gz, and data.tar.*).
 
771
            yield UploadError(error)
 
772
        try:
 
773
            deb_file.control.go(tar_checker.callback)
 
774
            deb_file.data.go(tar_checker.callback)
 
775
            future_files = tar_checker.future_files.keys()
 
776
            if future_files:
 
777
                first_file = future_files[0]
 
778
                timestamp = time.ctime(tar_checker.future_files[first_file])
 
779
                yield UploadError(
 
780
                    "%s: has %s file(s) with a time stamp too "
 
781
                    "far into the future (e.g. %s [%s])."
 
782
                     % (self.filename, len(future_files), first_file,
 
783
                        timestamp))
 
784
 
 
785
            ancient_files = tar_checker.ancient_files.keys()
 
786
            if ancient_files:
 
787
                first_file = ancient_files[0]
 
788
                timestamp = time.ctime(tar_checker.ancient_files[first_file])
 
789
                yield UploadError(
 
790
                    "%s: has %s file(s) with a time stamp too "
 
791
                    "far in the past (e.g. %s [%s])."
 
792
                     % (self.filename, len(ancient_files), first_file,
 
793
                        timestamp))
811
794
        except (SystemExit, KeyboardInterrupt):
812
795
            raise
813
796
        except Exception, error: