blob: a6650f49a14df247fba9e518cf9b930a43029cd4 [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 Keishing05b36ec2017-03-06 05:50:31 -060016inventory_items = ['fru']
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
28repo_subdir_path = '/phosphor-dbus-interfaces/xyz/openbmc_project/Inventory/'
29base_dir_path = os.getcwd() + repo_subdir_path
30
31# yaml paths for FRU
32item_yaml_file_path = base_dir_path + 'Item.interface.yaml'
33asset_yaml_file_path = base_dir_path + 'Decorator/Asset.interface.yaml'
34revision_yaml_file_path = base_dir_path + 'Decorator/Revision.interface.yaml'
George Keishing05b36ec2017-03-06 05:50:31 -060035replaceable_yaml_file_path = base_dir_path + 'Decorator/Replaceable.interface.yaml'
George Keishingae7c8202017-02-09 10:33:45 -060036
37# FRU list
38yaml_fru_list = []
39yaml_fru_list.append(item_yaml_file_path)
40yaml_fru_list.append(asset_yaml_file_path)
41yaml_fru_list.append(revision_yaml_file_path)
George Keishing05b36ec2017-03-06 05:50:31 -060042yaml_fru_list.append(replaceable_yaml_file_path)
George Keishingae7c8202017-02-09 10:33:45 -060043
44# Append to master list
45yaml_master_list.append(yaml_fru_list)
46
47# Populate Inventory data
48inventory_dict = {}
49
50for master_index in range(0, len(yaml_master_list)):
51 inventory_dict[str(inventory_items[master_index])] = []
52 for yaml_file in yaml_master_list[master_index]:
53
54 # Get the yaml dictionary data
55 print_timen("Loading " + yaml_file)
56 f = open(yaml_file)
57 yaml_data = yaml.load(f)
58 f.close()
59 for item in range(0, len(yaml_data['properties'])):
60 tmp_data = yaml_data['properties'][item]['name']
61 inventory_dict[str(inventory_items[master_index])].append(tmp_data)
62
63# Pretty print json formatter
64data = json.dumps(inventory_dict, indent=4, sort_keys=True, default=str)
65
66# Check if there is mismatch in data vs expect list
67if len(inventory_dict) != len(inventory_items):
68 print_error("The generated list doesn't match Master Inventory List.\n")
69 print data
70 print_var(inventory_items)
71 sys.exit()
72
73# Write dictionary data to inventory file
74print "\nGenerated Inventory item json format\n"
75print data
76out = open(fru_inventory_file_path, 'w')
77out.write('inventory_dict = ')
78out.write(data)
79
80out.close()
81print "\nGenerated Inventory File: ", fru_inventory_file_path