From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by finch.gentoo.org (Postfix) with ESMTPS id 6B5E6139694 for ; Wed, 15 Mar 2017 21:56:38 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 8F471E0DD1; Wed, 15 Mar 2017 21:56:35 +0000 (UTC) Received: from smtp.gentoo.org (mail.gentoo.org [IPv6:2001:470:ea4a:1:5054:ff:fec7:86e4]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 5BBB1E0DD1 for ; Wed, 15 Mar 2017 21:56:35 +0000 (UTC) Received: from oystercatcher.gentoo.org (unknown [IPv6:2a01:4f8:202:4333:225:90ff:fed9:fc84]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 47BA8340AD2 for ; Wed, 15 Mar 2017 21:56:34 +0000 (UTC) Received: from localhost.localdomain (localhost [IPv6:::1]) by oystercatcher.gentoo.org (Postfix) with ESMTP id B4DD56978 for ; Wed, 15 Mar 2017 21:56:31 +0000 (UTC) From: "Brian Dolbec" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Brian Dolbec" Message-ID: <1489614962.fd893603470071e5657e381f4461ee11a31474d6.dolsen@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: repoman/pym/repoman/ X-VCS-Repository: proj/portage X-VCS-Files: repoman/pym/repoman/actions.py repoman/pym/repoman/utilities.py X-VCS-Directories: repoman/pym/repoman/ X-VCS-Committer: dolsen X-VCS-Committer-Name: Brian Dolbec X-VCS-Revision: fd893603470071e5657e381f4461ee11a31474d6 X-VCS-Branch: master Date: Wed, 15 Mar 2017 21:56:31 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 727387a1-87af-40e1-9f8b-c67c1625b17d X-Archives-Hash: c98f03a4afb8895ec36f7e9d2b5e8c8d commit: fd893603470071e5657e381f4461ee11a31474d6 Author: Doug Goldstein cardoe com> AuthorDate: Wed Mar 15 21:27:30 2017 +0000 Commit: Brian Dolbec gentoo org> CommitDate: Wed Mar 15 21:56:02 2017 +0000 URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=fd893603 repoman: Change how the tmp file for the commit msg is made (bug 571546) Changes the way the temporary file for the commit message is generated to make a temporary directory and create a file called COMMIT_EDITMSG inside of it. This is to cause various editors to treat this as a git style commit message by default. Signed-off-by: Doug Goldstein cardoe.com> X-Gentoo-Bug: 571546 X-Gentoo-Bug-URL: https://bugs.gentoo.org/show_bug.cgi?id=571546 repoman/pym/repoman/actions.py | 21 +++++++++++---------- repoman/pym/repoman/utilities.py | 39 ++++++++++++++++++++------------------- 2 files changed, 31 insertions(+), 29 deletions(-) diff --git a/repoman/pym/repoman/actions.py b/repoman/pym/repoman/actions.py index 6b0c6459d..73b44c5f5 100644 --- a/repoman/pym/repoman/actions.py +++ b/repoman/pym/repoman/actions.py @@ -7,6 +7,7 @@ import io import logging import platform import re +import shutil import signal import sys import tempfile @@ -457,15 +458,15 @@ class Actions(object): myfiles += myremoved myfiles.sort() - fd, commitmessagefile = tempfile.mkstemp(".repoman.msg") - mymsg = os.fdopen(fd, "wb") - mymsg.write(_unicode_encode(commitmessage)) - mymsg.close() + commitmessagedir = tempfile.mkdtemp(".repoman.msg") + commitmessagefile = os.path.join(commitmessagedir, "COMMIT_EDITMSG") + with open(commitmessagefile, "wb") as mymsg: + mymsg.write(_unicode_encode(commitmessage)) retval = self.vcs_settings.changes.commit(myfiles, commitmessagefile) # cleanup the commit message before possibly exiting try: - os.unlink(commitmessagefile) + shutil.rmtree(commitmessagedir) except OSError: pass if retval != os.EX_OK: @@ -478,10 +479,10 @@ class Actions(object): def priming_commit(self, myupdates, myremoved, commitmessage): myfiles = myupdates + myremoved - fd, commitmessagefile = tempfile.mkstemp(".repoman.msg") - mymsg = os.fdopen(fd, "wb") - mymsg.write(_unicode_encode(commitmessage)) - mymsg.close() + commitmessagedir = tempfile.mkdtemp(".repoman.msg") + commitmessagefile = os.path.join(commitmessagedir, "COMMIT_EDITMSG") + with open(commitmessagefile, "wb") as mymsg: + mymsg.write(_unicode_encode(commitmessage)) separator = '-' * 78 @@ -500,7 +501,7 @@ class Actions(object): retval = self.vcs_settings.changes.commit(myfiles, commitmessagefile) # cleanup the commit message before possibly exiting try: - os.unlink(commitmessagefile) + shutil.rmtree(commitmessagedir) except OSError: pass if retval != os.EX_OK: diff --git a/repoman/pym/repoman/utilities.py b/repoman/pym/repoman/utilities.py index 8a757dc85..c204faa8d 100644 --- a/repoman/pym/repoman/utilities.py +++ b/repoman/pym/repoman/utilities.py @@ -30,7 +30,7 @@ import sys import time import textwrap import difflib -from tempfile import mkstemp +import tempfile # import our initialized portage instance from repoman._portage import portage @@ -187,23 +187,24 @@ def get_commit_message_with_editor(editor, message=None, prefix=""): @rtype: string or None @return: A string on success or None if an error occurs. """ - fd, filename = mkstemp() + commitmessagedir = tempfile.mkdtemp(".repoman.msg") + filename = os.path.join(commitmessagedir, "COMMIT_EDITMSG") try: - os.write( - fd, _unicode_encode(_( - prefix + - "\n\n# Please enter the commit message " - "for your changes.\n# (Comment lines starting " - "with '#' will not be included)\n"), - encoding=_encodings['content'], errors='backslashreplace')) - if message: - os.write(fd, b"#\n") - for line in message: - os.write( - fd, _unicode_encode( - "#" + line, encoding=_encodings['content'], - errors='backslashreplace')) - os.close(fd) + with open(filename, "wb") as mymsg: + mymsg.write( + _unicode_encode(_( + prefix + + "\n\n# Please enter the commit message " + "for your changes.\n# (Comment lines starting " + "with '#' will not be included)\n"), + encoding=_encodings['content'], errors='backslashreplace')) + if message: + mymsg.write(b"#\n") + for line in message: + mymsg.write( + _unicode_encode( + "#" + line, encoding=_encodings['content'], + errors='backslashreplace')) retval = os.system(editor + " '%s'" % filename) if not (os.WIFEXITED(retval) and os.WEXITSTATUS(retval) == os.EX_OK): return None @@ -220,7 +221,7 @@ def get_commit_message_with_editor(editor, message=None, prefix=""): return "".join(line for line in mylines if not line.startswith("#")) finally: try: - os.unlink(filename) + shutil.rmtree(commitmessagedir) except OSError: pass @@ -409,7 +410,7 @@ def UpdateChangeLog( except EnvironmentError: pass - f, clnew_path = mkstemp() + f, clnew_path = tempfile.mkstemp() # construct correct header first try: