Fix some ResourceWarnings.
authorArfrever Frehtes Taifersar Arahesis <Arfrever@Apache.Org>
Sun, 10 Feb 2013 03:47:21 +0000 (04:47 +0100)
committerArfrever Frehtes Taifersar Arahesis <Arfrever@Apache.Org>
Sun, 10 Feb 2013 03:47:21 +0000 (04:47 +0100)
bin/archive-conf
bin/repoman
pym/_emerge/depgraph.py
pym/_emerge/getloadavg.py
pym/portage/package/ebuild/deprecated_profile_check.py
pym/repoman/utilities.py

index 2c10884eac4926994d51469912b92309dd69fd50..42b62748ede3b179ffca88de6191a70442614437 100755 (executable)
@@ -63,8 +63,8 @@ def archive_conf():
         md5_match_hash[conf] = ''
 
     # Find all the CONTENT files in VDB_PATH.
-    content_files += os.popen(FIND_EXTANT_CONTENTS %
-                       (os.path.join(portage.settings['EROOT'], portage.VDB_PATH))).readlines()
+    with os.popen(FIND_EXTANT_CONTENTS % (os.path.join(portage.settings['EROOT'], portage.VDB_PATH))) as f:
+           content_files += f.readlines()
 
     # Search for the saved md5 checksum of all the specified config files
     # and see if the current file is unmodified or not.
index 58d4f23fe1b576cbd7f938e5dbfd58266dc96303..3532babf388f2c8720094d9b4b4b6d0a1cd08480 100755 (executable)
@@ -1218,7 +1218,8 @@ elif vcs == "hg":
        with repoman_popen("hg status --no-status --modified .") as f:
                mychanged = f.readlines()
        mychanged = ["./" + elem.rstrip() for elem in mychanged]
-       mynew = repoman_popen("hg status --no-status --added .").readlines()
+       with repoman_popen("hg status --no-status --added .") as f:
+               mynew = f.readlines()
        mynew = ["./" + elem.rstrip() for elem in mynew]
        if options.if_modified == "y":
                with repoman_popen("hg status --no-status --removed .") as f:
index 3f242679cc1889936da3670f5da2fe84ca016617..27104e17ee86115d32819ac582b527f5aae72329 100644 (file)
@@ -6609,11 +6609,12 @@ class depgraph(object):
                def write_changes(root, changes, file_to_write_to):
                        file_contents = None
                        try:
-                               file_contents = io.open(
+                               with io.open(
                                        _unicode_encode(file_to_write_to,
                                        encoding=_encodings['fs'], errors='strict'),
                                        mode='r', encoding=_encodings['content'],
-                                       errors='replace').readlines()
+                                       errors='replace') as f:
+                                       file_contents = f.readlines()
                        except IOError as e:
                                if e.errno == errno.ENOENT:
                                        file_contents = []
index e9babf13effd9375888ca8ca739c8a7394ac8e30..6a2794fb1c806c74095bc687ab6b7531309d2f60 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 1999-2009 Gentoo Foundation
+# Copyright 1999-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 from portage import os
@@ -11,7 +11,8 @@ if getloadavg is None:
                Raises OSError if the load average was unobtainable.
                """
                try:
-                       loadavg_str = open('/proc/loadavg').readline()
+                       with open('/proc/loadavg') as f:
+                               loadavg_str = f.readline()
                except IOError:
                        # getloadavg() is only supposed to raise OSError, so convert
                        raise OSError('unknown')
index ddb8c70f5343b84c01fb723d2c79b4fcede9ae49..2acf8e3c2e189eb76cfda2ad4743ce238fc81230 100644 (file)
@@ -1,4 +1,4 @@
-# Copyright 2010-2011 Gentoo Foundation
+# Copyright 2010-2013 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
 __all__ = ['deprecated_profile_check']
@@ -32,9 +32,10 @@ def deprecated_profile_check(settings=None):
                        if not os.access(deprecated_profile_file, os.R_OK):
                                return
 
-       dcontent = io.open(_unicode_encode(deprecated_profile_file,
+       with io.open(_unicode_encode(deprecated_profile_file,
                encoding=_encodings['fs'], errors='strict'), 
-               mode='r', encoding=_encodings['content'], errors='replace').readlines()
+               mode='r', encoding=_encodings['content'], errors='replace') as f:
+               dcontent = f.readlines()
        writemsg(colorize("BAD", _("\n!!! Your current profile is "
                "deprecated and not supported anymore.")) + "\n", noiselevel=-1)
        writemsg(colorize("BAD", _("!!! Use eselect profile to update your "
index cb036217ac9687a54711e8871c245e8b6692774a..990090c5f253ea7dccd95708094c33c9407e9a2b 100644 (file)
@@ -380,10 +380,11 @@ def get_commit_message_with_editor(editor, message=None):
                if not (os.WIFEXITED(retval) and os.WEXITSTATUS(retval) == os.EX_OK):
                        return None
                try:
-                       mylines = io.open(_unicode_encode(filename,
+                       with io.open(_unicode_encode(filename,
                                encoding=_encodings['fs'], errors='strict'),
                                mode='r', encoding=_encodings['content'], errors='replace'
-                               ).readlines()
+                               ) as f:
+                               mylines = f.readlines()
                except OSError as e:
                        if e.errno != errno.ENOENT:
                                raise