[bitbake-devel] [PATCH 06/10] cooker|command|event: add new command findFilesMatchingInDir

Joshua Lock josh at linux.intel.com
Fri Jul 1 06:02:52 UTC 2011


This command can be used to search each BBPATH for files in the passed
directory which have a filename matching the supplied pattern.

This is implemented for use from the GUI (to determine the available
PACKAGE_CLASSES) but has been written so as to be generically useful and
reusable.

Signed-off-by: Joshua Lock <josh at linux.intel.com>
---
 lib/bb/command.py |   12 ++++++++++++
 lib/bb/cooker.py  |   23 +++++++++++++++++++++++
 lib/bb/event.py   |   10 ++++++++++
 3 files changed, 45 insertions(+), 0 deletions(-)

diff --git a/lib/bb/command.py b/lib/bb/command.py
index 2f37938..a902da2 100644
--- a/lib/bb/command.py
+++ b/lib/bb/command.py
@@ -251,6 +251,18 @@ class CommandsAsync:
         command.finishAsyncCommand()
     findConfigFiles.needcache = True
 
+    def findFilesMatchingInDir(self, command, params):
+        """
+        Find implementation files matching the specified pattern
+        in the requested subdirectory of a BBPATH
+        """
+        pattern = params[0]
+        directory = params[1]
+
+        command.cooker.findFilesMatchingInDir(pattern, directory)
+        command.finishAsyncCommand()
+    findFilesMatchingInDir.needcache = True
+
     def findConfigFilePath(self, command, params):
         """
         Find the path of the requested configuration file
diff --git a/lib/bb/cooker.py b/lib/bb/cooker.py
index 48c9e24..f0c94fa 100644
--- a/lib/bb/cooker.py
+++ b/lib/bb/cooker.py
@@ -517,6 +517,29 @@ class BBCooker:
         path = self._findConfigFile(configfile)
         bb.event.fire(bb.event.ConfigFilePathFound(path), self.configuration.data)
 
+    def findFilesMatchingInDir(self, filepattern, directory):
+        """
+        Searches for files matching the regex 'pattern' which are children of
+        'directory' in each BBPATH. i.e. to find all rootfs package classes available
+        to BitBake one could call findFilesMatchingInDir(self, 'rootfs_', 'classes')
+        or to find all machine configuration files on could call
+        findFilesMatchingInDir(self, 'conf/machines', 'conf')
+        """
+        import re
+
+        matches = []
+        p = re.compile(re.escape(filepattern))
+        bbpaths = bb.data.getVar('BBPATH', self.configuration.data, True).split(':')
+        for path in bbpaths:
+            dirpath = os.path.join(path, directory)
+            if os.path.exists(dirpath):
+                for root, dirs, files in os.walk(dirpath):
+                    for f in files:
+                        if p.search(f):
+                            matches.append(f)
+
+        bb.event.fire(bb.event.FilesMatchingFound(filepattern, matches), self.configuration.data)
+
     def findConfigFiles(self, varname):
         """
         Find config files which are appropriate values for varname.
diff --git a/lib/bb/event.py b/lib/bb/event.py
index 7c49d46..c7252dd 100644
--- a/lib/bb/event.py
+++ b/lib/bb/event.py
@@ -390,6 +390,16 @@ class TargetsTreeGenerated(Event):
         Event.__init__(self)
         self._model = model
 
+class FilesMatchingFound(Event):
+    """
+    Event when a list of files matching the supplied pattern has
+    been generated
+    """
+    def __init__(self, pattern, matches):
+        Event.__init__(self)
+        self._pattern = pattern
+        self._matches = matches
+
 class ConfigFilesFound(Event):
     """
     Event when a list of appropriate config files has been generated
-- 
1.7.5.4





More information about the bitbake-devel mailing list