diff options
| author | Ed Bartosh <ed.bartosh@linux.intel.com> | 2016-06-20 14:00:52 +0300 |
|---|---|---|
| committer | Richard Purdie <richard.purdie@linuxfoundation.org> | 2016-06-20 17:23:57 +0100 |
| commit | 95f6e7bd0f7188f59e66e1769799e44a123b638b (patch) | |
| tree | 8c2f1509b0e65317d04f2223408999cf8cd73679 | |
| parent | f6fc25d1df2b77cb1d6534b302812c3af97dfd28 (diff) | |
| download | poky-95f6e7bd0f7188f59e66e1769799e44a123b638b.tar.gz | |
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>
| -rw-r--r-- | 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 3e4f8d8e5e..9bd3460625 100644 --- a/bitbake/lib/bb/cooker.py +++ b/bitbake/lib/bb/cooker.py | |||
| @@ -124,46 +124,39 @@ class EventWriter: | |||
| 124 | self.eventfile = eventfile | 124 | self.eventfile = eventfile |
| 125 | self.event_queue = [] | 125 | self.event_queue = [] |
| 126 | 126 | ||
| 127 | def init_file(self): | ||
| 128 | # write current configuration data | ||
| 129 | with open(eventfile, "w") as f: | ||
| 130 | f.write("%s\n" % json.dumps({ "allvariables" : self.cooker.getAllKeysWithFlags(["doc", "func"])})) | ||
| 131 | |||
| 132 | def write_event(self, event): | 127 | def write_event(self, event): |
| 133 | with open(self.eventfile, "a") as f: | 128 | with open(self.eventfile, "a") as f: |
| 134 | try: | 129 | try: |
| 135 | str_event = codecs.encode(pickle.dumps(event), 'base64').decode('utf-8') | 130 | str_event = codecs.encode(pickle.dumps(event), 'base64').decode('utf-8') |
| 136 | f.write("%s\n" % json.dumps({"class": event.__module__ + "." + event.__class__.__name__, | 131 | f.write("%s\n" % json.dumps({"class": event.__module__ + "." + event.__class__.__name__, |
| 137 | "vars": str_event})) | 132 | "vars": str_event})) |
| 138 | except Exception as e: | 133 | except Exception as err: |
| 139 | import traceback | 134 | import traceback |
| 140 | print(e, traceback.format_exc()) | 135 | print(err, traceback.format_exc()) |
| 141 | |||
| 142 | 136 | ||
| 143 | def send(self, event): | 137 | def send(self, event): |
| 144 | event_class = event.__module__ + "." + event.__class__.__name__ | 138 | if self.file_inited: |
| 139 | # we have the file, just write the event | ||
| 140 | self.write_event(event) | ||
| 141 | else: | ||
| 142 | # init on bb.event.BuildStarted | ||
| 143 | name = "%s.%s" % (event.__module__, event.__class__.__name__) | ||
| 144 | if name == "bb.event.BuildStarted": | ||
| 145 | with open(self.eventfile, "w") as f: | ||
| 146 | f.write("%s\n" % json.dumps({ "allvariables" : self.cooker.getAllKeysWithFlags(["doc", "func"])})) | ||
| 145 | 147 | ||
| 146 | # init on bb.event.BuildStarted | ||
| 147 | if self.file_inited is None: | ||
| 148 | if event_class == "bb.event.BuildStarted": | ||
| 149 | self.init_file() | ||
| 150 | self.file_inited = True | 148 | self.file_inited = True |
| 151 | 149 | ||
| 152 | # write pending events | 150 | # write pending events |
| 153 | for e in self.event_queue: | 151 | for evt in self.event_queue: |
| 154 | self.write_event(e) | 152 | self.write_event(evt) |
| 155 | 153 | ||
| 156 | # also write the current event | 154 | # also write the current event |
| 157 | self.write_event(event) | 155 | self.write_event(event) |
| 158 | |||
| 159 | else: | 156 | else: |
| 160 | # queue all events until the file is inited | 157 | # queue all events until the file is inited |
| 161 | self.event_queue.append(event) | 158 | self.event_queue.append(event) |
| 162 | 159 | ||
| 163 | else: | ||
| 164 | # we have the file, just write the event | ||
| 165 | self.write_event(event) | ||
| 166 | |||
| 167 | #============================================================================# | 160 | #============================================================================# |
| 168 | # BBCooker | 161 | # BBCooker |
| 169 | #============================================================================# | 162 | #============================================================================# |
