bitbake : Paginate 'bitbake -e' using less.
PATCH 1/1 bitbake : Paginate 'bitbake -e' using less.
This patch modifies bitbake/lib/bb/cooker.py#showEnvironment to call less using subprocess.Popen, rather than using the logger. It is a WIP solution to bug 9203.
--- bitbake/lib/bb/cooker.py | 41 ++++++++++++++++++++++++++--------------- 1 file changed, 26 insertions(+), 15 deletions(-)
bitbake/lib/bb/cooker.py +26 -15
@@ -514,21 +514,32 @@ class BBCooker: parselog.exception("Unable to read %s", fn) raise - # Display history - with closing(StringIO()) as env: - self.data.inchistory.emit(env) - logger.plain(env.getvalue()) - - # emit variables and shell functions - with closing(StringIO()) as env: - data.emit_env(env, envdata, True) - logger.plain(env.getvalue()) - - # emit the metadata which isnt valid shell - data.expandKeys(envdata) - for e in sorted(envdata.keys()): - if envdata.getVarFlag(e, 'func', False) and envdata.getVarFlag(e, 'python', False): - logger.plain("\npython %s () {\n%s}\n", e, envdata.getVar(e, False)) + # establish `less` as a pager for environment output + # TODO determine pager by env var + pager = subprocess.Popen(['less', '-F', '-R', '-S', '-X', '-K'], + stdin=subprocess.PIPE, + stdout=sys.stdout, + universal_newlines=True) + with pager: + lines = [] + # Display history + with closing(StringIO()) as env: + self.data.inchistory.emit(env) + lines.append(env.getvalue()) + + # emit variables and shell functions + with closing(StringIO()) as env: + data.emit_env(env, envdata, True) + lines.append(env.getvalue()) + + # emit the metadata which isnt valid shell + data.expandKeys(envdata) + for e in sorted(envdata.keys()): + if envdata.getVarFlag(e, 'func', False) and envdata.getVarFlag(e, 'python', False): + lines.append("\npython %s () {\n%s}\n" % (e, envdata.getVar(e, False))) + + # communicate lines to pager + pager.communicate('\n'.join(lines)) def buildTaskData(self, pkgs_to_build, task, abort, allowincomplete=False):
Signature · 1 line
2.7.4
bitbake/lib/bb/cooker.py class BBCooker: · line 522
Quoted 5 lines · Diana Thayer
bitbake/lib/bb/cooker.py +4
-0+ pager = subprocess.Popen(['less', '-F', '-R', '-S', '-X', '-K'], + stdin=subprocess.PIPE, + stdout=sys.stdout, + universal_newlines=True)
What if I'm piping bitbake -e though grep or into a file already?
Ross
Basically, this change needs to be aware of the destination for the output. If it is a tty, then it is fine to output to a viewer such as less, but otherwise it should go to stdout as before. This should of course not be hardcoded, but use environment variables, e.g., $OE_PAGER || $PAGER || less (inspired by git_pager() in the git source). You should also not expect that everyone wants the options you have used for less. Looking again at how git handles this, they use “LESS=FRX <command>” if the $LESS environment variable is not set, and does not modify it if it is set. You also want to add options such as --paginate and --no-pager (yet again inspired by git) to bitbake.
All in all, look at and be inspired by how git handles pagers, they have this pretty well covered.
//Peter
From: [email protected] [mailto:[email protected]] On Behalf Of Burton, Ross
Sent: den 20 juni 2017 12:06
To: Diana Thayer <[email protected]>
Cc: bitbake-devel <[email protected]>
Subject: Re: [bitbake-devel] [PATCH] bitbake : Paginate 'bitbake -e' using less.
On 20 June 2017 at 05:54, Diana Thayer <[email protected]<mailto:[email protected]>> wrote:
+ pager = subprocess.Popen(['less', '-F', '-R', '-S', '-X', '-K'],
+ stdin=subprocess.PIPE, + stdout=sys.stdout, + universal_newlines=True)
What if I'm piping bitbake -e though grep or into a file already?
Ross
Thank you for the feedback!
I've added lines to check $OE_PAGER and $PAGER, such that PAGER=cat bitbake -e effectively disables pagination.
Regarding the option '--paginate', would it capture output from whatever command has run? I'm not sure how to capture stdout at such a scope.
Quoted 48 lines · Peter Kjellerstedt
Basically, this change needs to be aware of the destination for the output. If it is a tty, then it is fine to output to a viewer such as less, but otherwise it should go to stdout as before. This should of course not be hardcoded, but use environment variables, e.g., $OE_PAGER || $PAGER || less (inspired by
git_pager()in the git source). You should also not expect that everyone wants the options you have used for less. Looking again at how git handles this, they use “LESS=FRX <command>” if the $LESS environment variable is not set, and does not modify it if it is set. You also want to add options such as --paginate and --no-pager (yet again inspired by git) to bitbake.All in all, look at and be inspired by how git handles pagers, they have this pretty well covered.
//Peter
*From:* [email protected] [mailto:
[email protected]] *On Behalf Of *Burton, Ross *Sent:* den 20 juni 2017 12:06
*To:* Diana Thayer <[email protected]>
*Cc:* bitbake-devel <[email protected]> *Subject:* Re: [bitbake-devel] [PATCH] bitbake : Paginate 'bitbake -e' using less.On 20 June 2017 at 05:54, Diana Thayer <[email protected]> wrote:
bitbake/lib/bb/cooker.py +4
-0+ pager = subprocess.Popen(['less', '-F', '-R', '-S', '-X', '-K'], + stdin=subprocess.PIPE, + stdout=sys.stdout, + universal_newlines=True)What if I'm piping bitbake -e though grep or into a file already?
Ross