| Gopichand Paturi | ce34a26 | 2024-06-19 06:16:00 -0500 | [diff] [blame^] | 1 | bmc_dump_path = "/var/lib/phosphor-debug-collector/dumps" | 
| Marri Devender Rao | b6e5cb0 | 2017-10-11 02:22:46 -0500 | [diff] [blame] | 2 | dreport_plugin_dir = "${datadir}/dreport.d/plugins.d" | 
 | 3 | dreport_include_dir = "${datadir}/dreport.d/include.d" | 
 | 4 | dreport_conf_dir = "${datadir}/dreport.d/conf.d" | 
 | 5 | dreport_dir = "${datadir}/dreport.d/" | 
| Gopichand Paturi | ce34a26 | 2024-06-19 06:16:00 -0500 | [diff] [blame^] | 6 |  | 
 | 7 | # Make the links for a single user plugin script | 
 | 8 | # Create user directories based on the dump type value in the config section | 
 | 9 | # Create softlinks for the base scripts in the user directories | 
 | 10 | def install_dreport_user_script(dreport_conf, script_path, d): | 
 | 11 |     import re | 
 | 12 |     import configparser | 
 | 13 |  | 
 | 14 |     #Set variables | 
 | 15 |     config = ("config:") | 
 | 16 |     section = "DumpType" | 
 | 17 |  | 
 | 18 |     #Read the user types from the dreport_conf file | 
 | 19 |     configure = configparser.ConfigParser() | 
 | 20 |     conf_dir  = d.getVar('D', True) + d.getVar('dreport_conf_dir', True) | 
 | 21 |     confsource = os.path.join(conf_dir, dreport_conf) | 
 | 22 |     configure.read(confsource) | 
 | 23 |  | 
 | 24 |     #Extract the script name, and open the user script file | 
 | 25 |     dreport_dir = d.getVar('D', True) + d.getVar('dreport_dir', True) | 
 | 26 |     script = os.path.basename(script_path) | 
 | 27 |     file = open(script_path, "r") | 
 | 28 |  | 
 | 29 |     #softlink to the script | 
 | 30 |     srclink = os.path.join(d.getVar('dreport_plugin_dir', True), script) | 
 | 31 |  | 
 | 32 |     for line in file: | 
 | 33 |        if not config in line: | 
 | 34 |            continue | 
 | 35 |  | 
 | 36 |        revalue = re.search('[0-9]+.[0-9]+', line) | 
 | 37 |        if not revalue: | 
 | 38 |            bb.warn("Invalid format for config value =%s" % line) | 
 | 39 |            continue | 
 | 40 |  | 
 | 41 |        #Regex search to identify which directories get softlinks to the script | 
 | 42 |        parse_value = revalue.group(0) | 
 | 43 |        config_values = re.split(r'\W+', parse_value, 1) | 
 | 44 |        if(len(config_values) != 2): | 
 | 45 |            bb.warn("Invalid config value=%s" % parse_value) | 
 | 46 |            break; | 
 | 47 |        priority = config_values[1] | 
 | 48 |        types = [int(d) for d in str(config_values[0])] | 
 | 49 |  | 
 | 50 |        #For every dump type identified from 'types',create softlink to script | 
 | 51 |        for type in types: | 
 | 52 |            if not configure.has_option(section, str(type)): | 
 | 53 |                bb.warn("Invalid dump type id =%s" % (str(type))) | 
 | 54 |                continue | 
 | 55 |  | 
 | 56 |            #create directories based on the usertype | 
 | 57 |            typestr = configure.get(section, str(type)) | 
 | 58 |            destdir = os.path.join(dreport_dir, ("pl_" + typestr + ".d")) | 
 | 59 |            if not os.path.exists(destdir): | 
 | 60 |                os.makedirs(destdir) | 
 | 61 |  | 
 | 62 |            #Create softlinks to the user script in the directories | 
 | 63 |            linkname = "E" + priority + script | 
 | 64 |            destlink = os.path.join(destdir, linkname) | 
 | 65 |            os.symlink(srclink, destlink) | 
 | 66 |  | 
 | 67 |     file.close() |