From patchwork Tue Mar 7 19:46:22 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Finucane X-Patchwork-Id: 736356 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 3vd6fN2Q2Fz9sDb for ; Wed, 8 Mar 2017 06:48:44 +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="IZZEsizW"; 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 3vd6fN1FzjzDqYs for ; Wed, 8 Mar 2017 06:48:44 +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="IZZEsizW"; dkim-atps=neutral X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Received: from relay1007.mymailcheap.com (relay1007.mymailcheap.com [144.217.215.67]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3vd6cR3G48zDqY1 for ; Wed, 8 Mar 2017 06:47:03 +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="IZZEsizW"; dkim-atps=neutral Received: from filter1007.mymailcheap.com (filter1007.mymailcheap.com [164.132.58.18]) by relay1007.mymailcheap.com (Postfix) with ESMTPS id CFCD61E040 for ; Tue, 7 Mar 2017 14:46:59 -0500 (EST) Received: from localhost (localhost [127.0.0.1]) by filter1007.mymailcheap.com (Postfix) with ESMTP id 122B61E085 for ; Tue, 7 Mar 2017 20:46:59 +0100 (CET) X-Virus-Scanned: Debian amavisd-new at filter1007.mymailcheap.com Received: from filter1007.mymailcheap.com ([127.0.0.1]) by localhost (filter1007.mymailcheap.com [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2xEkr67P1D93 for ; Tue, 7 Mar 2017 20:46:53 +0100 (CET) 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 filter1007.mymailcheap.com (Postfix) with ESMTPS for ; Tue, 7 Mar 2017 20:46:44 +0100 (CET) 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=PiAmvSjA2PeS2HeIhFC9I5WRlw+mekNzZv1DmZHQWUk=; b=IZZEsizWoWZo9HeWPwhMpLnG3e Q1D0XRT5Jr0UKT7mzwcq/NV4I5BY96gOCIxk5xXZROv5Qm41ZHfQY7lzpNJpgzp3v197trNA6aVmv L9nX/611BgrcxEXvgTcFPENub+49cktlaKbOcMcobIhJKDXKIdenFZIw1CDyPWQOYDyrtALN+6Bks N08fyU7cpg9vw+LQPCK7ob9fAOY1XmadHcW8yDn0SAwd4UYN5BIfP6jufkkzsm5fnPlu3sqGwXvTt upTo/WEHcY4XKRvH1yDU/t7sxbqnhYRJbvvHKUOjvuZNgdpq0VmQrE34KcAjLPe0ujWM2B2RPO7To eZ7yWiEw==; From: Stephen Finucane To: patchwork@lists.ozlabs.org Subject: [PATCH v3 7/9] views: Expose Series mbox Date: Tue, 7 Mar 2017 19:46:22 +0000 Message-Id: <20170307194624.21582-8-stephen@that.guru> X-Mailer: git-send-email 2.9.3 In-Reply-To: <20170307194624.21582-1-stephen@that.guru> References: <20170307194624.21582-1-stephen@that.guru> X-OutGoing-Spam-Status: No, score=-1.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" It is possible to download a patch mbox with all dependencies. Now make it possible to download the entire series. This takes the form of the following URL when using the default routes: /series/{seriesID}/mbox/ Like the equivalent patch and bundle links, this will return a 404 if '{seriesID}' does not match an existing series' ID. However, a 404 will also be returned in the series is not complete, as indicated by Series.total > Series.received_total. You can override this behavior by providing the 'force' parameter: /series/{seriesID}/mbox/?force=1 Note that there are no current plans to provide a series-specific view, a.k.a. /series/{seriesID}/ As a result, this particular URL will continue to return a 404. Signed-off-by: Stephen Finucane --- v3: - Correct license header --- patchwork/models.py | 6 ++++++ patchwork/urls.py | 7 ++++++- patchwork/views/series.py | 35 +++++++++++++++++++++++++++++++++++ patchwork/views/utils.py | 17 +++++++++++++++++ 4 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 patchwork/views/series.py diff --git a/patchwork/models.py b/patchwork/models.py index 94aaa0f..22ab522 100644 --- a/patchwork/models.py +++ b/patchwork/models.py @@ -589,6 +589,12 @@ class Series(models.Model): def received_all(self): return self.total <= self.received_total + @property + def filename(self): + fname_re = re.compile(r'[^-_A-Za-z0-9\.]+') + fname = fname_re.sub('-', str(self)) + return fname.strip('-') + '.patch' + def add_cover_letter(self, cover): """Add a cover letter to the series. diff --git a/patchwork/urls.py b/patchwork/urls.py index 7a8ea95..ef283c0 100644 --- a/patchwork/urls.py +++ b/patchwork/urls.py @@ -32,6 +32,7 @@ from patchwork.views import notification as notification_views from patchwork.views import patch as patch_views from patchwork.views import project as project_views from patchwork.views import pwclient as pwclient_views +from patchwork.views import series as series_views from patchwork.views import user as user_views from patchwork.views import xmlrpc as xmlrpc_views @@ -61,10 +62,14 @@ urlpatterns = [ url(r'^cover/(?P\d+)/$', cover_views.cover_detail, name='cover-detail'), - # comment urls + # comment views url(r'^comment/(?P\d+)/$', comment_views.comment, name='comment-redirect'), + # series views + url(r'^series/(?P\d+)/mbox/$', series_views.series_mbox, + name='series-mbox'), + # logged-in user stuff url(r'^user/$', user_views.profile, name='user-profile'), url(r'^user/todo/$', user_views.todo_lists, diff --git a/patchwork/views/series.py b/patchwork/views/series.py new file mode 100644 index 0000000..a59bffd --- /dev/null +++ b/patchwork/views/series.py @@ -0,0 +1,35 @@ +# Patchwork - automated patch tracking system +# Copyright (C) 2017 Stephen Finucane +# +# This file is part of the Patchwork package. +# +# Patchwork is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# Patchwork is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with Patchwork; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + +from django.http import HttpResponse +from django.shortcuts import get_object_or_404 + +from patchwork.models import Series +from patchwork.views.utils import series_to_mbox + + +def series_mbox(request, series_id): + series = get_object_or_404(Series, id=series_id) + + response = HttpResponse(content_type='text/plain') + response.write(series_to_mbox(series)) + response['Content-Disposition'] = 'attachment; filename=' + \ + series.filename.replace(';', '').replace('\n', '') + + return response diff --git a/patchwork/views/utils.py b/patchwork/views/utils.py index f936ed8..49d9c0c 100644 --- a/patchwork/views/utils.py +++ b/patchwork/views/utils.py @@ -151,3 +151,20 @@ def series_patch_to_mbox(patch, series_num): mbox.append(patch_to_mbox(patch)) return '\n'.join(mbox) + + +def series_to_mbox(series): + """Get an mbox representation of an entire series. + + Arguments: + series: The Series object to convert. + + Returns: + A string for the mbox file. + """ + mbox = [] + + for dep in series.seriespatch_set.all(): + mbox.append(patch_to_mbox(dep.patch)) + + return '\n'.join(mbox)