From: Arfrever Frehtes Taifersar Arahesis Date: Sun, 10 Feb 2013 03:47:21 +0000 (+0100) Subject: Fix some ResourceWarnings. X-Git-Tag: v2.2.0_alpha162~16 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=e993a6e34c564211242cbaa76b082f95ec713097;p=portage.git Fix some ResourceWarnings. --- diff --git a/bin/archive-conf b/bin/archive-conf index 2c10884ea..42b62748e 100755 --- a/bin/archive-conf +++ b/bin/archive-conf @@ -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. diff --git a/bin/repoman b/bin/repoman index 58d4f23fe..3532babf3 100755 --- a/bin/repoman +++ b/bin/repoman @@ -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: diff --git a/pym/_emerge/depgraph.py b/pym/_emerge/depgraph.py index 3f242679c..27104e17e 100644 --- a/pym/_emerge/depgraph.py +++ b/pym/_emerge/depgraph.py @@ -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 = [] diff --git a/pym/_emerge/getloadavg.py b/pym/_emerge/getloadavg.py index e9babf13e..6a2794fb1 100644 --- a/pym/_emerge/getloadavg.py +++ b/pym/_emerge/getloadavg.py @@ -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') diff --git a/pym/portage/package/ebuild/deprecated_profile_check.py b/pym/portage/package/ebuild/deprecated_profile_check.py index ddb8c70f5..2acf8e3c2 100644 --- a/pym/portage/package/ebuild/deprecated_profile_check.py +++ b/pym/portage/package/ebuild/deprecated_profile_check.py @@ -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 " diff --git a/pym/repoman/utilities.py b/pym/repoman/utilities.py index cb036217a..990090c5f 100644 --- a/pym/repoman/utilities.py +++ b/pym/repoman/utilities.py @@ -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