]> git.ipfire.org Git - thirdparty/openembedded/openembedded-core-contrib.git/commitdiff
cooker: clean up EvertWriter
authorEd Bartosh <ed.bartosh@linux.intel.com>
Mon, 20 Jun 2016 11:00:52 +0000 (14:00 +0300)
committerRichard Purdie <richard.purdie@linuxfoundation.org>
Mon, 20 Jun 2016 16:23:53 +0000 (17:23 +0100)
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

Signed-off-by: Ed Bartosh <ed.bartosh@linux.intel.com>
Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
lib/bb/cooker.py

index 3e4f8d8e5e58c9ae9826122893c9a36711b34c75..9bd346062513a83a9ff288b880a6b07cc3af96e9 100644 (file)
@@ -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
 #============================================================================#