示例#1
0
    def addReleaseFile(self,
                       filename,
                       file_content,
                       content_type,
                       uploader,
                       signature_filename=None,
                       signature_content=None,
                       file_type=UpstreamFileType.CODETARBALL,
                       description=None,
                       from_api=False):
        """See `IProductRelease`."""
        if not self.can_have_release_files:
            raise ProprietaryProduct(
                "Only public projects can have download files.")
        if self.hasReleaseFile(filename):
            raise InvalidFilename
        # Create the alias for the file.
        filename = self.normalizeFilename(filename)
        # XXX: StevenK 2013-02-06 bug=1116954: We should not need to refetch
        # the file content from the request, since the passed in one has been
        # wrongly encoded.
        if from_api:
            file_content = get_raw_form_value_from_current_request(
                file_content, 'file_content')
        file_obj, file_size = self._getFileObjectAndSize(file_content)

        alias = getUtility(ILibraryFileAliasSet).create(
            name=filename,
            size=file_size,
            file=file_obj,
            contentType=content_type)
        if signature_filename is not None and signature_content is not None:
            # XXX: StevenK 2013-02-06 bug=1116954: We should not need to
            # refetch the file content from the request, since the passed in
            # one has been wrongly encoded.
            if from_api:
                signature_content = get_raw_form_value_from_current_request(
                    signature_content, 'signature_content')
            signature_obj, signature_size = self._getFileObjectAndSize(
                signature_content)
            signature_filename = self.normalizeFilename(signature_filename)
            signature_alias = getUtility(ILibraryFileAliasSet).create(
                name=signature_filename,
                size=signature_size,
                file=signature_obj,
                contentType='application/pgp-signature')
        else:
            signature_alias = None
        return ProductReleaseFile(productrelease=self,
                                  libraryfile=alias,
                                  signature=signature_alias,
                                  filetype=file_type,
                                  description=description,
                                  uploader=uploader)
    def addReleaseFile(self, filename, file_content, content_type,
                       uploader, signature_filename=None,
                       signature_content=None,
                       file_type=UpstreamFileType.CODETARBALL,
                       description=None, from_api=False):
        """See `IProductRelease`."""
        if not self.can_have_release_files:
            raise ProprietaryProduct(
                "Only public projects can have download files.")
        if self.hasReleaseFile(filename):
            raise InvalidFilename
        # Create the alias for the file.
        filename = self.normalizeFilename(filename)
        # XXX: StevenK 2013-02-06 bug=1116954: We should not need to refetch
        # the file content from the request, since the passed in one has been
        # wrongly encoded.
        if from_api:
            file_content = get_raw_form_value_from_current_request(
                'file_content')
        file_obj, file_size = self._getFileObjectAndSize(file_content)

        alias = getUtility(ILibraryFileAliasSet).create(
            name=filename, size=file_size, file=file_obj,
            contentType=content_type)
        if signature_filename is not None and signature_content is not None:
            # XXX: StevenK 2013-02-06 bug=1116954: We should not need to
            # refetch the file content from the request, since the passed in
            # one has been wrongly encoded.
            if from_api:
                signature_content = get_raw_form_value_from_current_request(
                    'signature_content')
            signature_obj, signature_size = self._getFileObjectAndSize(
                signature_content)
            signature_filename = self.normalizeFilename(signature_filename)
            signature_alias = getUtility(ILibraryFileAliasSet).create(
                name=signature_filename, size=signature_size,
                file=signature_obj, contentType='application/pgp-signature')
        else:
            signature_alias = None
        return ProductReleaseFile(
            productrelease=self, libraryfile=alias, signature=signature_alias,
            filetype=file_type, description=description, uploader=uploader)
 def setChroot(self, data, sha1sum):
     """See `IDistroArchSeries`."""
     # XXX: StevenK 2013-06-06 bug=1116954: We should not need to refetch
     # the file content from the request, since the passed in one has been
     # wrongly encoded.
     data = get_raw_form_value_from_current_request('data')
     if isinstance(data, str):
         filecontent = data
     else:
         filecontent = data.read()
     filename = 'chroot-%s-%s-%s.tar.bz2' % (
         self.distroseries.distribution.name, self.distroseries.name,
         self.architecturetag)
     lfa = getUtility(ILibraryFileAliasSet).create(
         name=filename, size=len(filecontent), file=StringIO(filecontent),
         contentType='application/octet-stream')
     if lfa.content.sha1 != sha1sum:
         raise InvalidChrootUploaded("Chroot upload checksums do not match")
     self.addOrUpdateChroot(lfa)
示例#4
0
 def setChroot(self, data, sha1sum):
     """See `IDistroArchSeries`."""
     # XXX: StevenK 2013-06-06 bug=1116954: We should not need to refetch
     # the file content from the request, since the passed in one has been
     # wrongly encoded.
     data = get_raw_form_value_from_current_request('data')
     if isinstance(data, str):
         filecontent = data
     else:
         filecontent = data.read()
     filename = 'chroot-%s-%s-%s.tar.bz2' % (
         self.distroseries.distribution.name, self.distroseries.name,
         self.architecturetag)
     lfa = getUtility(ILibraryFileAliasSet).create(
         name=filename,
         size=len(filecontent),
         file=StringIO(filecontent),
         contentType='application/octet-stream')
     if lfa.content.sha1 != sha1sum:
         raise InvalidChrootUploaded("Chroot upload checksums do not match")
     self.addOrUpdateChroot(lfa)
    def setChroot(self, data, sha1sum, pocket=None, image_type=None):
        """See `IDistroArchSeries`."""
        # XXX: StevenK 2013-06-06 bug=1116954: We should not need to refetch
        # the file content from the request, since the passed in one has been
        # wrongly encoded.
        data = get_raw_form_value_from_current_request(data, 'data')
        if isinstance(data, str):
            filecontent = data
        else:
            filecontent = data.read()

        # Due to http://bugs.python.org/issue1349106 launchpadlib sends
        # MIME with \n line endings, which is illegal. lazr.restful
        # parses each ending as \r\n, resulting in a binary that ends
        # with \r getting the last byte chopped off. To cope with this
        # on the server side we try to append \r if the SHA-1 doesn't
        # match.
        content_sha1sum = hashlib.sha1(filecontent).hexdigest()
        if content_sha1sum != sha1sum:
            filecontent += '\r'
            content_sha1sum = hashlib.sha1(filecontent).hexdigest()
        if content_sha1sum != sha1sum:
            raise InvalidChrootUploaded("Chroot upload checksums do not match")

        # This duplicates addOrUpdateChroot, but we need it to build a
        # reasonable filename.
        if image_type is None:
            image_type = BuildBaseImageType.CHROOT

        filename = '%s-%s-%s-%s.tar.gz' % (
            image_type.name.lower().split()[0],
            self.distroseries.distribution.name, self.distroseries.name,
            self.architecturetag)
        lfa = getUtility(ILibraryFileAliasSet).create(
            name=filename, size=len(filecontent), file=StringIO(filecontent),
            contentType='application/octet-stream')
        if lfa.content.sha1 != sha1sum:
            raise InvalidChrootUploaded("Chroot upload checksums do not match")
        self.addOrUpdateChroot(lfa, pocket=pocket, image_type=image_type)