From patchwork Tue Jul 30 19:08:59 2013 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kamal Mostafa X-Patchwork-Id: 263514 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from huckleberry.canonical.com (huckleberry.canonical.com [91.189.94.19]) by ozlabs.org (Postfix) with ESMTP id B31BB2C00BF for ; Wed, 31 Jul 2013 05:10:19 +1000 (EST) Received: from localhost ([127.0.0.1] helo=huckleberry.canonical.com) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1V4FJB-0000iJ-0Q; Tue, 30 Jul 2013 19:10:09 +0000 Received: from youngberry.canonical.com ([91.189.89.112]) by huckleberry.canonical.com with esmtp (Exim 4.76) (envelope-from ) id 1V4FIP-0000WU-R9 for kernel-team@lists.ubuntu.com; Tue, 30 Jul 2013 19:09:21 +0000 Received: from c-67-160-231-162.hsd1.ca.comcast.net ([67.160.231.162] helo=fourier) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1V4FIP-0007bb-Kn; Tue, 30 Jul 2013 19:09:21 +0000 Received: from kamal by fourier with local (Exim 4.80) (envelope-from ) id 1V4FIN-0000kq-M7; Tue, 30 Jul 2013 12:09:19 -0700 From: Kamal Mostafa To: luis.henriques@canonical.com Subject: [kteam-tools][PATCH 1/3] notify-stable-review: factor out generate_cover_letter() Date: Tue, 30 Jul 2013 12:08:59 -0700 Message-Id: <1375211341-2827-2-git-send-email-kamal@canonical.com> X-Mailer: git-send-email 1.8.1.2 In-Reply-To: <1375211341-2827-1-git-send-email-kamal@canonical.com> References: <1375211341-2827-1-git-send-email-kamal@canonical.com> Cc: kernel-team@lists.ubuntu.com, Kamal Mostafa X-BeenThere: kernel-team@lists.ubuntu.com X-Mailman-Version: 2.1.14 Precedence: list List-Id: Kernel team discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: kernel-team-bounces@lists.ubuntu.com Sender: kernel-team-bounces@lists.ubuntu.com Code re-factor; no functional change. Signed-off-by: Kamal Mostafa --- stable/notify-stable-review | 121 +++++++++++++++++++++++++------------------- 1 file changed, 68 insertions(+), 53 deletions(-) diff --git a/stable/notify-stable-review b/stable/notify-stable-review index 7a36c7e..ef6952b 100755 --- a/stable/notify-stable-review +++ b/stable/notify-stable-review @@ -200,6 +200,70 @@ see https://wiki.ubuntu.com/Kernel/Dev/ExtendedStable . new_ver, base_ver, sender.split()[0] ) # end of def message_text + # function to generate the announcement email (cover letter) + # + def generate_cover_letter(self, editor, sender, base_ver, main_ver): + + new_ver = self.cfg['new_version'] + old_head = self.cfg['previous_release'] + + ann_ver = "%s.z" % base_ver + + # Get the number of patches, diffstat and shortlog from + # previous release + status, result = run_command("git log --no-merges " + "--format=%%h %s.. | wc -l" % + (old_head), self.debug_run) + if status != 0: + raise GitError("\n".join(result)) + patch_cnt = result[0] + status, diffstat = getstatusoutput("git diff --stat %s.." % + (old_head)) + if status != 0: + raise GitError(diffstat) + status, shortlog = getstatusoutput("git shortlog %s.." % + (old_head)) + if status != 0: + raise GitError(shortlog) + + mailbody = "# This is the cover letter message for the patch" + mailbody += " series, that will be\n# sent as the start for" + mailbody += " the review thread. Review this and edit+save" + mailbody += " if\n# necessary. Lines beginning with '#' will" + mailbody += " not be included in the sent\n# email.\n#\n" + mailbody += "From: " + sender + '\n' + for entry in self.tolist: + mailbody += "To: " + entry + '\n' + mailbody += ("Subject: [ %s extended stable ] Linux %s stable review" + % (ann_ver, new_ver) + "\n") + mailbody += "X-Extended-Stable: %s\n" % (main_ver) + mailbody += self.message_text(base_ver, new_ver, patch_cnt, sender) + mailbody += diffstat + '\n\n' + mailbody += shortlog + tf = NamedTemporaryFile(prefix="pmail-") + tf.write(mailbody) + tf.flush() + try: + call([editor, tf.name]) + except: + print("%s not found to edit cover letter for the patch series." + % editor) + print("Please install an editor, if your system doesn't have") + print(" /usr/bin/editor setup as alternatives, you can set the") + print(" NSR_EDITOR environment variable pointing to the editor") + print(" executable (eg. vim, nano, etc.)") + tf.close() + return + tfe = NamedTemporaryFile(prefix="mail-") + tf.seek(0) + for line in tf: + if line.startswith("#"): + continue + tfe.write(line) + tfe.flush() + tf.close() + return tfe; + # function to add headers to the patches # def modify_patch(self, patch, version, basever): @@ -331,28 +395,10 @@ see https://wiki.ubuntu.com/Kernel/Dev/ExtendedStable . else: base_ver = "%s.%s.y" % (kver[0], kver[1]) main_ver = "%s.%s" % (kver[0], kver[1]) - ann_ver = "%s.z" % base_ver old_head = self.cfg['previous_release'] new_ver = self.cfg['new_version'] - # Get the number of patches, diffstat and shortlog from - # previous release - status, result = run_command("git log --no-merges " - "--format=%%h %s.. | wc -l" % - (old_head), self.debug_run) - if status != 0: - raise GitError("\n".join(result)) - patch_cnt = result[0] - status, diffstat = getstatusoutput("git diff --stat %s.." % - (old_head)) - if status != 0: - raise GitError(diffstat) - status, shortlog = getstatusoutput("git shortlog %s.." % - (old_head)) - if status != 0: - raise GitError(shortlog) - # Create emails and send them tmpdir = mkdtemp() status, result = run_command("git format-patch -o %s %s.." % @@ -363,43 +409,12 @@ see https://wiki.ubuntu.com/Kernel/Dev/ExtendedStable . patches = listdir(tmpdir) for patch in patches: self.modify_patch(tmpdir + "/" + patch, new_ver, main_ver) - mailbody = "# This is the cover letter message for the patch" - mailbody += " series, that will be\n# sent as the start for" - mailbody += " the review thread. Review this and edit+save" - mailbody += " if\n# necessary. Lines beginning with '#' will" - mailbody += " not be included in the sent\n# email.\n#\n" - mailbody += "From: " + sender + '\n' - for entry in self.tolist: - mailbody += "To: " + entry + '\n' - mailbody += ("Subject: [ %s extended stable ] Linux %s stable review" - % (ann_ver, new_ver) + "\n") - mailbody += "X-Extended-Stable: %s\n" % (main_ver) - mailbody += self.message_text(base_ver, new_ver, patch_cnt, sender) - mailbody += diffstat + '\n\n' - mailbody += shortlog - tf = NamedTemporaryFile(prefix="pmail-") - tf.write(mailbody) - tf.flush() - try: - call([editor, tf.name]) - except: - print("%s not found to edit cover letter for the patch series." - % editor) - print("Please install an editor, if your system doesn't have") - print(" /usr/bin/editor setup as alternatives, you can set the") - print(" NSR_EDITOR environment variable pointing to the editor") - print(" executable (eg. vim, nano, etc.)") - tf.close() + + tfe = self.generate_cover_letter(editor, sender, base_ver, main_ver) + if not tfe: rmtree(tmpdir) return - tfe = NamedTemporaryFile(prefix="mail-") - tf.seek(0) - for line in tf: - if line.startswith("#"): - continue - tfe.write(line) - tfe.flush() - tf.close() + cmd = "git send-email --no-chain-reply-to --thread " cmd += "--from \"" + sender + "\"" for line in self.tolist: