From patchwork Tue Jun 30 08:52:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Finucane X-Patchwork-Id: 489599 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 AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 279901402C8 for ; Tue, 30 Jun 2015 18:54:15 +1000 (AEST) Received: from ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 0DAB71A2B99 for ; Tue, 30 Jun 2015 18:54:15 +1000 (AEST) X-Original-To: patchwork@lists.ozlabs.org Delivered-To: patchwork@lists.ozlabs.org Received: from mga11.intel.com (mga11.intel.com [192.55.52.93]) by lists.ozlabs.org (Postfix) with ESMTP id 6FFF81A1EFE for ; Tue, 30 Jun 2015 18:52:19 +1000 (AEST) Received: from fmsmga002.fm.intel.com ([10.253.24.26]) by fmsmga102.fm.intel.com with ESMTP; 30 Jun 2015 01:52:15 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.15,376,1432623600"; d="scan'208";a="753109315" Received: from irvmail001.ir.intel.com ([163.33.26.43]) by fmsmga002.fm.intel.com with ESMTP; 30 Jun 2015 01:52:14 -0700 Received: from sivswdev01.ir.intel.com (sivswdev01.ir.intel.com [10.237.217.45]) by irvmail001.ir.intel.com (8.14.3/8.13.6/MailSET/Hub) with ESMTP id t5U8qD9l030641; Tue, 30 Jun 2015 09:52:13 +0100 Received: from sivswdev01.ir.intel.com (localhost [127.0.0.1]) by sivswdev01.ir.intel.com with ESMTP id t5U8qDOJ020387; Tue, 30 Jun 2015 09:52:13 +0100 Received: (from sfinucan@localhost) by sivswdev01.ir.intel.com with id t5U8qDrh020381; Tue, 30 Jun 2015 09:52:13 +0100 From: Stephen Finucane To: patchwork@lists.ozlabs.org Subject: [PATCH 10/11] management: Resolve some issues with the commands Date: Tue, 30 Jun 2015 09:52:08 +0100 Message-Id: <1435654329-19960-11-git-send-email-stephen.finucane@intel.com> X-Mailer: git-send-email 2.0.0 In-Reply-To: <1435654329-19960-1-git-send-email-stephen.finucane@intel.com> References: <1435654329-19960-1-git-send-email-stephen.finucane@intel.com> X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Stephen Finucane MIME-Version: 1.0 Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Patchwork" There were a number of bugs in the two commands, due to things like missing imports. Remove unused code and fix the remaining bugs. In addition, add license headers. Signed-off-by: Stephen Finucane --- patchwork/management/commands/cron.py | 30 ++++++++++++++++++------- patchwork/management/commands/retag.py | 40 ++++++++++++++++++++++++---------- 2 files changed, 51 insertions(+), 19 deletions(-) diff --git a/patchwork/management/commands/cron.py b/patchwork/management/commands/cron.py index 6217e75..0367945 100755 --- a/patchwork/management/commands/cron.py +++ b/patchwork/management/commands/cron.py @@ -1,20 +1,34 @@ -#!/usr/bin/env python +# Patchwork - automated patch tracking system +# Copyright (C) 2015 Jeremy Kerr +# +# 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.core.management.base import BaseCommand, CommandError +from django.core.management.base import BaseCommand from patchwork.utils import send_notifications, do_expiry + class Command(BaseCommand): - help = ('Run periodic patchwork functions: send notifications and ' + help = ('Run periodic patchwork functions: send notifications and ' 'expire unused users') def handle(self, *args, **kwargs): errors = send_notifications() for (recipient, error) in errors: self.stderr.write("Failed sending to %s: %s" % - (recipient.email, ex)) + (recipient.email, error)) do_expiry() - -if __name__ == '__main__': - sys.exit(main(sys.argv)) - diff --git a/patchwork/management/commands/retag.py b/patchwork/management/commands/retag.py index e07594a..683f9c5 100644 --- a/patchwork/management/commands/retag.py +++ b/patchwork/management/commands/retag.py @@ -1,7 +1,25 @@ +# Patchwork - automated patch tracking system +# Copyright (C) 2015 Jeremy Kerr +# +# 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.core.management.base import BaseCommand, CommandError +from django.core.management.base import BaseCommand from patchwork.models import Patch -import sys + class Command(BaseCommand): help = 'Update the tag (Ack/Review/Test) counts on existing patches' @@ -9,18 +27,18 @@ class Command(BaseCommand): def handle(self, *args, **options): - qs = Patch.objects + query = Patch.objects if args: - qs = qs.filter(id__in = args) + query = query.filter(id__in=args) + else: + query = query.all() - count = qs.count() - i = 0 + count = query.count() - for patch in qs.iterator(): + for i, patch in enumerate(query.iterator()): patch.refresh_tag_counts() - i += 1 if (i % 10) == 0 or i == count: - sys.stdout.write('%06d/%06d\r' % (i, count)) - sys.stdout.flush() - sys.stderr.write('\ndone\n') + self.stdout.write('%06d/%06d\r' % (i, count)) + self.stdout.flush() + self.stderr.write('\ndone\n')