[bitbake-devel] [PATCH] bitbake : Paginate 'bitbake -e' using less.

Diana Thayer garbados at gmail.com
Tue Jun 20 04:54:30 UTC 2017


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.

Signed-off-by: Diana Thayer <garbados at gmail.com>
---
 bitbake/lib/bb/cooker.py | 41 ++++++++++++++++++++++++++---------------
 1 file changed, 26 insertions(+), 15 deletions(-)

diff --git a/bitbake/lib/bb/cooker.py b/bitbake/lib/bb/cooker.py
index 479dc5a..eaec040 100644
--- a/bitbake/lib/bb/cooker.py
+++ b/bitbake/lib/bb/cooker.py
@@ -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):
-- 
2.7.4




More information about the bitbake-devel mailing list