Example #1
0
    def published_source_and_binary_files(self):
        """Return list of dictionaries representing published files."""
        files = sorted(
            (ProxiedLibraryFileAlias(lfa, self.context.archive)
             for lfa in self.context.getSourceAndBinaryLibraryFiles()),
            key=attrgetter('filename'))
        result = []
        urls = set()
        for library_file in files:
            url = library_file.http_url
            if url in urls:
                # Don't print out the same file multiple times. This
                # actually happens for arch-all builds, and is
                # particularly irritating for PPAs.
                continue
            urls.add(url)

            custom_dict = {}
            custom_dict["url"] = url
            custom_dict["filename"] = library_file.filename
            custom_dict["filesize"] = library_file.content.filesize
            if (library_file.filename.endswith('.deb') or
                library_file.filename.endswith('.udeb')):
                custom_dict['class'] = 'binary'
            else:
                custom_dict['class'] = 'source'

            result.append(custom_dict)

        return result
Example #2
0
    def changesfile(self):
        """Return a `ProxiedLibraryFileAlias` for the Build changesfile."""
        changesfile = self.context.upload_changesfile
        if changesfile is None:
            return None

        return ProxiedLibraryFileAlias(changesfile, self.context)
Example #3
0
 def delete_action(self, action, data):
     libraryfile_url = ProxiedLibraryFileAlias(
         self.context.libraryfile, self.context).http_url
     self.request.response.addInfoNotification(structured(
         'Attachment "<a href="%(url)s">%(name)s</a>" has been deleted.',
         url=libraryfile_url, name=self.context.title))
     self.context.removeFromBug(user=self.user)
Example #4
0
 def attachment_text(self, attachment):
     """Return a text representation of a bug attachment."""
     mime_type = normalize_mime_type.sub(
         ' ', attachment.libraryfile.mimetype)
     download_url = ProxiedLibraryFileAlias(
         attachment.libraryfile, attachment).http_url
     return "%s %s" % (download_url, mime_type)
Example #5
0
 def sourcepackagerelease(self):
     if self._changesfile is not None:
         changesfile = ProxiedLibraryFileAlias(self._changesfile,
                                               self.context.archive)
     else:
         changesfile = None
     return ArchiveSourcePackageRelease(self.context.sourcepackagerelease,
                                        changesfile)
Example #6
0
 def test_composeNameAndChangesLink_links_to_changes_file(self):
     complete_upload = self.makeCompletePackageUpload()
     link = html.fromstring(
         html_escape(complete_upload.composeNameAndChangesLink()))
     self.assertEqual(
         ProxiedLibraryFileAlias(
             complete_upload.changesfile, complete_upload.context).http_url,
         link.get("href"))
 def files(self):
     """The source package release files as `ProxiedLibraryFileAlias`."""
     last_publication = self._cached_publishing_history[0]
     return [
         ProxiedLibraryFileAlias(source_file.libraryfile,
                                 last_publication.archive)
         for source_file in self.context.files
     ]
Example #8
0
    def files(self):
        """Return `LibraryFileAlias`es for files produced by this build."""
        if not self.context.was_built:
            return None

        return [
            ProxiedLibraryFileAlias(alias, self.context)
            for _, alias, _ in self.context.getFiles() if not alias.deleted
        ]
Example #9
0
    def files(self):
        """Return `LibraryFileAlias`es for files produced by this build."""
        if not self.context.was_built:
            return None

        return [
            ProxiedLibraryFileAlias(alias, self.context)
            for bpr, bpf, alias, content
                in self.context.getBinaryFilesForDisplay()
                if not alias.deleted]
    def getURLsForBPPH(self, bpph, include_meta=False):
        bpr = bpph.binarypackagerelease
        archive = bpph.archive
        urls = [ProxiedLibraryFileAlias(f.libraryfile, archive).http_url
            for f in bpr.files]

        if include_meta:
            meta = [(
                f.libraryfile.content.filesize,
                f.libraryfile.content.sha1,
                f.libraryfile.content.sha256,
            ) for f in bpr.files]

            return [dict(url=url, size=size, sha1=sha1, sha256=sha256)
                for url, (size, sha1, sha256) in zip(urls, meta)]
        return urls
Example #11
0
 def test_getFileUrls(self):
     # API clients can fetch files attached to builds.
     db_build = self.factory.makeSnapBuild(requester=self.person)
     db_files = [
         self.factory.makeSnapFile(snapbuild=db_build) for i in range(2)
     ]
     build_url = api_url(db_build)
     file_urls = [
         ProxiedLibraryFileAlias(file.libraryfile, db_build).http_url
         for file in db_files
     ]
     logout()
     response = self.webservice.named_get(build_url, "getFileUrls")
     self.assertEqual(200, response.status)
     self.assertContentEqual(file_urls, response.jsonBody())
     browser = self.getNonRedirectingBrowser(user=self.person)
     for file_url in file_urls:
         self.assertCanOpenRedirectedUrl(browser, file_url)
    def test_binaryFileUrls(self):
        person = self.factory.makePerson()
        webservice = webservice_for_person(
            person, permission=OAuthPermission.READ_PUBLIC)
        bpph, url = self.make_bpph_for(person)

        response = webservice.named_get(url,
                                        'binaryFileUrls',
                                        api_version='devel')

        self.assertEqual(200, response.status)
        urls = response.jsonBody()
        with person_logged_in(person):
            bpf = bpph.binarypackagerelease.files[0]
            expected_urls = [
                ProxiedLibraryFileAlias(bpf.libraryfile, bpph.archive).http_url
            ]
        self.assertEqual(expected_urls, urls)
Example #13
0
 def _bug_attachments(self):
     """Get a dict of attachment type -> attachments list."""
     # Note that this is duplicated with get_comments_for_bugtask
     # if you are looking to consolidate things.
     result = {
         BugAttachmentType.PATCH: [],
         'other': [],
         }
     for attachment in self.context.attachments_unpopulated:
         info = {
             'attachment': attachment,
             'file': ProxiedLibraryFileAlias(
                 attachment.libraryfile, attachment),
             }
         if attachment.type == BugAttachmentType.PATCH:
             key = attachment.type
         else:
             key = 'other'
         result[key].append(info)
     return result
    def test_binaryFileUrls_include_meta(self):
        person = self.factory.makePerson()
        webservice = webservice_for_person(
            person, permission=OAuthPermission.READ_PUBLIC)
        bpph, url = self.make_bpph_for(person)

        def create_file():
            self.factory.makeBinaryPackageFile(
                binarypackagerelease=bpph.binarypackagerelease)

        def get_urls():
            return webservice.named_get(url,
                                        'binaryFileUrls',
                                        include_meta=True,
                                        api_version='devel')

        recorder1, recorder2 = record_two_runs(get_urls,
                                               create_file,
                                               2,
                                               login_method=partial(
                                                   login_person, person),
                                               record_request=True)
        self.assertThat(recorder2, HasQueryCount.byEquality(recorder1))

        response = get_urls()
        self.assertEqual(200, response.status)
        info = response.jsonBody()
        with person_logged_in(person):
            expected_info = [{
                "url":
                ProxiedLibraryFileAlias(bpf.libraryfile,
                                        bpph.archive).http_url,
                "size":
                bpf.libraryfile.content.filesize,
                "sha1":
                bpf.libraryfile.content.sha1,
                "sha256":
                bpf.libraryfile.content.sha256,
            } for bpf in bpph.binarypackagerelease.files]
        self.assertContentEqual(expected_info, info)
Example #15
0
 def proxiedUrlForLibraryFile(self, attachment):
     """Return the proxied download URL for a Librarian file."""
     return ProxiedLibraryFileAlias(
         attachment.libraryfile, attachment).http_url
 def lfaUrl(self, lfa):
     """Return the URL for a LibraryFileAlias, in the context of self.
     """
     if lfa is None:
         return None
     return ProxiedLibraryFileAlias(lfa, self).http_url
Example #17
0
 def upload_log_url(self):
     """See `IPackageBuild`."""
     if self.upload_log is None:
         return None
     return ProxiedLibraryFileAlias(self.upload_log, self).http_url
Example #18
0
 def proxiedFile(self, libraryfile):
     """Return a librarian file proxied in the context of this upload."""
     return ProxiedLibraryFileAlias(libraryfile, self.context)
Example #19
0
 def log_url(self):
     """See `IBuildFarmJob`."""
     if self.log is None:
         return None
     return ProxiedLibraryFileAlias(self.log, self).http_url
Example #20
0
def download_url_of_bugattachment(attachment):
    """Return the URL of the ProxiedLibraryFileAlias for the attachment."""
    return ProxiedLibraryFileAlias(attachment.libraryfile, attachment).http_url
Example #21
0
 def proxiedUrlOfLibraryFileAlias(self, attachment):
     """Return the proxied URL for the Librarian file of the attachment."""
     return ProxiedLibraryFileAlias(attachment.libraryfile,
                                    attachment).http_url
Example #22
0
 def diff_content(self):
     library_file = self.context.diff_content
     if library_file is None:
         return None
     return ProxiedLibraryFileAlias(library_file, self.parent)
Example #23
0
def serialise_bugtask(bugtask):
    bug = bugtask.bug
    bug_node = ET.Element('bug', id=str(bug.id))
    bug_node.text = bug_node.tail = '\n'

    addnode(bug_node, 'private', str(bug.private))
    addnode(bug_node, 'security_related', str(bug.security_related))
    if bug.duplicateof is not None:
        addnode(bug_node, 'duplicateof', str(bug.duplicateof.id))
    addnode(bug_node, 'datecreated',
            bug.datecreated.strftime('%Y-%m-%dT%H:%M:%SZ'))
    if bug.name is not None:
        addnode(bug_node, 'nickname', bug.name)
    addnode(bug_node, 'title', bug.title)
    addnode(bug_node, 'description', bug.description)
    addperson(bug_node, 'reporter', bug.owner)

    # Information from bug task:
    addnode(bug_node, 'status', bugtask.status.name)
    addnode(bug_node, 'importance', bugtask.importance.name)
    if bugtask.milestone is not None:
        addnode(bug_node, 'milestone', bugtask.milestone.name)
    if bugtask.assignee is not None:
        addperson(bug_node, 'assignee', bugtask.assignee)

    if bug.tags:
        tags_node = ET.SubElement(bug_node, 'tags')
        tags_node.text = tags_node.tail = '\n'
        for tag in bug.tags:
            addnode(tags_node, 'tag', tag)

    subscribers = bug.getDirectSubscribers()
    if subscribers:
        subs_node = ET.SubElement(bug_node, 'subscriptions')
        subs_node.text = subs_node.tail = '\n'
        for person in subscribers:
            addperson(subs_node, 'subscriber', person)

    for comment in get_comments_for_bugtask(bugtask):
        comment_node = ET.SubElement(bug_node, 'comment')
        comment_node.text = comment_node.tail = '\n'
        addperson(comment_node, 'sender', comment.owner)
        addnode(comment_node, 'date',
                comment.datecreated.strftime('%Y-%m-%dT%H:%M:%SZ'))
        addnode(comment_node, 'text', comment.text_for_display)
        for attachment in comment.bugattachments:
            attachment_node = ET.SubElement(comment_node,
                                            'attachment',
                                            href=ProxiedLibraryFileAlias(
                                                attachment.libraryfile,
                                                attachment).http_url)
            attachment_node.text = attachment_node.tail = '\n'
            addnode(attachment_node, 'type', attachment.type.name)
            addnode(attachment_node, 'filename',
                    attachment.libraryfile.filename)
            addnode(attachment_node, 'title', attachment.title)
            addnode(attachment_node, 'mimetype',
                    attachment.libraryfile.mimetype)
            # Attach the attachment file contents, base 64 encoded.
            addnode(attachment_node, 'contents',
                    base64.encodestring(attachment.libraryfile.read()))

    return bug_node