Control: retitle -1 ResourceWarnings in dh_python3 and py3clean because of 
unclosed files

There are some unclosed files in dh_python3, too:

        /usr/share/python3/debpython/debhelper.py:140: ResourceWarning: 
unclosed file <_io.TextIOWrapper name='debian/python3-markdown.substvars' 
mode='r' encoding='UTF-8'>
          data = open(fn, 'r').read()
        /usr/share/python3/debpython/debhelper.py:105: ResourceWarning: 
unclosed file <_io.TextIOWrapper name='debian/python3-markdown.prerm.debhelper' 
mode='r' encoding='UTF-8'>
          data = open(fn, 'r').read()
        /usr/share/python3/debpython/debhelper.py:117: ResourceWarning: 
unclosed file <_io.TextIOWrapper 
name='/usr/share/debhelper/autoscripts/prerm-py3clean' mode='r' 
encoding='UTF-8'>
          tpl = open(fpath, 'r').read()
        /usr/share/python3/debpython/debhelper.py:105: ResourceWarning: 
unclosed file <_io.TextIOWrapper 
name='debian/python3-markdown.postinst.debhelper' mode='r' encoding='UTF-8'>
          data = open(fn, 'r').read()
        /usr/share/python3/debpython/debhelper.py:117: ResourceWarning: 
unclosed file <_io.TextIOWrapper 
name='/usr/share/debhelper/autoscripts/postinst-py3compile' mode='r' 
encoding='UTF-8'>
          tpl = open(fpath, 'r').read()

Updated patch that fixes these warnings is attached.

--
Dmitry Shachnev
Author: Dmitry Shachnev <[email protected]>
Description: Fix some ResourceWarnings caused by unclosed files
Bug: http://bugs.debian.org/686587
=== modified file 'debian/py3versions.py'
--- debian/py3versions.py	2012-06-30 19:15:05 +0000
+++ debian/py3versions.py	2012-09-14 16:37:00 +0000
@@ -193,6 +193,7 @@
             if section != 'Source':
                 raise ValueError('attribute X-Python3-Version not in Source section')
             sversion = line.split(':', 1)[1].strip()
+    fn.close()
     if section == None:
         raise ControlFileValueError('not a control file')
     if pkg == 'Source':

=== modified file 'debpython/debhelper.py'
--- debpython/debhelper.py	2012-08-02 21:43:51 +0000
+++ debpython/debhelper.py	2012-09-14 16:37:00 +0000
@@ -24,6 +24,11 @@
 
 log = logging.getLogger(__name__)
 
+def _read_from_file(filename):
+    fileobj = open(filename, "r")
+    text = fileobj.read()
+    fileobj.close()
+    return text
 
 class DebHelper:
     """Reinvents the wheel / some dh functionality (Perl is ugly ;-P)"""
@@ -102,7 +107,7 @@
             for when, templates in autoscripts.items():
                 fn = "debian/%s.%s.debhelper" % (package, when)
                 if exists(fn):
-                    data = open(fn, 'r').read()
+                    data = _read_from_file(fn)
                 else:
                     data = ''
 
@@ -114,7 +119,7 @@
                                      "autoscripts/%s" % tpl_name)
                         if not exists(fpath):
                             fpath = "/usr/share/debhelper/autoscripts/%s" % tpl_name
-                        tpl = open(fpath, 'r').read()
+                        tpl = _read_from_file(fpath)
                         if self.options.compile_all and args:
                             # TODO: should args be checked to contain dir name?
                             tpl = tpl.replace('#PACKAGE#', '')
@@ -137,7 +142,7 @@
                 continue
             fn = "debian/%s.substvars" % package
             if exists(fn):
-                data = open(fn, 'r').read()
+                data = _read_from_file(fn)
             else:
                 data = ''
             for name, values in substvars.items():

Reply via email to