[Reportbug-commits] [reportbug] 25/38: Make sure some file descriptors will be closed properly
Sandro Tosi
morph at moszumanska.debian.org
Fri Dec 29 04:33:45 UTC 2017
This is an automated email from the git hooks/post-receive script.
morph pushed a commit to branch master
in repository reportbug.
commit 4ecc16193ec3bd94e91649245e70d49a03244591
Author: Nis Martensen <nis.martensen at web.de>
Date: Mon Dec 4 21:33:15 2017 +0100
Make sure some file descriptors will be closed properly
---
bin/reportbug | 3 ++-
reportbug/submit.py | 3 ++-
reportbug/ui/text_ui.py | 18 ++++++++++--------
3 files changed, 14 insertions(+), 10 deletions(-)
diff --git a/bin/reportbug b/bin/reportbug
index 61e54ab..fe170ea 100755
--- a/bin/reportbug
+++ b/bin/reportbug
@@ -339,7 +339,8 @@ def handle_editing(filename, dmessage, options, sendto, attachments, package,
skip_editing = True
if x == 'l':
pager = os.environ.get('PAGER', 'sensible-pager')
- os.popen(pager, 'w').write(message)
+ with os.popen(pager, 'w') as p:
+ p.write(message)
else:
sys.stdout.write(message)
elif x == 't':
diff --git a/reportbug/submit.py b/reportbug/submit.py
index 1eb1b71..474c937 100644
--- a/reportbug/submit.py
+++ b/reportbug/submit.py
@@ -279,7 +279,8 @@ def send_report(body, attachments, mua, fromaddr, sendto, ccaddr, bccaddr,
if paranoid and not (template or printonly):
pager = os.environ.get('PAGER', 'sensible-pager')
try:
- os.popen(pager, 'w').write(message)
+ with os.popen(pager, 'w') as p:
+ p.write(message)
except Exception as e:
# if the PAGER exits before all the text has been sent,
# it'd send a SIGPIPE, so crash only if that's not the case
diff --git a/reportbug/ui/text_ui.py b/reportbug/ui/text_ui.py
index b852b79..4a60ff8 100644
--- a/reportbug/ui/text_ui.py
+++ b/reportbug/ui/text_ui.py
@@ -451,10 +451,9 @@ def show_report(number, system, mirrors,
text = 'Original report - %s\n\n%s' % (buginfo.subject, messages[0])
if not skip_pager:
- fd = os.popen('sensible-pager', 'w')
try:
- fd.write(text)
- fd.close()
+ with os.popen('sensible-pager', 'w') as fd:
+ fd.write(text)
except IOError as x:
if x.errno == errno.EPIPE:
pass
@@ -1009,7 +1008,8 @@ def display_report(text, use_pager=True, presubj=False):
pager = os.environ.get('PAGER', 'sensible-pager')
try:
- os.popen(pager, 'w').write(text)
+ with os.popen(pager, 'w') as p:
+ p.write(text)
except IOError:
pass
@@ -1023,9 +1023,10 @@ def spawn_editor(message, filename, editor, charset='utf-8'):
# Move the cursor for lazy buggers like me; add your editor here...
ourline = 0
- for (lineno, line) in enumerate(open(filename)):
- if line == '\n' and not ourline:
- ourline = lineno + 2
+ with open(filename) as f:
+ for (lineno, line) in enumerate(f):
+ if line == '\n' and not ourline:
+ ourline = lineno + 2
opts = ''
if 'vim' in edname:
@@ -1061,7 +1062,8 @@ def spawn_editor(message, filename, editor, charset='utf-8'):
if '&' in editor:
return (None, 1)
- newmessage = open(filename).read()
+ with open(filename) as f:
+ newmessage = f.read()
if newmessage == message:
ewrite('No changes were made in the editor.\n')
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/reportbug/reportbug.git
More information about the Reportbug-commits
mailing list