diff options
author | Zac Medico <zmedico@gentoo.org> | 2011-08-24 20:29:04 -0700 |
---|---|---|
committer | Zac Medico <zmedico@gentoo.org> | 2011-08-24 20:29:04 -0700 |
commit | 2f550d8eb3183b76de7b33df2e9c649cc9b29dda (patch) | |
tree | 01f82062847fb32b4cf9dc47b9e9b4f0e7278914 /pym/portage | |
parent | 148fc6a73f3fa3b53039ee3292e222015e96bc79 (diff) | |
download | portage-2f550d8eb3183b76de7b33df2e9c649cc9b29dda.tar.gz portage-2f550d8eb3183b76de7b33df2e9c649cc9b29dda.tar.bz2 portage-2f550d8eb3183b76de7b33df2e9c649cc9b29dda.zip |
python3.2 fixes: ResourceWarning: unclosed file
Diffstat (limited to 'pym/portage')
-rw-r--r-- | pym/portage/package/ebuild/doebuild.py | 24 | ||||
-rw-r--r-- | pym/portage/package/ebuild/prepare_build_dirs.py | 2 | ||||
-rw-r--r-- | pym/portage/update.py | 7 | ||||
-rw-r--r-- | pym/portage/util/_dyn_libs/PreservedLibsRegistry.py | 10 |
4 files changed, 30 insertions, 13 deletions
diff --git a/pym/portage/package/ebuild/doebuild.py b/pym/portage/package/ebuild/doebuild.py index a710e09e5..aa9218c69 100644 --- a/pym/portage/package/ebuild/doebuild.py +++ b/pym/portage/package/ebuild/doebuild.py @@ -1335,7 +1335,9 @@ def _check_build_log(mysettings, out=None): except EnvironmentError: return + f_real = None if logfile.endswith('.gz'): + f_real = f f = gzip.GzipFile(filename='', mode='rb', fileobj=f) am_maintainer_mode = [] @@ -1440,6 +1442,10 @@ def _check_build_log(mysettings, out=None): msg.extend("\t" + line for line in make_jobserver) _eqawarn(msg) + f.close() + if f_real is not None: + f_real.close() + def _post_src_install_chost_fix(settings): """ It's possible that the ebuild has changed the @@ -1617,15 +1623,19 @@ def _post_src_install_uid_fix(mysettings, out): build_info_dir = os.path.join(mysettings['PORTAGE_BUILDDIR'], 'build-info') - io.open(_unicode_encode(os.path.join(build_info_dir, + f = io.open(_unicode_encode(os.path.join(build_info_dir, 'SIZE'), encoding=_encodings['fs'], errors='strict'), mode='w', encoding=_encodings['repo.content'], - errors='strict').write(_unicode_decode(str(size) + '\n')) + errors='strict') + f.write(_unicode_decode(str(size) + '\n')) + f.close() - io.open(_unicode_encode(os.path.join(build_info_dir, + f = io.open(_unicode_encode(os.path.join(build_info_dir, 'BUILD_TIME'), encoding=_encodings['fs'], errors='strict'), mode='w', encoding=_encodings['repo.content'], - errors='strict').write(_unicode_decode("%.0f\n" % (time.time(),))) + errors='strict') + f.write(_unicode_decode("%.0f\n" % (time.time(),))) + f.close() use = frozenset(mysettings['PORTAGE_USE'].split()) for k in _vdb_use_conditional_keys: @@ -1651,10 +1661,12 @@ def _post_src_install_uid_fix(mysettings, out): except OSError: pass continue - io.open(_unicode_encode(os.path.join(build_info_dir, + f = io.open(_unicode_encode(os.path.join(build_info_dir, k), encoding=_encodings['fs'], errors='strict'), mode='w', encoding=_encodings['repo.content'], - errors='strict').write(_unicode_decode(v + '\n')) + errors='strict') + f.write(_unicode_decode(v + '\n')) + f.close() _reapply_bsdflags_to_image(mysettings) diff --git a/pym/portage/package/ebuild/prepare_build_dirs.py b/pym/portage/package/ebuild/prepare_build_dirs.py index 9104d0e63..12c80ed29 100644 --- a/pym/portage/package/ebuild/prepare_build_dirs.py +++ b/pym/portage/package/ebuild/prepare_build_dirs.py @@ -312,7 +312,7 @@ def _prepare_workdir(mysettings): logdir = normalize_path(mysettings["PORT_LOGDIR"]) logid_path = os.path.join(mysettings["PORTAGE_BUILDDIR"], ".logid") if not os.path.exists(logid_path): - open(_unicode_encode(logid_path), 'w') + open(_unicode_encode(logid_path), 'w').close() logid_time = _unicode_decode(time.strftime("%Y%m%d-%H%M%S", time.gmtime(os.stat(logid_path).st_mtime)), encoding=_encodings['content'], errors='replace') diff --git a/pym/portage/update.py b/pym/portage/update.py index 52ab50645..548d19cef 100644 --- a/pym/portage/update.py +++ b/pym/portage/update.py @@ -132,10 +132,11 @@ def grab_updates(updpath, prev_mtimes=None): if update_data or \ file_path not in prev_mtimes or \ long(prev_mtimes[file_path]) != mystat[stat.ST_MTIME]: - content = io.open(_unicode_encode(file_path, + f = io.open(_unicode_encode(file_path, encoding=_encodings['fs'], errors='strict'), - mode='r', encoding=_encodings['repo.content'], errors='replace' - ).read() + mode='r', encoding=_encodings['repo.content'], errors='replace') + content = f.read() + f.close() update_data.append((file_path, mystat, content)) return update_data diff --git a/pym/portage/util/_dyn_libs/PreservedLibsRegistry.py b/pym/portage/util/_dyn_libs/PreservedLibsRegistry.py index 602cf870a..b916051a1 100644 --- a/pym/portage/util/_dyn_libs/PreservedLibsRegistry.py +++ b/pym/portage/util/_dyn_libs/PreservedLibsRegistry.py @@ -55,10 +55,11 @@ class PreservedLibsRegistry(object): def load(self): """ Reload the registry data from file """ self._data = None + f = None try: - self._data = pickle.load( - open(_unicode_encode(self._filename, - encoding=_encodings['fs'], errors='strict'), 'rb')) + f = open(_unicode_encode(self._filename, + encoding=_encodings['fs'], errors='strict'), 'rb') + self._data = pickle.load(f) except (ValueError, pickle.UnpicklingError) as e: writemsg_level(_("!!! Error loading '%s': %s\n") % \ (self._filename, e), level=logging.ERROR, noiselevel=-1) @@ -69,6 +70,9 @@ class PreservedLibsRegistry(object): raise PermissionDenied(self._filename) else: raise + finally: + if f is not None: + f.close() if self._data is None: self._data = {} self._data_orig = self._data.copy() |