blob: b96a7457a4ebe95f87a489b7f676919fbbc7d554 [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.
16inventory_items = ['FRU']
17print_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'
35
36# FRU list
37yaml_fru_list = []
38yaml_fru_list.append(item_yaml_file_path)
39yaml_fru_list.append(asset_yaml_file_path)
40yaml_fru_list.append(revision_yaml_file_path)
41
42# Append to master list
43yaml_master_list.append(yaml_fru_list)
44
45# Populate Inventory data
46inventory_dict = {}
47
48for master_index in range(0, len(yaml_master_list)):
49 inventory_dict[str(inventory_items[master_index])] = []
50 for yaml_file in yaml_master_list[master_index]:
51
52 # Get the yaml dictionary data
53 print_timen("Loading " + yaml_file)
54 f = open(yaml_file)
55 yaml_data = yaml.load(f)
56 f.close()
57 for item in range(0, len(yaml_data['properties'])):
58 tmp_data = yaml_data['properties'][item]['name']
59 inventory_dict[str(inventory_items[master_index])].append(tmp_data)
60
61# Pretty print json formatter
62data = json.dumps(inventory_dict, indent=4, sort_keys=True, default=str)
63
64# Check if there is mismatch in data vs expect list
65if len(inventory_dict) != len(inventory_items):
66 print_error("The generated list doesn't match Master Inventory List.\n")
67 print data
68 print_var(inventory_items)
69 sys.exit()
70
71# Write dictionary data to inventory file
72print "\nGenerated Inventory item json format\n"
73print data
74out = open(fru_inventory_file_path, 'w')
75out.write('inventory_dict = ')
76out.write(data)
77
78out.close()
79print "\nGenerated Inventory File: ", fru_inventory_file_path