if not (y in ("ChangeLog", "metadata.xml") or y.endswith(".ebuild")):
continue
+ f = None
try:
line = 1
- for l in io.open(_unicode_encode(os.path.join(checkdir, y),
+ f = io.open(_unicode_encode(os.path.join(checkdir, y),
encoding=_encodings['fs'], errors='strict'),
- mode='r', encoding=_encodings['repo.content']):
+ mode='r', encoding=_encodings['repo.content'])
+ for l in f:
line +=1
except UnicodeDecodeError as ue:
stats["file.UTF8"] += 1
if l2 != 0:
s = s[s.rfind("\n") + 1:]
fails["file.UTF8"].append("%s/%s: line %i, just after: '%s'" % (checkdir, y, line, s))
+ finally:
+ if f is not None:
+ f.close()
if vcs in ("git", "hg") and check_ebuild_notadded:
if vcs == "git":
temp_file = open(_unicode_encode(temp_log,
encoding=_encodings['fs'], errors='strict'), 'rb')
- log_file = self._open_log(log_path)
+ log_file, log_file_real = self._open_log(log_path)
for line in temp_file:
log_file.write(line)
temp_file.close()
log_file.close()
+ if log_file_real is not log_file:
+ log_file_real.close()
os.unlink(temp_log)
def _open_log(self, log_path):
f = open(_unicode_encode(log_path,
encoding=_encodings['fs'], errors='strict'),
mode='ab')
+ f_real = f
if log_path.endswith('.gz'):
f = gzip.GzipFile(filename='', mode='ab', fileobj=f)
- return f
+ return (f, f_real)
def _die_hooks(self):
self.returncode = None
f = open(_unicode_encode(log_path,
encoding=_encodings['fs'], errors='strict'),
mode='ab')
+ f_real = f
except IOError as e:
if e.errno not in (errno.ENOENT, errno.ESTALE):
raise
f.write(_unicode_encode(msg))
f.close()
+ if f_real is not f:
+ f_real.close()
_can_poll_device = None
"path_lookup", "pre_exec")
__slots__ = ("args",) + \
- _spawn_kwarg_names + ("_selinux_type",)
+ _spawn_kwarg_names + ("_log_file_real", "_selinux_type",)
_file_names = ("log", "process", "stdout")
_files_dict = slot_dict_class(_file_names, prefix="")
files.log = open(_unicode_encode(logfile,
encoding=_encodings['fs'], errors='strict'), mode='ab')
if logfile.endswith('.gz'):
+ self._log_file_real = files.log
files.log = gzip.GzipFile(filename='', mode='ab',
fileobj=files.log)
self._unregister_if_appropriate(event)
+ def _unregister(self):
+ super(SpawnProcess, self)._unregister()
+ if self._log_file_real is not None:
+ # Avoid "ResourceWarning: unclosed file" since python 3.2.
+ self._log_file_real.close()
+ self._log_file_real = None
logentries[msgfunction] = []
lastmsgtype = None
msgcontent = []
- for l in io.open(_unicode_encode(filename,
+ f = io.open(_unicode_encode(filename,
encoding=_encodings['fs'], errors='strict'),
- mode='r', encoding=_encodings['repo.content'], errors='replace'):
+ mode='r', encoding=_encodings['repo.content'], errors='replace')
+ for l in f:
if not l:
continue
try:
logentries[msgfunction].append((lastmsgtype, msgcontent))
msgcontent = [msg]
lastmsgtype = msgtype
+ f.close()
if msgcontent:
logentries[msgfunction].append((lastmsgtype, msgcontent))
background = settings.get("PORTAGE_BACKGROUND") == "1"
log_path = settings.get("PORTAGE_LOG_FILE")
log_file = None
+ log_file_real = None
if background and log_path is not None:
try:
log_file = open(_unicode_encode(log_path,
encoding=_encodings['fs'], errors='strict'), mode='ab')
+ log_file_real = log_file
except IOError:
def write(msg):
pass
finally:
if log_file is not None:
log_file.close()
+ if log_file_real is not log_file:
+ log_file_real.close()
def _prepare_features_dirs(mysettings):
return (None, str(details))
except IOError as details:
return (None, str(details))
+ finally:
+ f.close()
lines = [l.strip() for l in lines]