diff --git a/lib/entropy/misc.py b/lib/entropy/misc.py index bb4a94af8..d216bd693 100644 --- a/lib/entropy/misc.py +++ b/lib/entropy/misc.py @@ -35,7 +35,8 @@ import threading from collections import deque from entropy.const import etpConst, const_isunicode, \ - const_isfileobj, const_convert_log_level, const_setup_file + const_isfileobj, const_convert_log_level, const_setup_file, \ + const_convert_to_unicode from entropy.exceptions import EntropyException import entropy.tools @@ -1665,6 +1666,24 @@ class FastRSS(object): const_setup_file(self.__file, etpConst['entropygid'], 0o664) +class FileobjCompatBuffer: + + """ + Compatibility shim for file object with the buffer attribute. + To be used with classes whose write method expect strings. + """ + + def __init__(self, parent): + self._parent = parent + + def write(self, msg): + msg_str = const_convert_to_unicode(msg) + self._parent.write(msg_str) + + def flush(self): + self._parent.flush() + + class LogFile: """ Entropy simple logging interface, works as file object """ @@ -1715,6 +1734,9 @@ class LogFile: LogFile.DATE_FORMAT)) self.__logger.addHandler(self.__handler) + if const_is_python3(): + self.buffer = FileobjCompatBuffer(self) + def __enter__(self): """ Just return self, configuration is done in __init__ diff --git a/rigo/RigoDaemon/app/RigoDaemon_app.py b/rigo/RigoDaemon/app/RigoDaemon_app.py index 39c4aeefe..33b45e5b8 100755 --- a/rigo/RigoDaemon/app/RigoDaemon_app.py +++ b/rigo/RigoDaemon/app/RigoDaemon_app.py @@ -79,7 +79,7 @@ from entropy.exceptions import DependenciesNotFound, \ EntropyPackageException, InterruptError, RepositoryError from entropy.i18n import _ from entropy.misc import LogFile, ParallelTask, TimeScheduled, \ - ReadersWritersSemaphore + ReadersWritersSemaphore, FileobjCompatBuffer from entropy.fetchers import UrlFetcher, MultipleUrlFetcher from entropy.output import TextInterface, purple, teal from entropy.client.interfaces import Client @@ -340,6 +340,10 @@ class FakeOutFile(object): self._app_mgmt_mutex = app_mgmt_mutex self._app_mgmt_notes = app_mgmt_notes self._rfd, self._wfd = os.pipe() + + if const_is_python3(): + self.buffer = FileobjCompatBuffer(self) + task = ParallelTask(self._pusher) task.name = "FakeOutFilePusher" task.daemon = True