quote = var_assign_match.group(3)
filter_this = pattern.match(var_assign_match.group(2)) \
is not None
- if quote is not None and not have_end_quote(quote, line):
+ # Exclude the start quote when searching for the end quote,
+ # to ensure that the start quote is not misidentified as the
+ # end quote (happens if there is a newline immediately after
+ # the start quote).
+ if quote is not None and not \
+ have_end_quote(quote, line[var_assign_match.end(2)+2:]):
multi_line_quote = quote
multi_line_quote_filter = filter_this
if not filter_this:
ftype = []
for x in list:
if not isinstance(x, unicode):
- x = unicode(x, errors='replace')
+ x = unicode(x, encoding='utf_8', errors='replace')
try:
if followSymlinks:
pathstat = os.stat(mypath+"/"+x)
continue
for x in file_list:
if not isinstance(x, unicode):
- x = unicode(x, errors='replace')
+ x = unicode(x, encoding='utf_8', errors='replace')
pf = None
if glep55:
returnme = []
for x in dir_list:
if not isinstance(x, unicode):
- x = unicode(x, errors='replace')
+ x = unicode(x, encoding='utf_8', errors='replace')
if self._excluded_dirs.match(x) is not None:
continue
ps = pkgsplit(x)
def listdir(p, **kwargs):
try:
return [isinstance(x, unicode) and x or \
- unicode(x, errors='replace') for x in os.listdir(p) \
+ unicode(x, encoding='utf_8', errors='replace') \
+ for x in os.listdir(p) \
if os.path.isdir(os.path.join(p, x))]
except EnvironmentError, e:
if e.errno == PermissionDenied.errno:
from portage.const import EBUILD_PHASES
from portage.localization import _
+import codecs
import os
import sys
logentries[msgfunction] = []
lastmsgtype = None
msgcontent = []
- for l in open(filename):
+ for l in codecs.open(filename, mode='r',
+ encoding='utf_8', errors='replace'):
if not l:
continue
try:
from portage.exception import PortageException
from portage.localization import _
from portage.util import writemsg
-from email.MIMEText import MIMEText as TextMessage
_items = {}
def process(mysettings, key, logentries, fulltext):
# Distributed under the terms of the GNU General Public License v2
# $Id$
+import codecs
import os, time
from portage.data import portage_uid, portage_gid
from portage.util import ensure_dirs
ensure_dirs(elogdir, uid=portage_uid, gid=portage_gid, mode=02770)
elogfilename = elogdir+"/"+path+":"+time.strftime("%Y%m%d-%H%M%S", time.gmtime(time.time()))+".log"
- elogfile = open(elogfilename, "w")
+ elogfile = codecs.open(elogfilename, mode='w',
+ encoding='utf_8', errors='replace')
elogfile.write(fulltext)
elogfile.close()
# Distributed under the terms of the GNU General Public License v2
# $Id$
+import codecs
import os, time
from portage.data import portage_uid, portage_gid
from portage.localization import _
# TODO: Locking
elogfilename = elogdir+"/summary.log"
- elogfile = open(elogfilename, "a")
+ elogfile = codecs.open(elogfilename, mode='a',
+ encoding='utf_8', errors='replace')
apply_permissions(elogfilename, mode=060, mask=0)
elogfile.write(_(">>> Messages generated by process %(pid)d on %(time)s for package %(pkg)s:\n\n") %
{"pid": os.getpid(), "time": time.strftime("%Y-%m-%d %H:%M:%S %Z", time.localtime(time.time())), "pkg": key})
# Distributed under the terms of the GNU General Public License v2
# $Id$
+import sys
import syslog
from portage.const import EBUILD_PHASES
+_pri = {
+ "INFO" : syslog.LOG_INFO,
+ "WARN" : syslog.LOG_WARNING,
+ "ERROR" : syslog.LOG_ERR,
+ "LOG" : syslog.LOG_NOTICE,
+ "QA" : syslog.LOG_WARNING
+}
+
def process(mysettings, key, logentries, fulltext):
syslog.openlog("portage", syslog.LOG_ERR | syslog.LOG_WARNING | syslog.LOG_INFO | syslog.LOG_NOTICE, syslog.LOG_LOCAL5)
for phase in EBUILD_PHASES:
if not phase in logentries:
continue
for msgtype,msgcontent in logentries[phase]:
- pri = {"INFO": syslog.LOG_INFO,
- "WARN": syslog.LOG_WARNING,
- "ERROR": syslog.LOG_ERR,
- "LOG": syslog.LOG_NOTICE,
- "QA": syslog.LOG_WARNING}
msgtext = "".join(msgcontent)
- syslog.syslog(pri[msgtype], "%s: %s: %s" % (key, phase, msgtext))
+ msgtext = "%s: %s: %s" % (key, phase, msgtext)
+ if sys.hexversion < 0x3000000 and isinstance(msgtext, unicode):
+ # Avoid TypeError from syslog.syslog()
+ msgtext = msgtext.encode('utf_8', 'replace')
+ syslog.syslog(_pri[msgtype], msgtext)
syslog.closelog()
from email.header import Header
def create_message(sender, recipient, subject, body, attachments=None):
+
+ if sys.hexversion < 0x3000000:
+ if isinstance(sender, unicode):
+ sender = sender.encode('utf_8', 'replace')
+ if isinstance(recipient, unicode):
+ recipient = recipient.encode('utf_8', 'replace')
+ if isinstance(subject, unicode):
+ subject = subject.encode('utf_8', 'replace')
+ if isinstance(body, unicode):
+ body = body.encode('utf_8', 'replace')
+
if attachments == None:
mymessage = TextMessage(body)
else:
if isinstance(x, BaseMessage):
mymessage.attach(x)
elif isinstance(x, basestring):
+ if sys.hexversion < 0x3000000 and isinstance(x, unicode):
+ x = x.encode('utf_8', 'replace')
mymessage.attach(TextMessage(x))
else:
raise portage.exception.PortageException("Can't handle type of attachment: %s" % type(x))
myrecipient = mysettings["PORTAGE_ELOG_MAILURI"]
myfrom = message.get("From")
-
+
+ if sys.hexversion < 0x3000000:
+ if isinstance(myrecipient, unicode):
+ myrecipient = myrecipient.encode('utf_8', 'replace')
+ if isinstance(mymailhost, unicode):
+ mymailhost = mymailhost.encode('utf_8', 'replace')
+ if isinstance(mymailport, unicode):
+ mymailport = mymailport.encode('utf_8', 'replace')
+ if isinstance(myfrom, unicode):
+ myfrom = myfrom.encode('utf_8', 'replace')
+ if isinstance(mymailuser, unicode):
+ mymailuser = mymailuser.encode('utf_8', 'replace')
+ if isinstance(mymailpasswd, unicode):
+ mymailpasswd = mymailpasswd.encode('utf_8', 'replace')
+
# user wants to use a sendmail binary instead of smtp
if mymailhost[0] == os.sep and os.path.exists(mymailhost):
fd = os.popen(mymailhost+" -f "+myfrom+" "+myrecipient, "w")
sys.stdout.flush()
sys.stderr.flush()
+ def _write(self, f, s):
+ if sys.hexversion < 0x3000000 and isinstance(s, unicode):
+ # avoid potential UnicodeEncodeError
+ s = s.encode('utf_8', 'replace')
+ f.write(s)
+ f.flush()
+
def __eend(self, caller, errno, msg):
if errno == 0:
status_brackets = colorize("BRACKET", "[ ") + colorize("GOOD", "ok") + colorize("BRACKET", " ]")
self.__last_e_len = 0
if not self.quiet:
out = sys.stdout
- out.write("%*s%s\n" % ((self.term_columns - self.__last_e_len - 6),
+ self._write(out,
+ "%*s%s\n" % ((self.term_columns - self.__last_e_len - 6),
"", status_brackets))
- out.flush()
def ebegin(self, msg):
"""
out = sys.stderr
if not self.quiet:
if self.__last_e_cmd == "ebegin":
- out.write("\n")
- out.write(colorize("BAD", " * ") + msg + "\n")
- out.flush()
+ self._write(out, "\n")
+ self._write(out, colorize("BAD", " * ") + msg + "\n")
self.__last_e_cmd = "eerror"
def einfo(self, msg):
out = sys.stdout
if not self.quiet:
if self.__last_e_cmd == "ebegin":
- out.write("\n")
- out.write(colorize("GOOD", " * ") + msg + "\n")
- out.flush()
+ self._write(out, "\n")
+ self._write(out, colorize("GOOD", " * ") + msg + "\n")
self.__last_e_cmd = "einfo"
def einfon(self, msg):
out = sys.stdout
if not self.quiet:
if self.__last_e_cmd == "ebegin":
- out.write("\n")
- out.write(colorize("GOOD", " * ") + msg)
- out.flush()
+ self._write(out, "\n")
+ self._write(out, colorize("GOOD", " * ") + msg)
self.__last_e_cmd = "einfon"
def ewarn(self, msg):
out = sys.stderr
if not self.quiet:
if self.__last_e_cmd == "ebegin":
- out.write("\n")
- out.write(colorize("WARN", " * ") + msg + "\n")
- out.flush()
+ self._write(out, "\n")
+ self._write(out, colorize("WARN", " * ") + msg + "\n")
self.__last_e_cmd = "ewarn"
def ewend(self, errno, *msg):
pipe = subprocess.Popen(self._command, stdout=subprocess.PIPE, shell=True)
stdout, stderr = pipe.communicate()
if pipe.wait() == os.EX_OK:
- self._setAtoms(unicode(stdout, errors='replace').splitlines())
+ self._setAtoms(unicode(stdout,
+ encoding='utf_8', errors='replace').splitlines())
def singleBuilder(self, options, settings, trees):
if not "command" in options: