Example #1
0
    def processFiles(self):
        """Build objects for each file mentioned in this changesfile.

        This method is an error generator, i.e, it returns an iterator over
        all exceptions that are generated while processing all mentioned
        files.
        """
        try:
            raw_files = parse_and_merge_file_lists(self._dict, changes=True)
        except UploadError as e:
            yield e
            return

        files = []
        for attr in raw_files:
            filename, hashes, size, component_and_section, priority_name = attr
            filepath = os.path.join(self.dirname, filename)
            try:
                if self.isCustom(component_and_section):
                    # This needs to be the first check, because
                    # otherwise the tarballs in custom uploads match
                    # with source_match.
                    file_instance = CustomUploadFile(
                        filepath, hashes, size, component_and_section, priority_name, self.policy, self.logger
                    )
                else:
                    try:
                        package, cls = determine_file_class_and_name(filename)
                    except CannotDetermineFileTypeError:
                        yield UploadError(
                            "Unable to identify file %s (%s) in changes." % (filename, component_and_section)
                        )
                        continue

                    file_instance = cls(
                        filepath,
                        hashes,
                        size,
                        component_and_section,
                        priority_name,
                        package,
                        self.version,
                        self,
                        self.policy,
                        self.logger,
                    )

                    if cls == DSCFile:
                        self.dsc = file_instance
            except UploadError as error:
                yield error
            else:
                files.append(file_instance)

        self.files = files
Example #2
0
    def processFiles(self):
        """Build objects for each file mentioned in this changesfile.

        This method is an error generator, i.e, it returns an iterator over
        all exceptions that are generated while processing all mentioned
        files.
        """
        try:
            raw_files = parse_and_merge_file_lists(self._dict, changes=True)
        except UploadError as e:
            yield e
            return

        files = []
        for attr in raw_files:
            filename, hashes, size, component_and_section, priority_name = attr
            filepath = os.path.join(self.dirname, filename)
            try:
                if self.isCustom(component_and_section):
                    # This needs to be the first check, because
                    # otherwise the tarballs in custom uploads match
                    # with source_match.
                    file_instance = CustomUploadFile(filepath, hashes, size,
                                                     component_and_section,
                                                     priority_name,
                                                     self.policy, self.logger)
                else:
                    try:
                        package, cls = determine_file_class_and_name(filename)
                    except CannotDetermineFileTypeError:
                        yield UploadError(
                            "Unable to identify file %s (%s) in changes." %
                            (filename, component_and_section))
                        continue

                    file_instance = cls(filepath, hashes, size,
                                        component_and_section, priority_name,
                                        package, self.version, self,
                                        self.policy, self.logger)

                    if cls == DSCFile:
                        self.dsc = file_instance
                    elif cls == BuildInfoFile:
                        self.buildinfo = file_instance
            except UploadError as error:
                yield error
            else:
                files.append(file_instance)

        self.files = files
Example #3
0
    def verify(self):
        """Verify the uploaded .dsc file.

        This method is an error generator, i.e, it returns an iterator over
        all exceptions that are generated while processing DSC file checks.
        """

        for error in SourceUploadFile.verify(self):
            yield error

        # Check size and checksum of the DSC file itself
        try:
            self.checkSizeAndCheckSum()
        except UploadError as error:
            yield error

        try:
            raw_files = parse_and_merge_file_lists(self._dict, changes=False)
        except UploadError as e:
            yield e
            return

        files = []
        for attr in raw_files:
            filename, hashes, size = attr
            if not re_issource.match(filename):
                # DSC files only really hold on references to source
                # files; they are essentially a description of a source
                # package. Anything else is crack.
                yield UploadError("%s: File %s does not look sourceful." %
                                  (self.filename, filename))
                continue
            filepath = os.path.join(self.dirname, filename)
            try:
                file_instance = DSCUploadedFile(filepath, hashes, size,
                                                self.policy, self.logger)
            except UploadError as error:
                yield error
            else:
                files.append(file_instance)
        self.files = files

        if not re_valid_pkg_name.match(self.source):
            yield UploadError("%s: invalid source name %s" %
                              (self.filename, self.source))
        if not re_valid_version.match(self.dsc_version):
            yield UploadError("%s: invalid version %s" %
                              (self.filename, self.dsc_version))

        if not self.policy.distroseries.isSourcePackageFormatPermitted(
                self.format):
            yield UploadError(
                "%s: format '%s' is not permitted in %s." %
                (self.filename, self.format, self.policy.distroseries.name))

        # Validate the build dependencies
        for field_name in ['Build-Depends', 'Build-Depends-Indep']:
            field = self._dict.get(field_name, None)
            if field is not None:
                if field.startswith("ARRAY"):
                    yield UploadError(
                        "%s: invalid %s field produced by a broken version "
                        "of dpkg-dev (1.10.11)" % (self.filename, field_name))
                try:
                    with warnings.catch_warnings():
                        warnings.simplefilter("error")
                        PkgRelation.parse_relations(field)
                except Warning as error:
                    yield UploadError(
                        "%s: invalid %s field; cannot be parsed by deb822: %s"
                        % (self.filename, field_name, error))

        # Verify if version declared in changesfile is the same than that
        # in DSC (including epochs).
        if self.dsc_version != self.version:
            yield UploadError(
                "%s: version ('%s') in .dsc does not match version "
                "('%s') in .changes." %
                (self.filename, self.dsc_version, self.version))

        for error in self.checkFiles():
            yield error
Example #4
0
    def verify(self):
        """Verify the uploaded .dsc file.

        This method is an error generator, i.e, it returns an iterator over
        all exceptions that are generated while processing DSC file checks.
        """

        for error in SourceUploadFile.verify(self):
            yield error

        # Check size and checksum of the DSC file itself
        try:
            self.checkSizeAndCheckSum()
        except UploadError as error:
            yield error

        try:
            raw_files = parse_and_merge_file_lists(self._dict, changes=False)
        except UploadError as e:
            yield e
            return

        files = []
        for attr in raw_files:
            filename, hashes, size = attr
            if not re_issource.match(filename):
                # DSC files only really hold on references to source
                # files; they are essentially a description of a source
                # package. Anything else is crack.
                yield UploadError("%s: File %s does not look sourceful." % (
                                  self.filename, filename))
                continue
            filepath = os.path.join(self.dirname, filename)
            try:
                file_instance = DSCUploadedFile(
                    filepath, hashes, size, self.policy, self.logger)
            except UploadError as error:
                yield error
            else:
                files.append(file_instance)
        self.files = files

        if not re_valid_pkg_name.match(self.source):
            yield UploadError(
                "%s: invalid source name %s" % (self.filename, self.source))
        if not re_valid_version.match(self.dsc_version):
            yield UploadError(
                "%s: invalid version %s" % (self.filename, self.dsc_version))

        if not self.policy.distroseries.isSourcePackageFormatPermitted(
            self.format):
            yield UploadError(
                "%s: format '%s' is not permitted in %s." %
                (self.filename, self.format, self.policy.distroseries.name))

        # Validate the build dependencies
        for field_name in ['Build-Depends', 'Build-Depends-Indep']:
            field = self._dict.get(field_name, None)
            if field is not None:
                if field.startswith("ARRAY"):
                    yield UploadError(
                        "%s: invalid %s field produced by a broken version "
                        "of dpkg-dev (1.10.11)" % (self.filename, field_name))
                try:
                    apt_pkg.parse_src_depends(field)
                except (SystemExit, KeyboardInterrupt):
                    raise
                except Exception as error:
                    # Swallow everything apt_pkg throws at us because
                    # it is not desperately pythonic and can raise odd
                    # or confusing exceptions at times and is out of
                    # our control.
                    yield UploadError(
                        "%s: invalid %s field; cannot be parsed by apt: %s"
                        % (self.filename, field_name, error))

        # Verify if version declared in changesfile is the same than that
        # in DSC (including epochs).
        if self.dsc_version != self.version:
            yield UploadError(
                "%s: version ('%s') in .dsc does not match version "
                "('%s') in .changes."
                % (self.filename, self.dsc_version, self.version))

        for error in self.checkFiles():
            yield error