bitbake: cooker: encode event objects to base64

pickle converts python objects into the binary form that can't be
decoded to text and therefore can't be converted to JSON format.

Attempt to convert event objects raises this error:
TypeError:
    b'\x80\x03cbb.runqueue\nrunQueueTaskSkipped\nq\x00)...
    is not JSON serializable

Encoded pickled event objects to base64 to be able to convert data
structure to JSON.

[YOCTO #9803]

(Bitbake rev: f18055237e6084f90f6221442e3ba021dcc59c50)

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Ed Bartosh 2016-06-20 14:00:49 +03:00 committed by Richard Purdie
parent 3e7edc303c
commit e28b36e1e8
1 changed files with 4 additions and 1 deletions

View File

@ -44,6 +44,7 @@ import prserv.serv
import pyinotify
import json
import pickle
import codecs
logger = logging.getLogger("BitBake")
collectlog = logging.getLogger("BitBake.Collection")
@ -143,7 +144,9 @@ class EventLogWriteHandler:
def write_event(self, event):
with open(self.eventfile, "a") as f:
try:
f.write("%s\n" % json.dumps({"class":event.__module__ + "." + event.__class__.__name__, "vars":json.dumps(pickle.dumps(event)) }))
str_event = codecs.encode(pickle.dumps(event), 'base64').decode('utf-8')
f.write("%s\n" % json.dumps({"class": event.__module__ + "." + event.__class__.__name__,
"vars": str_event}))
except Exception as e:
import traceback
print(e, traceback.format_exc())