From dfa3fdc3dc1045babc67ecd7974c4d997006d9c4 Mon Sep 17 00:00:00 2001 From: Patrick Williams Date: Wed, 7 Dec 2022 07:14:21 -0600 Subject: format: reformat with latest openbmc-build-scripts Reformat the repository using the latest from openbmc-build-scripts. Add the `static/redfish` directory to be ignored by prettier since these files come from elsewhere and having the ability to do a direct diff is handy. Signed-off-by: Patrick Williams Change-Id: I74464d6f97047b4888a591e0d8a4f5ca970ac69e --- scripts/check_base_registry.py | 53 +++++++----- scripts/parse_registries.py | 177 ++++++++++++++++++++++------------------- scripts/update_schemas.py | 25 +++--- scripts/websocket_test.py | 46 ++++++----- 4 files changed, 163 insertions(+), 138 deletions(-) (limited to 'scripts') diff --git a/scripts/check_base_registry.py b/scripts/check_base_registry.py index 1db533a09d..663c6e0541 100755 --- a/scripts/check_base_registry.py +++ b/scripts/check_base_registry.py @@ -4,10 +4,9 @@ import argparse import json import re - parser = argparse.ArgumentParser() -parser.add_argument('-b', '--base', default=None, required=True) -parser.add_argument('-f', '--file', default=None, required=True) +parser.add_argument("-b", "--base", default=None, required=True) +parser.add_argument("-f", "--file", default=None, required=True) args = parser.parse_args() with open(args.file) as error_file: @@ -15,9 +14,14 @@ with open(args.file) as error_file: with open(args.base) as base_file: base_json = json.load(base_file) - for message_name, message_data in base_json['Messages'].items(): - message_id = base_json['RegistryPrefix'] + '.' + \ - base_json['RegistryVersion'] + '.' + message_name + for message_name, message_data in base_json["Messages"].items(): + message_id = ( + base_json["RegistryPrefix"] + + "." + + base_json["RegistryVersion"] + + "." + + message_name + ) message_found = False index = 0 for i, error in enumerate(error_data): @@ -29,33 +33,38 @@ with open(args.file) as error_file: print("{} not found".format(message_id)) continue - error_info = error_data[index:index + 15] + error_info = error_data[index : index + 15] error_str = " ".join(error_info) error_str = re.sub( - 'std::to_string\\(arg(\\d+)\\)', - 'arg\\1', - error_str) - error_str = re.sub('"\n\\s*"', '', error_str, re.MULTILINE) + "std::to_string\\(arg(\\d+)\\)", "arg\\1", error_str + ) + error_str = re.sub('"\n\\s*"', "", error_str, re.MULTILINE) error_str = re.sub( '"\\s*\\+\\s*arg(\\d+)\\s*\\+\n?\\s*"', - '%\\1', + "%\\1", error_str, - re.MULTILINE) - if message_data['Message'] not in error_str: + re.MULTILINE, + ) + if message_data["Message"] not in error_str: print( "{}: error in Message: {}".format( - message_id, - message_data['Message'])) + message_id, message_data["Message"] + ) + ) print(error_str) - if message_data['MessageSeverity'] not in error_str: - print("{}: error in MessageSeverity: {}".format( - message_id, message_data['MessageSeverity'])) + if message_data["MessageSeverity"] not in error_str: + print( + "{}: error in MessageSeverity: {}".format( + message_id, message_data["MessageSeverity"] + ) + ) print(error_str) - if message_data['Resolution'] not in error_str: + if message_data["Resolution"] not in error_str: print( "{}: error in Resolution: {}".format( - message_id, - message_data['Resolution'])) + message_id, message_data["Resolution"] + ) + ) print(error_str) diff --git a/scripts/parse_registries.py b/scripts/parse_registries.py index bfe87ef773..369bebf582 100755 --- a/scripts/parse_registries.py +++ b/scripts/parse_registries.py @@ -1,14 +1,14 @@ #!/usr/bin/env python3 +import argparse import json import os import requests -import argparse -PRAGMA_ONCE = '''#pragma once -''' +PRAGMA_ONCE = """#pragma once +""" -WARNING = '''/**************************************************************** +WARNING = """/**************************************************************** * READ THIS WARNING FIRST * This is an auto-generated header which contains definitions * for Redfish DMTF defined messages. @@ -17,9 +17,12 @@ WARNING = '''/**************************************************************** * this file are owned by DMTF. Any modifications to these files * should be first pushed to the relevant registry in the DMTF * github organization. - ***************************************************************/''' + ***************************************************************/""" -REGISTRY_HEADER = PRAGMA_ONCE + WARNING + ''' +REGISTRY_HEADER = ( + PRAGMA_ONCE + + WARNING + + """ #include "registries.hpp" #include @@ -28,25 +31,20 @@ REGISTRY_HEADER = PRAGMA_ONCE + WARNING + ''' namespace redfish::registries::{} {{ -''' +""" +) SCRIPT_DIR = os.path.dirname(os.path.realpath(__file__)) include_path = os.path.realpath( - os.path.join( - SCRIPT_DIR, - "..", - "redfish-core", - "include", - "registries")) + os.path.join(SCRIPT_DIR, "..", "redfish-core", "include", "registries") +) -proxies = { - 'https': os.environ.get("https_proxy", None) -} +proxies = {"https": os.environ.get("https_proxy", None)} def make_getter(dmtf_name, header_name, type_name): - url = 'https://redfish.dmtf.org/registries/{}'.format(dmtf_name) + url = "https://redfish.dmtf.org/registries/{}".format(dmtf_name) dmtf = requests.get(url, proxies=proxies) dmtf.raise_for_status() json_file = json.loads(dmtf.text) @@ -62,72 +60,68 @@ def update_registries(files): except BaseException: print("{} not found".format(file)) - with open(file, 'w') as registry: + with open(file, "w") as registry: registry.write(REGISTRY_HEADER.format(namespace)) # Parse the Registry header info registry.write( "const Header header = {{\n" - " \"{json_dict[@Redfish.Copyright]}\",\n" - " \"{json_dict[@odata.type]}\",\n" - " \"{json_dict[Id]}\",\n" - " \"{json_dict[Name]}\",\n" - " \"{json_dict[Language]}\",\n" - " \"{json_dict[Description]}\",\n" - " \"{json_dict[RegistryPrefix]}\",\n" - " \"{json_dict[RegistryVersion]}\",\n" - " \"{json_dict[OwningEntity]}\",\n" + ' "{json_dict[@Redfish.Copyright]}",\n' + ' "{json_dict[@odata.type]}",\n' + ' "{json_dict[Id]}",\n' + ' "{json_dict[Name]}",\n' + ' "{json_dict[Language]}",\n' + ' "{json_dict[Description]}",\n' + ' "{json_dict[RegistryPrefix]}",\n' + ' "{json_dict[RegistryVersion]}",\n' + ' "{json_dict[OwningEntity]}",\n' "}};\n" "constexpr const char* url =\n" - " \"{url}\";\n" + ' "{url}";\n' "\n" "constexpr std::array registry =\n" "{{\n".format( json_dict=json_dict, url=url, - )) + ) + ) messages_sorted = sorted(json_dict["Messages"].items()) for messageId, message in messages_sorted: registry.write( " MessageEntry{{\n" - " \"{messageId}\",\n" + ' "{messageId}",\n' " {{\n" - " \"{message[Description]}\",\n" - " \"{message[Message]}\",\n" - " \"{message[MessageSeverity]}\",\n" + ' "{message[Description]}",\n' + ' "{message[Message]}",\n' + ' "{message[MessageSeverity]}",\n' " {message[NumberOfArgs]},\n" " {{".format( - messageId=messageId, - message=message - )) + messageId=messageId, message=message + ) + ) paramTypes = message.get("ParamTypes") if paramTypes: for paramType in paramTypes: registry.write( - "\n" - " \"{}\",".format(paramType) + '\n "{}",'.format(paramType) ) registry.write("\n },\n") else: registry.write("},\n") registry.write( - " \"{message[Resolution]}\",\n" - " }}}},\n".format(message=message)) + ' "{message[Resolution]}",\n' + " }}}},\n".format(message=message) + ) - registry.write( - "\n};\n" - "\n" - "enum class Index\n" - "{\n" - ) + registry.write("\n};\n\nenum class Index\n{\n") for index, (messageId, message) in enumerate(messages_sorted): messageId = messageId[0].lower() + messageId[1:] - registry.write( - " {} = {},\n".format(messageId, index)) + registry.write(" {} = {},\n".format(messageId, index)) registry.write( - "}};\n" - "}} // namespace redfish::registries::{}\n" - .format(namespace)) + "}};\n}} // namespace redfish::registries::{}\n".format( + namespace + ) + ) def get_privilege_string_from_list(privilege_list): @@ -138,9 +132,9 @@ def get_privilege_string_from_list(privilege_list): for privilege in privileges: if privilege == "NoAuth": continue - privilege_string += "\"" + privilege_string += '"' privilege_string += privilege - privilege_string += "\",\n" + privilege_string += '",\n' if privilege != "NoAuth": privilege_string = privilege_string[:-2] privilege_string += "}" @@ -158,7 +152,10 @@ def get_variable_name_for_privilege_set(privilege_list): return "Or".join(names) -PRIVILEGE_HEADER = PRAGMA_ONCE + WARNING + ''' +PRIVILEGE_HEADER = ( + PRAGMA_ONCE + + WARNING + + """ #include "privileges.hpp" #include @@ -167,29 +164,34 @@ PRIVILEGE_HEADER = PRAGMA_ONCE + WARNING + ''' namespace redfish::privileges { -''' +""" +) def make_privilege_registry(): - path, json_file, type_name, url = \ - make_getter('Redfish_1.3.0_PrivilegeRegistry.json', - 'privilege_registry.hpp', 'privilege') - with open(path, 'w') as registry: + path, json_file, type_name, url = make_getter( + "Redfish_1.3.0_PrivilegeRegistry.json", + "privilege_registry.hpp", + "privilege", + ) + with open(path, "w") as registry: registry.write(PRIVILEGE_HEADER) privilege_dict = {} for mapping in json_file["Mappings"]: # first pass, identify all the unique privilege sets for operation, privilege_list in mapping["OperationMap"].items(): - privilege_dict[get_privilege_string_from_list( - privilege_list)] = (privilege_list, ) + privilege_dict[ + get_privilege_string_from_list(privilege_list) + ] = (privilege_list,) for index, key in enumerate(privilege_dict): - (privilege_list, ) = privilege_dict[key] + (privilege_list,) = privilege_dict[key] name = get_variable_name_for_privilege_set(privilege_list) registry.write( "const std::array " - "privilegeSet{name} = {key};\n" - .format(length=len(privilege_list), name=name, key=key) + "privilegeSet{name} = {key};\n".format( + length=len(privilege_list), name=name, key=key + ) ) privilege_dict[key] = (privilege_list, name) @@ -198,26 +200,29 @@ def make_privilege_registry(): registry.write("// {}\n".format(entity)) for operation, privilege_list in mapping["OperationMap"].items(): privilege_string = get_privilege_string_from_list( - privilege_list) + privilege_list + ) operation = operation.lower() registry.write( "const static auto& {}{} = privilegeSet{};\n".format( - operation, - entity, - privilege_dict[privilege_string][1])) + operation, entity, privilege_dict[privilege_string][1] + ) + ) registry.write("\n") registry.write( - "} // namespace redfish::privileges\n" - "// clang-format on\n") + "} // namespace redfish::privileges\n// clang-format on\n" + ) def main(): parser = argparse.ArgumentParser() parser.add_argument( - '--registries', type=str, + "--registries", + type=str, default="base,task_event,resource_event,privilege", - help="Comma delimited list of registries to update") + help="Comma delimited list of registries to update", + ) args = parser.parse_args() @@ -225,17 +230,27 @@ def main(): files = [] if "base" in registries: - files.append(make_getter('Base.1.13.0.json', - 'base_message_registry.hpp', - 'base')) + files.append( + make_getter( + "Base.1.13.0.json", "base_message_registry.hpp", "base" + ) + ) if "task_event" in registries: - files.append(make_getter('TaskEvent.1.0.3.json', - 'task_event_message_registry.hpp', - 'task_event')) + files.append( + make_getter( + "TaskEvent.1.0.3.json", + "task_event_message_registry.hpp", + "task_event", + ) + ) if "resource_event" in registries: - files.append(make_getter('ResourceEvent.1.0.3.json', - 'resource_event_message_registry.hpp', - 'resource_event')) + files.append( + make_getter( + "ResourceEvent.1.0.3.json", + "resource_event_message_registry.hpp", + "resource_event", + ) + ) update_registries(files) diff --git a/scripts/update_schemas.py b/scripts/update_schemas.py index da9c3460f2..459d0457bd 100755 --- a/scripts/update_schemas.py +++ b/scripts/update_schemas.py @@ -1,14 +1,13 @@ #!/usr/bin/env python3 -import requests -import zipfile -from io import BytesIO -from packaging.version import parse - import os -from collections import OrderedDict, defaultdict import shutil - import xml.etree.ElementTree as ET +import zipfile +from collections import OrderedDict, defaultdict +from io import BytesIO + +import requests +from packaging.version import parse VERSION = "DSP8010_2022.2" @@ -42,7 +41,7 @@ include_list = [ "ComputerSystemCollection", "Drive", "DriveCollection", - 'EnvironmentMetrics', + "EnvironmentMetrics", "EthernetInterface", "EthernetInterfaceCollection", "Event", @@ -254,7 +253,6 @@ json_schema_files = OrderedDict( csdl_filenames.sort(key=version_sort_key) with open(metadata_index_path, "w") as metadata_index: - metadata_index.write('\n') metadata_index.write( "\n' ) else: metadata_index.write( - " " - '\n' ) @@ -392,6 +387,6 @@ with open(os.path.join(cpp_path, "schemas.hpp"), "w") as hpp_file: for schema_file in json_schema_files: hpp_file.write(' "{}",\n'.format(schema_file)) - hpp_file.write(" };\n" "}\n") + hpp_file.write(" };\n}\n") zip_ref.close() diff --git a/scripts/websocket_test.py b/scripts/websocket_test.py index 85b2c0d8ef..21c7f160b1 100755 --- a/scripts/websocket_test.py +++ b/scripts/websocket_test.py @@ -3,20 +3,23 @@ # Example of streaming sensor values from openbmc using the /subscribe api # requires websockets package to be installed +import argparse import asyncio -import ssl -import websockets import base64 import json -import argparse +import ssl + +import websockets parser = argparse.ArgumentParser() parser.add_argument("--host", help="Host to connect to", required=True) parser.add_argument( - "--username", help="Username to connect with", default="root") + "--username", help="Username to connect with", default="root" +) parser.add_argument("--password", help="Password to use", default="0penBmc") -parser.add_argument('--ssl', default=True, - action=argparse.BooleanOptionalAction) +parser.add_argument( + "--ssl", default=True, action=argparse.BooleanOptionalAction +) args = parser.parse_args() @@ -29,27 +32,30 @@ sensor_type_map = { "altitude": "Meters", "current": "Amps", "energy": "Joules", - "cfm": "CFM" + "cfm": "CFM", } async def hello(): - protocol = 'ws' + protocol = "ws" if args.ssl: - protocol += 's' - uri = '{}://{}/subscribe'.format(protocol, args.host) + protocol += "s" + uri = "{}://{}/subscribe".format(protocol, args.host) ssl_context = ssl.SSLContext() - authbytes = "{}:{}".format(args.username, args.password).encode('ascii') - auth = "Basic {}".format(base64.b64encode(authbytes).decode('ascii')) + authbytes = "{}:{}".format(args.username, args.password).encode("ascii") + auth = "Basic {}".format(base64.b64encode(authbytes).decode("ascii")) headers = {"Authorization": auth} - async with \ - websockets.connect(uri, ssl=ssl_context, extra_headers=headers) \ - if args.ssl else websockets.connect(uri, extra_headers=headers) \ - as websocket: - request = json.dumps({ - "paths": ["/xyz/openbmc_project/sensors"], - "interfaces": ["xyz.openbmc_project.Sensor.Value"] - }) + async with websockets.connect( + uri, ssl=ssl_context, extra_headers=headers + ) if args.ssl else websockets.connect( + uri, extra_headers=headers + ) as websocket: + request = json.dumps( + { + "paths": ["/xyz/openbmc_project/sensors"], + "interfaces": ["xyz.openbmc_project.Sensor.Value"], + } + ) await websocket.send(request) while True: -- cgit v1.2.3