From patchwork Fri Jun 28 11:43:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mete Polat X-Patchwork-Id: 1124131 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45Zw0V5Nhgz9s3Z for ; Fri, 28 Jun 2019 21:44:26 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="N8lpYzo1"; 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 45Zw0V3lgFzDqrV for ; Fri, 28 Jun 2019 21:44:26 +1000 (AEST) X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gmail.com (client-ip=2a00:1450:4864:20::42c; helo=mail-wr1-x42c.google.com; envelope-from=metepolat2000@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="N8lpYzo1"; dkim-atps=neutral Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 45Zw01254gzDqlw for ; Fri, 28 Jun 2019 21:43:57 +1000 (AEST) Received: by mail-wr1-x42c.google.com with SMTP id f9so5922557wre.12 for ; Fri, 28 Jun 2019 04:43:57 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ds3xPiCa3YWZElvHRfvk47A9Ta1JIGFMh3QUf19GP8U=; b=N8lpYzo1nVe9xIGjs0XaM7AikJaa8bh4FmmcysEnnjlTtXDUKs9sZLtd6/65ZkSm/9 Y47XANCBfRrUpHjyY4GhcI3YynLTdX4Rcbg2xC+H1MBddqX5C9VHO+jE18JeRNfvrh6m 5KeGhG2fKp94YRTCwHT/LmFnFbOVSuho2ZN1j1vCgGgUSd33nwsj/K7nxQ2KiT8W8YMt 8IaOW84hlk+SPkGgV91bbBeteppgq6f6D+huGB+QLO5FlVUwMkgQH27CsscpcEvbLNGk 7IMuc7FYls3E5TO4d2up3+Kda8NRQa5LbelbIWTS7gIeaz22Nih4aVrkW1WuDo1/xTty Bnwg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ds3xPiCa3YWZElvHRfvk47A9Ta1JIGFMh3QUf19GP8U=; b=K5lOKE4YJEHoELPmWhEDRTsnGdITfKogg3ONzlEPToPVsL2IfoVibNA0kmoGJ2/q4M QpJ+xj9B9bvozgY55Pl58ish68+8BGUKGFB9MunA2dhMIKv2V2sw/PXXN479IoDrijCi O/krCFpxqgYzzka/fU5a6EwC8fFT489yAF0DGK8vY4KpaOU9snwDDvfiLlND2h/+W4Sd pqXoBbfJum2TXmXfboBXg9uhLNNbuY/ljyOSpWLD0lzg+Xq0oP/QsUBSng3jdGBOO2J8 RDNFfuLyg1Gy7SInpsZ51FpLyzKXwld0MnT5tQBSJYnQHRf6S8A1jKS/AtYunpYGwkNe Gk0w== X-Gm-Message-State: APjAAAX60TxPelao7aImZEznhG8Ir3XlDgCmTe1PeAqYQJP1tKVG4Qok BtLMbhbeoOVXPyXPOJJ6ALaZrszScCVyDw== X-Google-Smtp-Source: APXvYqwhsbO7OdrjzjAwBFZYF2n1e8EjrJDL4efh3Ctvi5mQXPe3C3a3F3teuvtli3eCOm8K1Lf1bA== X-Received: by 2002:adf:82ca:: with SMTP id 68mr7487286wrc.250.1561722234232; Fri, 28 Jun 2019 04:43:54 -0700 (PDT) Received: from localhost.localdomain ([193.23.33.53]) by smtp.gmail.com with ESMTPSA id q12sm3258127wrp.50.2019.06.28.04.43.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 28 Jun 2019 04:43:53 -0700 (PDT) From: Mete Polat To: patchwork@lists.ozlabs.org Subject: [PATCH 1/5] Add option to get all project patches in one mbox Date: Fri, 28 Jun 2019 13:43:10 +0200 Message-Id: <20190628114314.10462-2-metepolat2000@gmail.com> X-Mailer: git-send-email 2.22.0 In-Reply-To: <20190628114314.10462-1-metepolat2000@gmail.com> References: <20190628114314.10462-1-metepolat2000@gmail.com> MIME-Version: 1.0 X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lukas.bulwahn@gmail.com Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" FilenameMixin.filename(self) returns a sanitized filename based on the str representation of the object. In our case str(project) returns the project name. Thus the output file will be .mbox Signed-off-by: Mete Polat --- patch_list_mbox() and project_patches_to_mbox() are not named project_mbox() and project_to_mbox() in order to prevent confusion. While a project also consists of cover letters, those are not intended to be included. patchwork/models.py | 22 +++++++++++----------- patchwork/views/patch.py | 12 ++++++++++++ patchwork/views/utils.py | 13 +++++++++++++ 3 files changed, 36 insertions(+), 11 deletions(-) diff --git a/patchwork/models.py b/patchwork/models.py index a7eee4d..36d6fad 100644 --- a/patchwork/models.py +++ b/patchwork/models.py @@ -55,8 +55,18 @@ class Person(models.Model): verbose_name_plural = 'People' +class FilenameMixin(object): + + @property + def filename(self): + """Return a sanitized filename without extension.""" + fname_re = re.compile(r'[^-_A-Za-z0-9\.]+') + fname = fname_re.sub('-', str(self)).strip('-') + return fname + + @python_2_unicode_compatible -class Project(models.Model): +class Project(FilenameMixin, models.Model): # properties linkname = models.CharField(max_length=255, unique=True) @@ -337,16 +347,6 @@ class EmailMixin(models.Model): abstract = True -class FilenameMixin(object): - - @property - def filename(self): - """Return a sanitized filename without extension.""" - fname_re = re.compile(r'[^-_A-Za-z0-9\.]+') - fname = fname_re.sub('-', str(self)).strip('-') - return fname - - @python_2_unicode_compatible class Submission(FilenameMixin, EmailMixin, models.Model): # parent diff --git a/patchwork/views/patch.py b/patchwork/views/patch.py index 277b281..cf494ad 100644 --- a/patchwork/views/patch.py +++ b/patchwork/views/patch.py @@ -20,6 +20,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 project_patches_to_mbox from patchwork.views.utils import series_patch_to_mbox @@ -34,6 +35,17 @@ def patch_list(request, project_id): return render(request, 'patchwork/list.html', context) +def patch_list_mbox(request, project_id): + project = get_object_or_404(Project, linkname=project_id) + + response = HttpResponse(content_type='text/plain') + response.write(project_patches_to_mbox(project)) + response['Content-Disposition'] = 'attachment; filename=%s.mbox' % ( + project.filename) + + return response + + def patch_detail(request, patch_id): # redirect to cover letters where necessary try: diff --git a/patchwork/views/utils.py b/patchwork/views/utils.py index 1da1aaa..1461525 100644 --- a/patchwork/views/utils.py +++ b/patchwork/views/utils.py @@ -110,6 +110,19 @@ patch_to_mbox = _submission_to_mbox cover_to_mbox = _submission_to_mbox +def project_patches_to_mbox(project): + """Get an mbox representation of all patches in a project. + + Arguments: + project: The project object to convert. + + Returns: + A string for the mbox file. + """ + patches = Patch.objects.filter(patch_project=project) + return '\n'.join([patch_to_mbox(p) for p in patches]) + + def bundle_to_mbox(bundle): """Get an mbox representation of a bundle.