Openembedded Core Discussions
 help / color / mirror / Atom feed
From: Paul Eggleton <paul.eggleton@linux.intel.com>
To: openembedded-core@lists.openembedded.org
Subject: [PATCH] classes/buildhistory: write out files in UTF-8 format
Date: Thu,  6 Feb 2014 11:02:55 +0000	[thread overview]
Message-ID: <1391684575-14359-1-git-send-email-paul.eggleton@linux.intel.com> (raw)

If the package information contained unicode characters (for example, in
the package file listing) then writing them out as ASCII would fail, so
write them out using codecs.open() instead of open() using UTF-8. This
fixes ca-certificates failing in do_packagedata when buildhistory is
enabled.

Signed-off-by: Paul Eggleton <paul.eggleton@linux.intel.com>
---
 meta/classes/buildhistory.bbclass | 46 +++++++++++++++++++++------------------
 1 file changed, 25 insertions(+), 21 deletions(-)

diff --git a/meta/classes/buildhistory.bbclass b/meta/classes/buildhistory.bbclass
index 6b097ea..6d1e74a 100644
--- a/meta/classes/buildhistory.bbclass
+++ b/meta/classes/buildhistory.bbclass
@@ -242,21 +242,25 @@ python buildhistory_emit_pkghistory() {
 
 
 def write_recipehistory(rcpinfo, d):
+    import codecs
+
     bb.debug(2, "Writing recipe history")
 
     pkghistdir = d.getVar('BUILDHISTORY_DIR_PACKAGE', True)
 
     infofile = os.path.join(pkghistdir, "latest")
-    with open(infofile, "w") as f:
+    with codecs.open(infofile, "w", encoding='utf8') as f:
         if rcpinfo.pe != "0":
-            f.write("PE = %s\n" %  rcpinfo.pe)
-        f.write("PV = %s\n" %  rcpinfo.pv)
-        f.write("PR = %s\n" %  rcpinfo.pr)
-        f.write("DEPENDS = %s\n" %  rcpinfo.depends)
-        f.write("PACKAGES = %s\n" %  rcpinfo.packages)
+            f.write(u"PE = %s\n" %  rcpinfo.pe)
+        f.write(u"PV = %s\n" %  rcpinfo.pv)
+        f.write(u"PR = %s\n" %  rcpinfo.pr)
+        f.write(u"DEPENDS = %s\n" %  rcpinfo.depends)
+        f.write(u"PACKAGES = %s\n" %  rcpinfo.packages)
 
 
 def write_pkghistory(pkginfo, d):
+    import codecs
+
     bb.debug(2, "Writing package history for package %s" % pkginfo.name)
 
     pkghistdir = d.getVar('BUILDHISTORY_DIR_PACKAGE', True)
@@ -266,11 +270,11 @@ def write_pkghistory(pkginfo, d):
         bb.utils.mkdirhier(pkgpath)
 
     infofile = os.path.join(pkgpath, "latest")
-    with open(infofile, "w") as f:
+    with codecs.open(infofile, "w", encoding='utf8') as f:
         if pkginfo.pe != "0":
-            f.write("PE = %s\n" %  pkginfo.pe)
-        f.write("PV = %s\n" %  pkginfo.pv)
-        f.write("PR = %s\n" %  pkginfo.pr)
+            f.write(u"PE = %s\n" %  pkginfo.pe)
+        f.write(u"PV = %s\n" %  pkginfo.pv)
+        f.write(u"PR = %s\n" %  pkginfo.pr)
 
         pkgvars = {}
         pkgvars['PKG'] = pkginfo.pkg if pkginfo.pkg != pkginfo.name else ''
@@ -280,26 +284,26 @@ def write_pkghistory(pkginfo, d):
         for pkgvar in pkgvars:
             val = pkgvars[pkgvar]
             if val:
-                f.write("%s = %s\n" % (pkgvar, val))
+                f.write(u"%s = %s\n" % (pkgvar, val))
 
-        f.write("RPROVIDES = %s\n" %  pkginfo.rprovides)
-        f.write("RDEPENDS = %s\n" %  pkginfo.rdepends)
-        f.write("RRECOMMENDS = %s\n" %  pkginfo.rrecommends)
+        f.write(u"RPROVIDES = %s\n" %  pkginfo.rprovides)
+        f.write(u"RDEPENDS = %s\n" %  pkginfo.rdepends)
+        f.write(u"RRECOMMENDS = %s\n" %  pkginfo.rrecommends)
         if pkginfo.rsuggests:
-            f.write("RSUGGESTS = %s\n" %  pkginfo.rsuggests)
+            f.write(u"RSUGGESTS = %s\n" %  pkginfo.rsuggests)
         if pkginfo.rreplaces:
-            f.write("RREPLACES = %s\n" %  pkginfo.rreplaces)
+            f.write(u"RREPLACES = %s\n" %  pkginfo.rreplaces)
         if pkginfo.rconflicts:
-            f.write("RCONFLICTS = %s\n" %  pkginfo.rconflicts)
-        f.write("PKGSIZE = %d\n" %  pkginfo.size)
-        f.write("FILES = %s\n" %  pkginfo.files)
-        f.write("FILELIST = %s\n" %  pkginfo.filelist)
+            f.write(u"RCONFLICTS = %s\n" %  pkginfo.rconflicts)
+        f.write(u"PKGSIZE = %d\n" %  pkginfo.size)
+        f.write(u"FILES = %s\n" %  pkginfo.files)
+        f.write(u"FILELIST = %s\n" %  pkginfo.filelist)
 
     for filevar in pkginfo.filevars:
         filevarpath = os.path.join(pkgpath, "latest.%s" % filevar)
         val = pkginfo.filevars[filevar]
         if val:
-            with open(filevarpath, "w") as f:
+            with codecs.open(filevarpath, "w", encoding='utf8') as f:
                 f.write(val)
         else:
             if os.path.exists(filevarpath):
-- 
1.8.5.3



                 reply	other threads:[~2014-02-06 11:03 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1391684575-14359-1-git-send-email-paul.eggleton@linux.intel.com \
    --to=paul.eggleton@linux.intel.com \
    --cc=openembedded-core@lists.openembedded.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox