Skip to contentSkip to conversation

bitbake-layers minor improvements

PATCH Applied Paul Eggleton 2 participants 7 messages Aug 12, 2011 – Aug 15, 2011

lore
Share & tools
lore
#0 lore raw

cover bitbake-layers minor improvements

Several improvements to the help and show_layers function in bitbake-layers.

The changes are available (against Poky, but apply cleanly against bitbake master with -p2) at:
git://git.pokylinux.org/poky-contrib paule/bitbake-layers-3
http://git.pokylinux.org/cgit.cgi/poky-contrib/log/?h=paule/bitbake-layers-3

Paul Eggleton (4):
bitbake-layers: improve default command help
bitbake-layers: show help with no command specified
bitbake-layers: use logger.plain instead of info
bitbake-layers: extend show_layers

 bitbake/bin/bitbake-layers |   89 ++++++++++++++++++++++++++++++-------------
 1 files changed, 62 insertions(+), 27 deletions(-)
Signature · 1 line
1.7.4.1
#1 lore raw

PATCH 1/4 bitbake-layers: improve default command help

Improve default help output and make unrecognised commands print it out rather than just an error.

---
 bitbake/bin/bitbake-layers |   36 ++++++++++++++++++++++++++++--------
 1 files changed, 28 insertions(+), 8 deletions(-)
bitbake/bin/bitbake-layers +28 -8
index d9f95d1..0900d00 100755
@@ -76,16 +76,36 @@ class Commands(cmd.Cmd):
         if not self.cooker_data:
             self.prepare_cooker()
 
+    def default(self, line):
+        """Handle unrecognised commands"""
+        sys.stderr.write("Unrecognised command or option\n")
+        self.do_help('')
+
+    def do_help(self, topic):
+        """display general help or help on a specified command"""
+        if topic:
+            sys.stdout.write('%s: ' % topic)
+            cmd.Cmd.do_help(self,topic)
+        else:
+            sys.stdout.write("usage: bitbake-layers <command> [arguments]\n\n")
+            sys.stdout.write("Available commands:\n")
+            procnames = self.get_names()
+            for procname in procnames:
+                if procname[:3] == 'do_':
+                    sys.stdout.write("  %s\n" % procname[3:])
+                    doc = getattr(self, procname).__doc__
+                    if doc:
+                        sys.stdout.write("    %s\n" % doc.splitlines()[0])
+
     def do_show_layers(self, args):
-        """show_layers: shows current configured layers"""
+        """show current configured layers"""
         self.check_prepare_cooker()
         logger.info(str(self.config_data.getVar('BBLAYERS', True)))
 
     def do_show_overlayed(self, args):
-        """show_overlayed: list overlayed recipes (where there is a recipe in another
-layer that has a higher layer priority)
+        """list overlayed recipes (where there is a recipe in another layer that has a higher layer priority)
 
-syntax: show_overlayed
+usage: show_overlayed
 
 Highest priority recipes are listed with the recipes they overlay as subitems.
 """
@@ -100,9 +120,9 @@ Highest priority recipes are listed with the recipes they overlay as subitems.
             logger.info('No overlayed recipes found')
 
     def do_flatten(self, args):
-        """flatten: flattens layer configuration into a separate output directory.
+        """flattens layer configuration into a separate output directory.
 
-syntax: flatten <outputdir>
+usage: flatten <outputdir>
 
 Takes the current layer configuration and builds a "flattened" directory
 containing the contents of all layers, with any overlayed recipes removed
@@ -175,9 +195,9 @@ cleanup may still be necessary afterwards, in particular:
         recipefile.writelines(appendfile.readlines())
 
     def do_show_appends(self, args):
-        """show_appends: List bbappend files and recipe files they apply to
+        """list bbappend files and recipe files they apply to
 
-syntax: show_appends
+usage: show_appends
 
 Recipes are listed with the bbappends that apply to them as subitems.
 """
Signature · 1 line
1.7.4.1
#2 lore raw

PATCH 2/4 bitbake-layers: show help with no command specified

In reply to Paul Eggleton

Instead of running show_appends when no command is specified, show the default help text. Running show_appends by default made sense previously when that was the only real command provided, but now we have several useful commands implemented.

---
 bitbake/bin/bitbake-layers |    7 ++-----
 1 files changed, 2 insertions(+), 5 deletions(-)
bitbake/bin/bitbake-layers +2 -5
index 0900d00..2845ae5 100755
@@ -2,9 +2,7 @@
 
 # This script has subcommands which operate against your bitbake layers, either
 # displaying useful information, or acting against them.
-# Currently, it only provides a show_appends command, which shows you what
-# bbappends are in effect, and warns you if you have appends which are not being
-# utilized.
+# See the help output for details on available commands.
 
 import cmd
 import logging
@@ -23,7 +21,6 @@ from bb.cooker import state
 
 
 logger = logging.getLogger('BitBake')
-default_cmd = 'show_appends'
 
 
 def main(args):
@@ -34,7 +31,7 @@ def main(args):
     if args:
         cmds.onecmd(' '.join(args))
     else:
-        cmds.onecmd(default_cmd)
+        cmds.do_help('')
     return cmds.returncode
 
 
Signature · 1 line
1.7.4.1
#3 lore raw

PATCH 3/4 bitbake-layers: use logger.plain instead of info

In reply to Paul Eggleton

The INFO: prefix makes sense in bitbake itself but in bitbake-layers is just noise. Changing this exposed the fact that the logger was not being set up correctly (which should be done anyway to correctly support logging from BitBake), so this has also been fixed.

---
 bitbake/bin/bitbake-layers |   33 +++++++++++++++++++--------------
 1 files changed, 19 insertions(+), 14 deletions(-)
bitbake/bin/bitbake-layers +19 -14
index 2845ae5..aea8f93 100755
@@ -24,7 +24,12 @@ logger = logging.getLogger('BitBake')
 
 
 def main(args):
-    logging.basicConfig(format='%(levelname)s: %(message)s')
+    # Set up logging
+    console = logging.StreamHandler(sys.stdout)
+    format = bb.msg.BBLogFormatter("%(levelname)s: %(message)s")
+    console.setFormatter(format)
+    logger.addHandler(console)
+
     bb.utils.clean_environment()
 
     cmds = Commands()
@@ -97,7 +102,7 @@ class Commands(cmd.Cmd):
     def do_show_layers(self, args):
         """show current configured layers"""
         self.check_prepare_cooker()
-        logger.info(str(self.config_data.getVar('BBLAYERS', True)))
+        logger.plain(str(self.config_data.getVar('BBLAYERS', True)))
 
     def do_show_overlayed(self, args):
         """list overlayed recipes (where there is a recipe in another layer that has a higher layer priority)
@@ -108,13 +113,13 @@ Highest priority recipes are listed with the recipes they overlay as subitems.
 """
         self.check_prepare_cooker()
         if self.cooker.overlayed:
-            logger.info('Overlayed recipes:')
+            logger.plain('Overlayed recipes:')
             for f in self.cooker.overlayed.iterkeys():
-                logger.info('%s' % f)
+                logger.plain('%s' % f)
                 for of in self.cooker.overlayed[f]:
-                    logger.info('  %s' % of)
+                    logger.plain('  %s' % of)
         else:
-            logger.info('No overlayed recipes found')
+            logger.plain('No overlayed recipes found')
 
     def do_flatten(self, args):
         """flattens layer configuration into a separate output directory.
@@ -151,12 +156,12 @@ cleanup may still be necessary afterwards, in particular:
                     if of.startswith(layer):
                         overlayed.append(of)
 
-            logger.info('Copying files from %s...' % layer )
+            logger.plain('Copying files from %s...' % layer )
             for root, dirs, files in os.walk(layer):
                 for f1 in files:
                     f1full = os.sep.join([root, f1])
                     if f1full in overlayed:
-                        logger.info('  Skipping overlayed file %s' % f1full )
+                        logger.plain('  Skipping overlayed file %s' % f1full )
                     else:
                         ext = os.path.splitext(f1)[1]
                         if ext != '.bbappend':
@@ -165,7 +170,7 @@ cleanup may still be necessary afterwards, in particular:
                             bb.utils.mkdirhier(os.path.dirname(fdest))
                             if os.path.exists(fdest):
                                 if f1 == 'layer.conf' and root.endswith('/conf'):
-                                    logger.info('  Skipping layer config file %s' % f1full )
+                                    logger.plain('  Skipping layer config file %s' % f1full )
                                     continue
                                 else:
                                     logger.warn('Overwriting file %s', fdest)
@@ -174,7 +179,7 @@ cleanup may still be necessary afterwards, in particular:
                                 if f1 in self.cooker_data.appends:
                                     appends = self.cooker_data.appends[f1]
                                     if appends:
-                                        logger.info('  Applying appends to %s' % fdest )
+                                        logger.plain('  Applying appends to %s' % fdest )
                                         for appendname in appends:
                                             self.apply_append(appendname, fdest)
 
@@ -200,10 +205,10 @@ Recipes are listed with the bbappends that apply to them as subitems.
 """
         self.check_prepare_cooker()
         if not self.cooker_data.appends:
-            logger.info('No append files found')
+            logger.plain('No append files found')
             return
 
-        logger.info('State of append files:')
+        logger.plain('State of append files:')
 
         pnlist = list(self.cooker_data.pkg_pn.keys())
         pnlist.sort()
@@ -232,9 +237,9 @@ Recipes are listed with the bbappends that apply to them as subitems.
         appended, missing = self.get_appends_for_files(filenames)
         if appended:
             for basename, appends in appended:
-                logger.info('%s%s:', basename, name_suffix)
+                logger.plain('%s%s:', basename, name_suffix)
                 for append in appends:
-                    logger.info('  %s', append)
+                    logger.plain('  %s', append)
 
             if best_filename:
                 if best_filename in missing:
Signature · 1 line
1.7.4.1
#4 lore raw

Re: [PATCH 3/4] bitbake-layers: use logger.plain instead of info

bitbake/bin/bitbake-layers logger = logging.getLogger('BitBake') · line 29

Quoted 3 lines · On Friday 12 August 2011 17:13:58 Paul Eggleton wrote:
bitbake/bin/bitbake-layers +3 -0
+    # Set up logging
+    console = logging.StreamHandler(sys.stdout)
+    format = bb.msg.BBLogFormatter("%(levelname)s: %(message)s")

Forgot to mention in the cover: when Richard's logging changes get merged this code will need the additional "bb.msg.addDefaultlogFilter(console)" line added as well.

Cheers,
Paul

Signature · 2 lines
Paul Eggleton
Intel Open Source Technology Centre
#5 lore raw

PATCH 4/4 bitbake-layers: extend show_layers

In reply to Paul Eggleton

Make show_layers print layer name, path, and priority in a simple table rather than just the value of BBLAYERS.

---
 bitbake/bin/bitbake-layers |   15 ++++++++++++++-
 1 files changed, 14 insertions(+), 1 deletions(-)
bitbake/bin/bitbake-layers +14 -1
index aea8f93..ce6a03e 100755
@@ -102,7 +102,20 @@ class Commands(cmd.Cmd):
     def do_show_layers(self, args):
         """show current configured layers"""
         self.check_prepare_cooker()
-        logger.plain(str(self.config_data.getVar('BBLAYERS', True)))
+        logger.plain('')
+        logger.plain("%s  %s  %s" % ("layer".ljust(20), "path".ljust(40), "priority"))
+        logger.plain('=' * 74)
+        layerdirs = str(self.config_data.getVar('BBLAYERS', True)).split()
+        for layerdir in layerdirs:
+            layername = '?'
+            layerpri = 0
+            for layer, _, regex, pri in self.cooker.status.bbfile_config_priorities:
+                if regex.match(os.path.join(layerdir, 'test')):
+                    layername = layer
+                    layerpri = pri
+                    break
+
+            logger.plain("%s  %s  %d" % (layername.ljust(20), layerdir.ljust(40), layerpri))
 
     def do_show_overlayed(self, args):
         """list overlayed recipes (where there is a recipe in another layer that has a higher layer priority)
Signature · 1 line
1.7.4.1
#6 lore raw
In reply to Paul Eggleton
Quoted 8 lines · Paul Eggleton

Several improvements to the help and show_layers function in bitbake-layers.

The changes are available (against Poky, but apply cleanly against bitbake master with -p2) at:
git://git.pokylinux.org/poky-contrib paule/bitbake-layers-3
http://git.pokylinux.org/cgit.cgi/poky-contrib/log/?h=paule/bitbake-layers-3

Quoted 5 lines

Paul Eggleton (4):
bitbake-layers: improve default command help
bitbake-layers: show help with no command specified
bitbake-layers: use logger.plain instead of info
bitbake-layers: extend show_layers

Merged to master, thanks (with the log change issue handled).

Cheers,

Richard