From 6c36f4a6aa76dbbca4f8c0623955058db34bd1e5 Mon Sep 17 00:00:00 2001 From: Joshua Lock Date: Thu, 30 Jun 2011 23:02:52 -0700 Subject: cooker|command|event: add new command findFilesMatchingInDir 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. (Bitbake rev: 2a599812a57cb0b964880a6a2b7548423497ea92) Signed-off-by: Joshua Lock Signed-off-by: Richard Purdie --- bitbake/lib/bb/cooker.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) (limited to 'bitbake/lib/bb/cooker.py') diff --git a/bitbake/lib/bb/cooker.py b/bitbake/lib/bb/cooker.py index e537634df8..9874f664b5 100644 --- a/bitbake/lib/bb/cooker.py +++ b/bitbake/lib/bb/cooker.py @@ -520,6 +520,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. -- cgit v1.2.3-54-g00ecf