[oe-commits] [bitbake] 02/06: cooker: move EventLogWriteHandler to the top module level

git at git.openembedded.org git at git.openembedded.org
Mon Jun 20 16:24:58 UTC 2016


rpurdie pushed a commit to branch master
in repository bitbake.

commit d3ad8eee850ec2df54aa09fae44cc7e69c12f32a
Author: Ed Bartosh <ed.bartosh at linux.intel.com>
AuthorDate: Mon Jun 20 14:00:48 2016 +0300

    cooker: move EventLogWriteHandler to the top module level
    
    EventLogWriteHandler object was created and used in
    BBCooker.initConfigurationData.
    This causes creation of multiple EventLogWriteHandler objects
    and results in duplicated entries in the output event file
    as BBCooker.initConfigurationData is called multiple times.
    
    Added eventlogfile parameter to EventLogWriteHandler to avoid using
    global variable DEFAULT_EVENTFILE.
    Moved EventLogWriteHandler to the module level.
    Created EventLogWriteHandler object in BBCooker.__init__ to ensure that only
    one handler object is created.
    
    Signed-off-by: Ed Bartosh <ed.bartosh at linux.intel.com>
    Signed-off-by: Richard Purdie <richard.purdie at linuxfoundation.org>
---
 lib/bb/cooker.py | 126 ++++++++++++++++++++++++++++---------------------------
 1 file changed, 64 insertions(+), 62 deletions(-)

diff --git a/lib/bb/cooker.py b/lib/bb/cooker.py
index 60ee5d7..b2cf0cd 100644
--- a/lib/bb/cooker.py
+++ b/lib/bb/cooker.py
@@ -42,6 +42,8 @@ import subprocess
 import errno
 import prserv.serv
 import pyinotify
+import json
+import pickle
 
 logger      = logging.getLogger("BitBake")
 collectlog  = logging.getLogger("BitBake.Collection")
@@ -114,6 +116,63 @@ class CookerFeatures(object):
         return next(self._features)
 
 
+class EventLogWriteHandler:
+
+    def __init__(self, cooker, eventfile):
+        # set our handler's event processor
+        self.event = self.EventWriter(cooker, eventfile)
+
+    class EventWriter:
+        def __init__(self, cooker, eventfile):
+            self.file_inited = None
+            self.cooker = cooker
+            self.eventfile = eventfile
+            self.event_queue = []
+
+        def init_file(self):
+            try:
+                # delete the old log
+                os.remove(self.eventfile)
+            except:
+                pass
+
+            # 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:
+                    f.write("%s\n" % json.dumps({"class":event.__module__ + "." + event.__class__.__name__, "vars":json.dumps(pickle.dumps(event)) }))
+                except Exception as e:
+                    import traceback
+                    print(e, traceback.format_exc())
+
+
+        def send(self, event):
+            event_class = event.__module__ + "." + event.__class__.__name__
+
+            # 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)
+
+                    # 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
 #============================================================================#
@@ -151,6 +210,11 @@ class BBCooker:
 
         self.initConfigurationData()
 
+        # we log all events to a file if so directed
+        if self.configuration.writeeventlog:
+            # register the log file writer as UI Handler
+            bb.event.register_UIHhandler(EventLogWriteHandler(self, self.configuration.writeeventlog))
+
         self.inotify_modified_files = []
 
         def _process_inotify_updates(server, notifier_list, abort):
@@ -301,68 +365,6 @@ class BBCooker:
         if consolelog:
             self.data.setVar("BB_CONSOLELOG", consolelog)
 
-        # we log all events to a file if so directed
-        if self.configuration.writeeventlog:
-            import json, pickle
-            DEFAULT_EVENTFILE = self.configuration.writeeventlog
-            class EventLogWriteHandler():
-
-                class EventWriter():
-                    def __init__(self, cooker):
-                        self.file_inited = None
-                        self.cooker = cooker
-                        self.event_queue = []
-
-                    def init_file(self):
-                        try:
-                            # delete the old log
-                            os.remove(DEFAULT_EVENTFILE)
-                        except:
-                            pass
-
-                        # write current configuration data
-                        with open(DEFAULT_EVENTFILE, "w") as f:
-                            f.write("%s\n" % json.dumps({ "allvariables" : self.cooker.getAllKeysWithFlags(["doc", "func"])}))
-
-                    def write_event(self, event):
-                        with open(DEFAULT_EVENTFILE, "a") as f:
-                            try:
-                                f.write("%s\n" % json.dumps({"class":event.__module__ + "." + event.__class__.__name__, "vars":json.dumps(pickle.dumps(event)) }))
-                            except Exception as e:
-                                import traceback
-                                print(e, traceback.format_exc())
-
-
-                    def send(self, event):
-                        event_class = event.__module__ + "." + event.__class__.__name__
-
-                        # 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)
-
-                                # 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)
-
-                # set our handler's event processor
-                event = EventWriter(self)       # self is the cooker here
-
-            # register the log file writer as UI Handler
-            bb.event.register_UIHhandler(EventLogWriteHandler())
-
         #
         # Copy of the data store which has been expanded.
         # Used for firing events and accessing variables where expansion needs to be accounted for

-- 
To stop receiving notification emails like this one, please contact
the administrator of this repository.


More information about the Openembedded-commits mailing list