blob: 2aa9e93f1bac6c0a73b1853e2e75b060d97661bf [file] [log] [blame]
George Keishingae7c8202017-02-09 10:33:45 -06001#!/usr/bin/env python
2r"""
3Generate an inventory variable file containing a list of properties
4fields from the YAML phosphor-dbus-interfaces repository.
5"""
6import sys
7import os
8import yaml
9import json
10
11lib_path = sys.path[0] + "/../lib"
12sys.path.insert(0, lib_path)
13from gen_print import *
14
15# This list will be longer when more development codes are available.
George Keishing36fedf22017-03-21 06:30:27 -050016inventory_items = ['fru', 'core']
George Keishingae7c8202017-02-09 10:33:45 -060017print_var(inventory_items)
18fru_inventory_file_path = 'inventory.py'
19print_var(fru_inventory_file_path)
20
21# Properties master list
22yaml_master_list = []
23
24# Clone the phosphor-dbus-interfaces repository
25cmd_buf = 'git clone https://github.com/openbmc/phosphor-dbus-interfaces'
26os.system(cmd_buf)
27
George Keishing36fedf22017-03-21 06:30:27 -050028repo_subdir_path = '/phosphor-dbus-interfaces/xyz/openbmc_project/'
George Keishingae7c8202017-02-09 10:33:45 -060029base_dir_path = os.getcwd() + repo_subdir_path
30
George Keishing9ef1fd42017-03-10 14:52:38 -060031# yaml file paths for FRU
George Keishing36fedf22017-03-21 06:30:27 -050032yaml_fru_list = [ 'Inventory/Item.interface.yaml',
33 'Inventory/Decorator/Asset.interface.yaml',
34 'Inventory/Decorator/Revision.interface.yaml',
35 'Inventory/Decorator/Replaceable.interface.yaml',
36 'Inventory/Decorator/Cacheable.interface.yaml',
37 'State/Decorator/OperationalStatus.interface.yaml',
George Keishing9ef1fd42017-03-10 14:52:38 -060038 ]
George Keishingae7c8202017-02-09 10:33:45 -060039
George Keishing36fedf22017-03-21 06:30:27 -050040# yaml file paths for CORE
41yaml_core_list = [ 'Inventory/Item.interface.yaml',
42 'State/Decorator/OperationalStatus.interface.yaml',
43 ]
George Keishingae7c8202017-02-09 10:33:45 -060044# Append to master list
45yaml_master_list.append(yaml_fru_list)
George Keishing36fedf22017-03-21 06:30:27 -050046yaml_master_list.append(yaml_core_list)
George Keishingae7c8202017-02-09 10:33:45 -060047
George Keishing9ef1fd42017-03-10 14:52:38 -060048print_var(yaml_master_list)
49
George Keishingae7c8202017-02-09 10:33:45 -060050# Populate Inventory data
51inventory_dict = {}
52
George Keishing9ef1fd42017-03-10 14:52:38 -060053for master_index in range(len(yaml_master_list)):
54 print_var(master_index)
George Keishingae7c8202017-02-09 10:33:45 -060055 inventory_dict[str(inventory_items[master_index])] = []
George Keishing9ef1fd42017-03-10 14:52:38 -060056 for rel_yaml_file_path in yaml_master_list[master_index]:
57 yaml_file_path = base_dir_path + rel_yaml_file_path
George Keishingae7c8202017-02-09 10:33:45 -060058
59 # Get the yaml dictionary data
George Keishing9ef1fd42017-03-10 14:52:38 -060060 print_timen("Loading " + yaml_file_path)
61 f = open(yaml_file_path)
George Keishingae7c8202017-02-09 10:33:45 -060062 yaml_data = yaml.load(f)
63 f.close()
64 for item in range(0, len(yaml_data['properties'])):
65 tmp_data = yaml_data['properties'][item]['name']
66 inventory_dict[str(inventory_items[master_index])].append(tmp_data)
67
68# Pretty print json formatter
George Keishing9ef1fd42017-03-10 14:52:38 -060069data = json.dumps(inventory_dict,
70 indent=4,
71 sort_keys=True,
72 default=str,
73 separators=(',', ':'))
George Keishingae7c8202017-02-09 10:33:45 -060074
75# Check if there is mismatch in data vs expect list
76if len(inventory_dict) != len(inventory_items):
77 print_error("The generated list doesn't match Master Inventory List.\n")
78 print data
79 print_var(inventory_items)
80 sys.exit()
81
82# Write dictionary data to inventory file
83print "\nGenerated Inventory item json format\n"
84print data
85out = open(fru_inventory_file_path, 'w')
86out.write('inventory_dict = ')
87out.write(data)
88
89out.close()
90print "\nGenerated Inventory File: ", fru_inventory_file_path