mirror of
https://git.yoctoproject.org/poky-contrib
synced 2025-05-08 23:52:25 +08:00
bitbake: tinfoil: Refactor temporary data tracking in a context manager
A new context manager Tinfoil._data_tracked_if_enabled() is introduced to replace the following structure: if self.tracking: self.run_command('enableDataTracking') # Code that need data tracking if self.tracking: self.run_command('disableDataTracking') (Bitbake rev: 0fea4555d2143c6b23a79d3d5cf791103a68141b) Signed-off-by: Yoann Congal <yoann.congal@smile.fr> Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
parent
8180865c22
commit
e4761312f7
@ -15,6 +15,7 @@ import atexit
|
||||
import re
|
||||
from collections import OrderedDict, defaultdict
|
||||
from functools import partial
|
||||
from contextlib import contextmanager
|
||||
|
||||
import bb.cache
|
||||
import bb.cooker
|
||||
@ -641,6 +642,22 @@ class Tinfoil:
|
||||
fn = self.get_recipe_file(pn)
|
||||
return self.parse_recipe_file(fn)
|
||||
|
||||
@contextmanager
|
||||
def _data_tracked_if_enabled(self):
|
||||
"""
|
||||
A context manager to enable data tracking for a code segment if data
|
||||
tracking was enabled for this tinfoil instance.
|
||||
"""
|
||||
if self.tracking:
|
||||
# Enable history tracking just for the operation
|
||||
self.run_command('enableDataTracking')
|
||||
|
||||
# Here goes the operation with the optional data tracking
|
||||
yield
|
||||
|
||||
if self.tracking:
|
||||
self.run_command('disableDataTracking')
|
||||
|
||||
def finalizeData(self):
|
||||
"""
|
||||
Run anonymous functions and expand keys
|
||||
@ -659,10 +676,7 @@ class Tinfoil:
|
||||
appendlist: optional list of bbappend files to apply, if you
|
||||
want to filter them
|
||||
"""
|
||||
if self.tracking:
|
||||
# Enable history tracking just for the parse operation
|
||||
self.run_command('enableDataTracking')
|
||||
try:
|
||||
with self._data_tracked_if_enabled():
|
||||
if appends and appendlist == []:
|
||||
appends = False
|
||||
if config_data:
|
||||
@ -674,9 +688,6 @@ class Tinfoil:
|
||||
return self._reconvert_type(dscon, 'DataStoreConnectionHandle')
|
||||
else:
|
||||
return None
|
||||
finally:
|
||||
if self.tracking:
|
||||
self.run_command('disableDataTracking')
|
||||
|
||||
def build_file(self, buildfile, task, internal=True):
|
||||
"""
|
||||
|
Loading…
x
Reference in New Issue
Block a user