1# Copyright 2021-2022 Google LLC
2#
3# Licensed under the Apache License, Version 2.0 (the "License");
4# you may not use this file except in compliance with the License.
5# You may obtain a copy of the License at
6#
7#      https://www.apache.org/licenses/LICENSE-2.0
8#
9# Unless required by applicable law or agreed to in writing, software
10# distributed under the License is distributed on an "AS IS" BASIS,
11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12# See the License for the specific language governing permissions and
13# limitations under the License.
14
15# -----------------------------------------------------------------------------
16# This script generates a python-syntax list of dictionary entries for the
17# company IDs listed at:
18# https://bitbucket.org/bluetooth-SIG/public/src/main/assigned_numbers/company_identifiers/company_identifiers.yaml
19# The input to this script is the YAML file that can be obtained at that URL
20# -----------------------------------------------------------------------------
21
22# -----------------------------------------------------------------------------
23# Imports
24# -----------------------------------------------------------------------------
25import sys
26import yaml
27
28# -----------------------------------------------------------------------------
29with open(sys.argv[1], "r") as yaml_file:
30    root = yaml.safe_load(yaml_file)
31    companies = {}
32    for company in root["company_identifiers"]:
33        companies[company["value"]] = company["name"]
34
35    for company_id in sorted(companies.keys()):
36        company_name = companies[company_id]
37        escaped_company_name = company_name.replace('"', '\\"')
38        print(f'    0x{company_id:04X}: "{escaped_company_name}",')
39