From patchwork Thu Jun 11 18:34:55 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Rohit Sarkar X-Patchwork-Id: 1307693 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)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 49jXc43PN1z9sRh for ; Fri, 12 Jun 2020 04:35:48 +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.a=rsa-sha256 header.s=20161025 header.b=ENlm6jtH; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 49jXc167fQzDqpf for ; Fri, 12 Jun 2020 04:35:45 +1000 (AEST) X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::543; helo=mail-pg1-x543.google.com; envelope-from=rohitsarkar5398@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.a=rsa-sha256 header.s=20161025 header.b=ENlm6jtH; dkim-atps=neutral Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) (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 49jXbc1D9zzDqrZ for ; Fri, 12 Jun 2020 04:35:24 +1000 (AEST) Received: by mail-pg1-x543.google.com with SMTP id 185so2880912pgb.10 for ; Thu, 11 Jun 2020 11:35:23 -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=bB8cTaItX835Oj5skPWowUlk2lmdtDf35U5cv3CFqL4=; b=ENlm6jtHVX0eUdlnhFWQwI7j0J6BtXgQL51yG4sUYbI7bclIwpd2rwRFsU5zFSCqh7 VCodnO6jiDjYnzS0K4F/g/0/V5nGhfs8qe/mIqlvT+ME23CUxvV2vVzb9LEs0PTbcLyW y1v6Tvac2x5umhCB0z6bf8Q2KDPA5KEGxyIGfnP1ejGaehbAxTIDTN79AXb/6CnqVYE4 aV1gIneohV2FO48FERwPCY/ZDudp3CHx7bIrqEP8hJvNZdqe00lG09wx1GudqjfQ4JtK uMRmwc32CLUE9CI9u1eZ1yvCR2AQjyz/IHFUOjxqn9U9ZfXm2OTKl1EBD0Oay4+aet5I j8lA== 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=bB8cTaItX835Oj5skPWowUlk2lmdtDf35U5cv3CFqL4=; b=Va+aIwcv4vwb+CgsulXc0iVC0Zv5FZf+O8u1gYZUFzjCstz9MdUW9fVV1UHdfsB0Rw nRw+Xt39VQActi3Rsw4pL7P5VhKfFLFw/ZyceA7lmjwiqEFQYQ9RvWsOH3g3+ElD4AoO tKDV/BbybuWXywG8bO193lqghDRHoYpCmTM2FRnyzmQB0v1X8LASuVU2b83yvI2a9J/W dh3KY8kE2EmtNuKQTI6d+dbn4qaCNFWAeVu3oEpXg6UT2WbAg2M5/ugWRdS6Eivao+Vj 2iTspoW4dw/dHz0rTFAKBhaESAzPH786AS3LKoUTI0QYieuV/Xo6Dzwo9QCJ0RRSoBsw 9WgA== X-Gm-Message-State: AOAM532riaFBArZlhVcNZYNRf/KEYcAGMcYS5c2AK0S7g0guMx0E3Gz5 Kym25bqYW7oRyMm+ONnQJMp250Pxq58= X-Google-Smtp-Source: ABdhPJwax+k6nvST3SNrBURfE8lCmyVs89JDtABY4/d6QQBKkcB9Hk8JuNhFy6LjsI68WPMZToZuKw== X-Received: by 2002:a65:6384:: with SMTP id h4mr7411307pgv.192.1591900520781; Thu, 11 Jun 2020 11:35:20 -0700 (PDT) Received: from localhost.localdomain ([49.207.57.96]) by smtp.gmail.com with ESMTPSA id h3sm3248274pgk.67.2020.06.11.11.35.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 11 Jun 2020 11:35:20 -0700 (PDT) From: Rohit Sarkar To: patchwork@lists.ozlabs.org Subject: [PATCH v2 1/1] management: introduce parserelations command Date: Fri, 12 Jun 2020 00:04:55 +0530 Message-Id: <20200611183455.18240-2-rohitsarkar5398@gmail.com> X-Mailer: git-send-email 2.23.0.385.gbc12974a89 In-Reply-To: <20200611183455.18240-1-rohitsarkar5398@gmail.com> References: <20200611183455.18240-1-rohitsarkar5398@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: ralf.ramsauer@oth-regensburg.de Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" The parserelations script is used to ingest relations into Patchwork's patch database. A patch groups file is taken as input, which on each line contains a space separated list of patchwork ids denoting a relation. All the existing relations in Patchwork's database are removed and the relations read from the patch groups file are ingested. Signed-off-by: Rohit Sarkar --- docs/deployment/management.rst | 26 +++++++ .../management/commands/parserelations.py | 71 +++++++++++++++++++ patchwork/tests/test_management.py | 7 ++ 3 files changed, 104 insertions(+) create mode 100644 patchwork/management/commands/parserelations.py diff --git a/docs/deployment/management.rst b/docs/deployment/management.rst index 9c57f19..3a9bb2b 100644 --- a/docs/deployment/management.rst +++ b/docs/deployment/management.rst @@ -116,6 +116,32 @@ the :ref:`deployment installation guide `. input mbox filename. If not supplied, a patch will be read from ``stdin``. +parserelations +~~~~~~~~~~~~~~ + +.. program:: manage.py parserelations + +Parse a patch groups file and store any relation found + +.. code-block:: shell + + ./manage.py parserelations + +This is a script used to ingest relations into Patchwork. +A patch groups file contains on each line patchwork ids of patches that form a relation. +Eg contents of a patch groups file: + + 1 3 5 + 2 + 7 10 11 12 + +In this case the script will identify 2 relations, (1, 3, 5) and (7, 10, 11, 12). +Running this script will remove all existing relations and replace them with the relations found in the file. + +.. option:: infile + + input patch groups file. + rehash ~~~~~~ diff --git a/patchwork/management/commands/parserelations.py b/patchwork/management/commands/parserelations.py new file mode 100644 index 0000000..ca8a523 --- /dev/null +++ b/patchwork/management/commands/parserelations.py @@ -0,0 +1,71 @@ +# Patchwork - automated patch tracking system +# Copyright (C) 2020 Rohit Sarkar +# +# SPDX-License-Identifier: GPL-2.0-or-later + +import logging +import os +import sys + +from django.db import transaction +from django.core.management.base import BaseCommand + +from patchwork.models import Patch +from patchwork.models import PatchRelation + +logger = logging.getLogger(__name__) + +class Command(BaseCommand): + help = 'Parse a relations file generated by PaStA and replace existing relations with the ones parsed' + + def add_arguments(self, parser): + parser.add_argument( + 'infile', + help='input relations filename') + + def handle(self, *args, **options): + verbosity = int(options['verbosity']) + if not verbosity: + level = logging.CRITICAL + elif verbosity == 1: + level = logging.ERROR + elif verbosity == 2: + level = logging.INFO + else: + level = logging.DEBUG + + logger.setLevel(level) + + path = args and args[0] or options['infile'] + if not os.path.exists(path): + logger.error('Invalid path: %s', path) + sys.exit(1) + + + with open(path, 'r') as f: + lines = f.readlines() + + # filter out trailing empty lines + while len(lines) and not lines[-1]: + lines.pop() + + relations = [line.split(' ') for line in lines] + + with transaction.atomic(): + PatchRelation.objects.all().delete() + count = len(relations) + ingested = 0 + logger.info('Parsing %d relations' % count) + for i, patch_ids in enumerate(relations): + related_patches = Patch.objects.filter(id__in=patch_ids) + if len(related_patches) > 1: + relation = PatchRelation() + relation.save() + related_patches.update(related=relation) + ingested += 1 + + if i % 10 == 0: + self.stdout.write('%06d/%06d\r' % (i, count), ending='') + self.stdout.flush() + + self.stdout.write('Ingested %d relations' % ingested) diff --git a/patchwork/tests/test_management.py b/patchwork/tests/test_management.py index 66c6bad..186ea56 100644 --- a/patchwork/tests/test_management.py +++ b/patchwork/tests/test_management.py @@ -124,3 +124,10 @@ class ParsearchiveTest(TestCase): self.assertIn('Processed 1 messages -->', out.getvalue()) self.assertIn(' 1 dropped', out.getvalue()) + +class ParserelationsTest(TestCase): + def test_invalid_path(self): + out = StringIO() + with self.assertRaises(SystemExit) as exc: + call_command('parserelations', 'xyz123random', stdout=out) + self.assertEqual(exc.exception.code, 1)