From patchwork Fri Mar 10 17:38:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Finucane X-Patchwork-Id: 737493 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher ADH-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3vfvf763Yfz9s7n for ; Sat, 11 Mar 2017 04:39:43 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="VGKrOAE9"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3vfvf7533pzDqYL for ; Sat, 11 Mar 2017 04:39:43 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="VGKrOAE9"; dkim-atps=neutral X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Received: from relay1001.mymailcheap.com (relay1001.mymailcheap.com [164.132.144.227]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3vfvcx04XHzDqXf for ; Sat, 11 Mar 2017 04:38:40 +1100 (AEDT) Authentication-Results: lists.ozlabs.org; dkim=fail reason="key not found in DNS" (0-bit key; unprotected) header.d=that.guru header.i=@that.guru header.b="VGKrOAE9"; dkim-atps=neutral Received: from filter1001.mymailcheap.com (filter1001.mymailcheap.com [158.69.67.251]) by relay1001.mymailcheap.com (Postfix) with ESMTPS id 940981E0D8 for ; Fri, 10 Mar 2017 18:38:37 +0100 (CET) Received: from localhost (localhost [127.0.0.1]) by filter1001.mymailcheap.com (Postfix) with ESMTP id AF35520918 for ; Fri, 10 Mar 2017 17:38:37 +0000 (UTC) Authentication-Results: filter1001.mymailcheap.com; dkim=permerror reason="key not found" header.d=that.guru header.i=@that.guru header.b=VGKrOAE9; dkim-adsp=none (unprotected policy); dkim-atps=neutral X-Virus-Scanned: Debian amavisd-new at filter1001.mymailcheap.com Received: from filter1001.mymailcheap.com ([127.0.0.1]) by localhost (filter1001.mymailcheap.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id qPrDEZ0y2ucP for ; Fri, 10 Mar 2017 17:38:36 +0000 (UTC) Received: from one.mxroute.com (one-outgoing.mxroute.com [23.92.70.115]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by filter1001.mymailcheap.com (Postfix) with ESMTPS for ; Fri, 10 Mar 2017 17:38:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=that.guru; s=default; h=References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Sender:Reply-To:MIME-Version:Content-Type:Content-Transfer-Encoding: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=wd72BhKdtQjaO3bo2HIZISRccXVYsRAw33PdVF/whLc=; b=VGKrOAE9lTg8/pnlAVsoHtTeX+ VbBNyj6Oa1UyRGI7QpiWDuj1h46YkRCPCDitQgFReI7R48hbuUT+FhA0aldu2a2uu/Khkt6gec/8C Q4Z13UtDHaJqxir3eFBmBBo/E9gk7G1BpRdFhs8I/dmCYTPdD+SUYq/Izn7bOsE863I1ZibuOv5Oz Hc5spPQXj5DKrjSgPaIOl35K+3/mXbk3GPAQ8GyfQLyVKqWLqEB01UE8+4Unl2U+IdBCrcW7KvC0t 0ZbP/kIHa2kfOx5BDPGOYmnUQkHMPqeUYf5OhqSPqWQynQnKB/3xKcn/dPlak/Nn1holQAShzOawa HRqwkH9g==; From: Stephen Finucane To: patchwork@lists.ozlabs.org Subject: [PATCH v4 6/9] views: Add 'series' parameter to '/mbox' endpoint Date: Fri, 10 Mar 2017 17:38:04 +0000 Message-Id: <20170310173807.13407-7-stephen@that.guru> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170310173807.13407-1-stephen@that.guru> References: <20170310173807.13407-1-stephen@that.guru> X-OutGoing-Spam-Status: No, score=-10.0 X-AuthUser: stephen@that.guru X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" This allows a user to download dependencies for a patch without having to do it manually. This is primarily aimed at users testing patches. Signed-off-by: Stephen Finucane Reviewed-by: Daniel Axtens --- v2: - Don't silently fail on invalid series - Move unrelated changes to separate patches --- patchwork/views/patch.py | 11 +++++++++-- patchwork/views/utils.py | 35 +++++++++++++++++++++++++++++++++++ 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/patchwork/views/patch.py b/patchwork/views/patch.py index a4cea2f..3c8cb25 100644 --- a/patchwork/views/patch.py +++ b/patchwork/views/patch.py @@ -34,6 +34,7 @@ from patchwork.models import Project from patchwork.models import Submission from patchwork.views import generic_list from patchwork.views.utils import patch_to_mbox +from patchwork.views.utils import series_patch_to_mbox def patch_list(request, project_id): @@ -120,6 +121,7 @@ def patch_detail(request, patch_id): def patch_raw(request, patch_id): patch = get_object_or_404(Patch, id=patch_id) + response = HttpResponse(content_type="text/x-patch") response.write(patch.diff) response['Content-Disposition'] = 'attachment; filename=' + \ @@ -130,8 +132,13 @@ def patch_raw(request, patch_id): def patch_mbox(request, patch_id): patch = get_object_or_404(Patch, id=patch_id) - response = HttpResponse(content_type="text/plain") - response.write(patch_to_mbox(patch)) + series_num = request.GET.get('series') + + response = HttpResponse(content_type='text/plain') + if series_num: + response.write(series_patch_to_mbox(patch, series_num)) + else: + response.write(patch_to_mbox(patch)) response['Content-Disposition'] = 'attachment; filename=' + \ patch.filename.replace(';', '').replace('\n', '') diff --git a/patchwork/views/utils.py b/patchwork/views/utils.py index 900480b..f936ed8 100644 --- a/patchwork/views/utils.py +++ b/patchwork/views/utils.py @@ -26,9 +26,11 @@ from email.parser import HeaderParser import email.utils import re +from django.http import Http404 from django.utils import six from patchwork.models import Comment +from patchwork.models import Series class PatchMbox(MIMENonMultipart): @@ -116,3 +118,36 @@ def bundle_to_mbox(bundle): A string for the mbox file. """ return '\n'.join([patch_to_mbox(p) for p in bundle.ordered_patches()]) + + +def series_patch_to_mbox(patch, series_num): + """Get an mbox representation of a patch with dependencies. + + Arguments: + patch: The Patch object to convert. + series_num: The series number to retrieve dependencies from. + + Returns: + A string for the mbox file. + """ + try: + series_num = int(series_num) + except ValueError: + raise Http404('Expected integer series value. Received: %r' % + series_num) + + try: + series = patch.series.get(id=series_num) + except Series.DoesNotExist: + raise Http404('Patch does not belong to series %d' % series_num) + + mbox = [] + + # get the series-ified patch + number = series.seriespatch_set.get(patch=patch).number + for dep in series.seriespatch_set.filter(number__lt=number): + mbox.append(patch_to_mbox(dep.patch)) + + mbox.append(patch_to_mbox(patch)) + + return '\n'.join(mbox)