dreport: refactor install_dreport_user_scripts
Pull the code that makes the plugin links for a single
script into its own function and then call it from
install_dreport_user_scripts.
This allows other layers to bbappend this recipe and
call the new install_dreport_user_script function so they
can link in their own dreport plugins.
The bbappends would need to:
* install their own plugins into ${D}${dreport_plugin_dir}
* call the new install_dreport_user_script function for
each of these plugins
* add any new functions to do_install[postfuncs]
Tested: Check that the bitbake output directory structure
matches what it was before the change.
Change-Id: Id0e97c2ed2f5233df70049a472c2a785f5efde71
Signed-off-by: Matt Spinler <spinler@us.ibm.com>
diff --git a/meta-phosphor/common/recipes-phosphor/dump/phosphor-debug-collector.bb b/meta-phosphor/common/recipes-phosphor/dump/phosphor-debug-collector.bb
index fcbe8ae..2aa5560 100644
--- a/meta-phosphor/common/recipes-phosphor/dump/phosphor-debug-collector.bb
+++ b/meta-phosphor/common/recipes-phosphor/dump/phosphor-debug-collector.bb
@@ -107,12 +107,10 @@
${D}${dreport_include_dir}/
}
-# Parse the scripts in base directory, read config value
+# Make the links for a single user plugin script
# Create user directories based on the dump type value in the config section
# Create softlinks for the base scripts in the user directories
-python install_dreport_user_scripts() {
- from shutil import copyfile
- import stat
+def install_dreport_user_script(script_path, d):
import re
import configparser
@@ -121,44 +119,52 @@
conf_dir = d.getVar('D', True) + d.getVar('dreport_conf_dir', True)
confsource = os.path.join(conf_dir, "dreport.conf")
configure.read(confsource)
- section = "DumpType"
- options = configure.options(section)
- #open the script from base dir and read the config value
+ config = ("config:")
+ section = "DumpType"
+ dreport_dir = d.getVar('D', True) + d.getVar('dreport_dir', True)
+
+ script = os.path.basename(script_path)
+ srclink = os.path.join(d.getVar('dreport_plugin_dir', True), script)
+
+ file = open(script_path, "r")
+
+ for line in file:
+ if not config in line:
+ continue
+ revalue = re.search('[0-9]+.[0-9]+', line)
+ if not revalue:
+ bb.warn("Invalid format for config value =%s" % line)
+ continue
+ parse_value = revalue.group(0)
+ config_values = re.split('\W+', parse_value, 1)
+ if(len(config_values) != 2):
+ bb.warn("Invalid config value=%s" % parse_value)
+ break;
+ priority = config_values[1]
+ types = [int(d) for d in str(config_values[0])]
+ for type in types:
+ if not configure.has_option(section, str(type)):
+ bb.warn("Invalid dump type id =%s" % (str(type)))
+ continue
+ typestr = configure.get(section, str(type))
+ destdir = os.path.join(dreport_dir, ("pl_" + typestr + ".d"))
+ if not os.path.exists(destdir):
+ os.makedirs(destdir)
+ linkname = "E" + priority + script
+ destlink = os.path.join(destdir, linkname)
+ os.symlink(srclink, destlink)
+
+#Make the links for all the plugins
+python install_dreport_user_scripts() {
+
source = d.getVar('S', True)
source_path = os.path.join(source, "tools", "dreport.d", "plugins.d")
scripts = os.listdir(source_path)
- dreport_dir= d.getVar('D', True) + d.getVar('dreport_dir', True)
- config = ("config:")
+
for script in scripts:
srcname = os.path.join(source_path, script)
- srclink = os.path.join(d.getVar('dreport_plugin_dir', True), script)
- file = open(srcname, "r")
- for line in file:
- if not config in line:
- continue
- revalue = re.search('[0-9]+.[0-9]+', line)
- if not revalue:
- bb.warn("Invalid format for config value =%s" % line)
- continue
- parse_value = revalue.group(0)
- config_values = re.split('\W+', parse_value, 1)
- if(len(config_values) != 2):
- bb.warn("Invalid config value=%s" % parse_value)
- break;
- priority = config_values[1]
- types = [int(d) for d in str(config_values[0])]
- for type in types:
- if not configure.has_option(section, str(type)):
- bb.warn("Invalid dump type id =%s" % (str(type)))
- continue
- typestr = configure.get(section, str(type))
- destdir = os.path.join(dreport_dir, ("pl_" + typestr + ".d"))
- if not os.path.exists(destdir):
- os.makedirs(destdir)
- linkname = "E" + priority + script
- destlink = os.path.join(destdir, linkname)
- os.symlink(srclink, destlink)
+ install_dreport_user_script(srcname, d)
}
#Enable ubifs-workaround by DISTRO_FEATURE obmc-ubi-fs.