diff options
Diffstat (limited to 'pym/portage/elog')
-rw-r--r-- | pym/portage/elog/__init__.py | 3 | ||||
-rw-r--r-- | pym/portage/elog/mod_echo.py | 3 | ||||
-rw-r--r-- | pym/portage/elog/mod_save.py | 24 | ||||
-rw-r--r-- | pym/portage/elog/mod_save_summary.py | 40 | ||||
-rw-r--r-- | pym/portage/elog/mod_syslog.py | 13 |
5 files changed, 58 insertions, 25 deletions
diff --git a/pym/portage/elog/__init__.py b/pym/portage/elog/__init__.py index 33dac178d..cc086123f 100644 --- a/pym/portage/elog/__init__.py +++ b/pym/portage/elog/__init__.py @@ -1,9 +1,10 @@ # elog/__init__.py - elog core functions -# Copyright 2006-2011 Gentoo Foundation +# Copyright 2006-2014 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 import sys if sys.hexversion >= 0x3000000: + # pylint: disable=W0622 basestring = str import portage diff --git a/pym/portage/elog/mod_echo.py b/pym/portage/elog/mod_echo.py index 59117beb3..f9cc53788 100644 --- a/pym/portage/elog/mod_echo.py +++ b/pym/portage/elog/mod_echo.py @@ -1,5 +1,5 @@ # elog/mod_echo.py - elog dispatch module -# Copyright 2007 Gentoo Foundation +# Copyright 2007-2014 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 from __future__ import print_function @@ -10,6 +10,7 @@ from portage.const import EBUILD_PHASES from portage.localization import _ if sys.hexversion >= 0x3000000: + # pylint: disable=W0622 basestring = str _items = [] diff --git a/pym/portage/elog/mod_save.py b/pym/portage/elog/mod_save.py index c69f4a3cf..7b1cd46a8 100644 --- a/pym/portage/elog/mod_save.py +++ b/pym/portage/elog/mod_save.py @@ -1,7 +1,8 @@ # elog/mod_save.py - elog dispatch module -# Copyright 2006-2011 Gentoo Foundation +# Copyright 2006-2012 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 +import errno import io import time import portage @@ -47,11 +48,22 @@ def process(mysettings, key, logentries, fulltext): elogfilename = os.path.join(log_subdir, cat + ':' + elogfilename) _ensure_log_subdirs(logdir, log_subdir) - elogfile = io.open(_unicode_encode(elogfilename, - encoding=_encodings['fs'], errors='strict'), - mode='w', encoding=_encodings['content'], errors='backslashreplace') - elogfile.write(_unicode_decode(fulltext)) - elogfile.close() + try: + with io.open(_unicode_encode(elogfilename, + encoding=_encodings['fs'], errors='strict'), mode='w', + encoding=_encodings['content'], + errors='backslashreplace') as elogfile: + elogfile.write(_unicode_decode(fulltext)) + except IOError as e: + func_call = "open('%s', 'w')" % elogfilename + if e.errno == errno.EACCES: + raise portage.exception.PermissionDenied(func_call) + elif e.errno == errno.EPERM: + raise portage.exception.OperationNotPermitted(func_call) + elif e.errno == errno.EROFS: + raise portage.exception.ReadOnlyFileSystem(func_call) + else: + raise # Copy group permission bits from parent directory. elogdir_st = os.stat(log_subdir) diff --git a/pym/portage/elog/mod_save_summary.py b/pym/portage/elog/mod_save_summary.py index 347f66e6e..786f89454 100644 --- a/pym/portage/elog/mod_save_summary.py +++ b/pym/portage/elog/mod_save_summary.py @@ -1,8 +1,12 @@ # elog/mod_save_summary.py - elog dispatch module -# Copyright 2006-2011 Gentoo Foundation +# Copyright 2006-2013 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 +from __future__ import unicode_literals + +import errno import io +import sys import time import portage from portage import os @@ -37,9 +41,21 @@ def process(mysettings, key, logentries, fulltext): # TODO: Locking elogfilename = elogdir+"/summary.log" - elogfile = io.open(_unicode_encode(elogfilename, - encoding=_encodings['fs'], errors='strict'), - mode='a', encoding=_encodings['content'], errors='backslashreplace') + try: + elogfile = io.open(_unicode_encode(elogfilename, + encoding=_encodings['fs'], errors='strict'), + mode='a', encoding=_encodings['content'], + errors='backslashreplace') + except IOError as e: + func_call = "open('%s', 'a')" % elogfilename + if e.errno == errno.EACCES: + raise portage.exception.PermissionDenied(func_call) + elif e.errno == errno.EPERM: + raise portage.exception.OperationNotPermitted(func_call) + elif e.errno == errno.EROFS: + raise portage.exception.ReadOnlyFileSystem(func_call) + else: + raise # Copy group permission bits from parent directory. elogdir_st = os.stat(elogdir) @@ -58,17 +74,19 @@ def process(mysettings, key, logentries, fulltext): apply_permissions(elogfilename, uid=logfile_uid, gid=elogdir_gid, mode=elogdir_grp_mode, mask=0) - time_str = time.strftime("%Y-%m-%d %H:%M:%S %Z", - time.localtime(time.time())) - # Avoid potential UnicodeDecodeError later. + time_fmt = "%Y-%m-%d %H:%M:%S %Z" + if sys.hexversion < 0x3000000: + time_fmt = _unicode_encode(time_fmt) + time_str = time.strftime(time_fmt, time.localtime(time.time())) + # Avoid potential UnicodeDecodeError in Python 2, since strftime + # returns bytes in Python 2, and %Z may contain non-ascii chars. time_str = _unicode_decode(time_str, encoding=_encodings['content'], errors='replace') - elogfile.write(_unicode_decode( - _(">>> Messages generated by process " + + elogfile.write(_(">>> Messages generated by process " "%(pid)d on %(time)s for package %(pkg)s:\n\n") % - {"pid": os.getpid(), "time": time_str, "pkg": key})) + {"pid": os.getpid(), "time": time_str, "pkg": key}) elogfile.write(_unicode_decode(fulltext)) - elogfile.write(_unicode_decode("\n")) + elogfile.write("\n") elogfile.close() return elogfilename diff --git a/pym/portage/elog/mod_syslog.py b/pym/portage/elog/mod_syslog.py index c8bf44172..8b26ffa1e 100644 --- a/pym/portage/elog/mod_syslog.py +++ b/pym/portage/elog/mod_syslog.py @@ -1,5 +1,5 @@ # elog/mod_syslog.py - elog dispatch module -# Copyright 2006-2011 Gentoo Foundation +# Copyright 2006-2014 Gentoo Foundation # Distributed under the terms of the GNU General Public License v2 import sys @@ -8,12 +8,13 @@ from portage.const import EBUILD_PHASES from portage import _encodings if sys.hexversion >= 0x3000000: + # pylint: disable=W0622 basestring = str _pri = { - "INFO" : syslog.LOG_INFO, - "WARN" : syslog.LOG_WARNING, - "ERROR" : syslog.LOG_ERR, + "INFO" : syslog.LOG_INFO, + "WARN" : syslog.LOG_WARNING, + "ERROR" : syslog.LOG_ERR, "LOG" : syslog.LOG_NOTICE, "QA" : syslog.LOG_WARNING } @@ -23,14 +24,14 @@ def process(mysettings, key, logentries, fulltext): for phase in EBUILD_PHASES: if not phase in logentries: continue - for msgtype,msgcontent in logentries[phase]: + for msgtype, msgcontent in logentries[phase]: if isinstance(msgcontent, basestring): msgcontent = [msgcontent] for line in msgcontent: line = "%s: %s: %s" % (key, phase, line) if sys.hexversion < 0x3000000 and not isinstance(line, bytes): # Avoid TypeError from syslog.syslog() - line = line.encode(_encodings['content'], + line = line.encode(_encodings['content'], 'backslashreplace') syslog.syslog(_pri[msgtype], line.rstrip("\n")) syslog.closelog() |