tinfoil: Do not fail when logging is disabled and full config is used
PATCH v3 1/3 tinfoil: Do not fail when logging is disabled and full config is used
If Tinfoil is initialized with setup_logging = False and Tinfoil.prepare() is called with config_only = False, then it fails because self.localhandlers is only initialized when setup_logging = True.
This is seen with, e.g., bitbake-getvar -q -r busybox MACHINE:
Traceback (most recent call last):
File ".../bitbake/bin/bitbake-getvar", line 41, in <module>
tinfoil.prepare(quiet=2)
File ".../bitbake/lib/bb/tinfoil.py", line 390, in prepare
for handler in self.localhandlers:AttributeError: 'Tinfoil' object has no attribute 'localhandlers'. Did you mean: 'oldhandlers'?
---
PATCHv2: New in this patch set.
PATCHv3: No change.
bitbake/lib/bb/tinfoil.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
bitbake/lib/bb/tinfoil.py +1 -1
@@ -325,11 +325,11 @@ class Tinfoil: self.recipes_parsed = False self.quiet = 0 self.oldhandlers = self.logger.handlers[:] + self.localhandlers = [] if setup_logging: # This is the *client-side* logger, nothing to do with # logging messages from the server bb.msg.logger_create('BitBake', output) - self.localhandlers = [] for handler in self.logger.handlers: if handler not in self.oldhandlers: self.localhandlers.append(handler)
PATCH v3 2/3 bitbake-getvar: Make --quiet work with --recipe
Initializing Tinfoil with setup_logging = False only has an effect when recipe parsing is not needed. To make it work regardless of if --recipe is used, manipulate the quiet parameter to Tinfoil.prepare() instead.
---
PATCHv2: New in this patch set.
PATCHv3: Apparently setup_logging still needs to be configured when
config_only=True...
bitbake/bin/bitbake-getvar | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-)
bitbake/bin/bitbake-getvar +3 -2
@@ -36,9 +36,10 @@ if __name__ == "__main__": print("--flag only makes sense with --value") sys.exit(1) - with bb.tinfoil.Tinfoil(tracking=True, setup_logging=not args.quiet) as tinfoil: + quiet = args.quiet + with bb.tinfoil.Tinfoil(tracking=True, setup_logging=not quiet) as tinfoil: if args.recipe: - tinfoil.prepare(quiet=2) + tinfoil.prepare(quiet=3 if quiet else 2) d = tinfoil.parse_recipe(args.recipe) else: tinfoil.prepare(quiet=2, config_only=True)
PATCH v3 3/3 bitbake-getvar: Make --value imply --quiet
In reply to Peter KjellerstedtIt does not make any sense to get log output from bitbake-getvar when the --value option is used as the log output is sent to stdout and thus interferes with the output of the variable's value.
---
PATCHv2: Adapted to the changes in the preceding commit.
PATCHv3: No change.
bitbake/bin/bitbake-getvar | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
bitbake/bin/bitbake-getvar +1 -1
@@ -36,7 +36,7 @@ if __name__ == "__main__": print("--flag only makes sense with --value") sys.exit(1) - quiet = args.quiet + quiet = args.quiet or args.value with bb.tinfoil.Tinfoil(tracking=True, setup_logging=not quiet) as tinfoil: if args.recipe: tinfoil.prepare(quiet=3 if quiet else 2)