[gnome-continuous-yocto/gnomeostree-3.28-rocko: 1005/8267] bitbake: cooker: clean up EvertWriter
- From: Emmanuele Bassi <ebassi src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-continuous-yocto/gnomeostree-3.28-rocko: 1005/8267] bitbake: cooker: clean up EvertWriter
- Date: Sat, 16 Dec 2017 21:13:17 +0000 (UTC)
commit 95f6e7bd0f7188f59e66e1769799e44a123b638b
Author: Ed Bartosh <ed bartosh linux intel com>
Date: Mon Jun 20 14:00:52 2016 +0300
bitbake: cooker: clean up EvertWriter
Restructured EventWriter code to make it more readable:
- got rid of init_file method as it's called only once
- renamed exception variable e -> err
- renamed event variable e -> evt
- simplified main 'if' structure of send method
(Bitbake rev: 31977e7bb98f676197c6cee66f6ab4c12d4dcbde)
Signed-off-by: Ed Bartosh <ed bartosh linux intel com>
Signed-off-by: Richard Purdie <richard purdie linuxfoundation org>
bitbake/lib/bb/cooker.py | 33 +++++++++++++--------------------
1 files changed, 13 insertions(+), 20 deletions(-)
---
diff --git a/bitbake/lib/bb/cooker.py b/bitbake/lib/bb/cooker.py
index 3e4f8d8..9bd3460 100644
--- a/bitbake/lib/bb/cooker.py
+++ b/bitbake/lib/bb/cooker.py
@@ -124,46 +124,39 @@ class EventWriter:
self.eventfile = eventfile
self.event_queue = []
- def init_file(self):
- # write current configuration data
- with open(eventfile, "w") as f:
- f.write("%s\n" % json.dumps({ "allvariables" : self.cooker.getAllKeysWithFlags(["doc",
"func"])}))
-
def write_event(self, event):
with open(self.eventfile, "a") as f:
try:
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:
+ except Exception as err:
import traceback
- print(e, traceback.format_exc())
-
+ print(err, traceback.format_exc())
def send(self, event):
- event_class = event.__module__ + "." + event.__class__.__name__
+ if self.file_inited:
+ # we have the file, just write the event
+ self.write_event(event)
+ else:
+ # init on bb.event.BuildStarted
+ name = "%s.%s" % (event.__module__, event.__class__.__name__)
+ if name == "bb.event.BuildStarted":
+ with open(self.eventfile, "w") as f:
+ f.write("%s\n" % json.dumps({ "allvariables" : self.cooker.getAllKeysWithFlags(["doc",
"func"])}))
- # init on bb.event.BuildStarted
- if self.file_inited is None:
- if event_class == "bb.event.BuildStarted":
- self.init_file()
self.file_inited = True
# write pending events
- for e in self.event_queue:
- self.write_event(e)
+ for evt in self.event_queue:
+ self.write_event(evt)
# also write the current event
self.write_event(event)
-
else:
# queue all events until the file is inited
self.event_queue.append(event)
- else:
- # we have the file, just write the event
- self.write_event(event)
-
#============================================================================#
# BBCooker
#============================================================================#
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]