diff options
author | Ed Tanous <edtanous@google.com> | 2021-08-02 18:56:24 +0300 |
---|---|---|
committer | Gunnar Mills <gmills@us.ibm.com> | 2021-08-04 16:37:30 +0300 |
commit | f395daac96c8122623700c2b124d905266ea8223 (patch) | |
tree | df1b920625cbb108d978c0a76be04c6b0edd610b | |
parent | c21865c469cfc9dffdc15d87710293115cf6d9e4 (diff) | |
download | bmcweb-f395daac96c8122623700c2b124d905266ea8223.tar.xz |
Enable pycodestyle
This commit allows our python code to be run through the CI format-code
scripts. The exact content is copied from sdbusplus.
Tested, ran pycodeformat on each script, observed it passing.
Ran each script individually. check_base_registry seems broken previous
to this commit, although it provides the same output.
Signed-off-by: Ed Tanous <edtanous@google.com>
Change-Id: I7eacfa355b794f49308b900c2988809d2aa122c3
-rw-r--r-- | scripts/check_base_registry.py | 6 | ||||
-rwxr-xr-x | scripts/parse_registries.py | 39 | ||||
-rwxr-xr-x | scripts/update_schemas.py | 82 | ||||
-rwxr-xr-x | scripts/websocket_test.py | 4 | ||||
-rw-r--r-- | setup.cfg | 1 |
5 files changed, 85 insertions, 47 deletions
diff --git a/scripts/check_base_registry.py b/scripts/check_base_registry.py index 667f167026..ab4b2e66b8 100644 --- a/scripts/check_base_registry.py +++ b/scripts/check_base_registry.py @@ -32,12 +32,12 @@ with open(args.file) as error_file: error_info = error_data[index:index + 15] error_str = " ".join(error_info) error_str = re.sub( - 'std::to_string\(arg(\d+)\)', + 'std::to_string\\(arg(\\d+)\\)', 'arg\\1', error_str) - error_str = re.sub('"\n\s*"', '', error_str, re.MULTILINE) + error_str = re.sub('"\n\\s*"', '', error_str, re.MULTILINE) error_str = re.sub( - '"\s*\+\s*arg(\d+)\s*\+\n?\s*"', + '"\\s*\\+\\s*arg(\\d+)\\s*\\+\n?\\s*"', '%\\1', error_str, re.MULTILINE) diff --git a/scripts/parse_registries.py b/scripts/parse_registries.py index 3d66a0353c..0a7464b6fa 100755 --- a/scripts/parse_registries.py +++ b/scripts/parse_registries.py @@ -55,11 +55,14 @@ def clang_format(filename): files = [] files.append(make_getter('Base.1.10.0.json', - 'base_message_registry.hpp', 'base')) + 'base_message_registry.hpp', + 'base')) files.append(make_getter('TaskEvent.1.0.3.json', - 'task_event_message_registry.hpp', 'task_event')) + 'task_event_message_registry.hpp', + 'task_event')) files.append(make_getter('ResourceEvent.1.0.3.json', - 'resource_event_message_registry.hpp', 'resource_event')) + 'resource_event_message_registry.hpp', + 'resource_event')) # Remove the old files for file, json_dict, namespace, url in files: @@ -85,8 +88,9 @@ for file, json_dict, namespace, url in files: registry.write('constexpr const char * url = "{}";\n\n'.format(url)) # Parse each Message entry - registry.write("constexpr std::array<MessageEntry, {}> registry = {{".format( - len(json_dict["Messages"]))) + registry.write( + "constexpr std::array<MessageEntry, {}> registry = {{".format( + len(json_dict["Messages"]))) for messageId, message in sorted(json_dict["Messages"].items()): registry.write("MessageEntry{") registry.write("\"{}\",".format(messageId)) @@ -127,6 +131,7 @@ def get_privilege_string_from_list(privilege_list): privilege_string += "\n}}" return privilege_string + def get_variable_name_for_privilege_set(privilege_list): names = [] for privilege_json in privilege_list: @@ -134,12 +139,16 @@ def get_variable_name_for_privilege_set(privilege_list): names.append("And".join(privileges)) return "Or".join(names) + def make_privilege_registry(): - path, json_file, type_name, url = make_getter('Redfish_1.1.0_PrivilegeRegistry.json', - 'privilege_registry.hpp', 'privilege') + path, json_file, type_name, url = \ + make_getter('Redfish_1.1.0_PrivilegeRegistry.json', + 'privilege_registry.hpp', 'privilege') with open(path, 'w') as registry: registry.write("#pragma once\n") - registry.write("//{} is generated. Do not edit directly\n".format(os.path.basename(path))) + registry.write( + "//{} is generated. Do not edit directly\n".format( + os.path.basename(path))) registry.write("#include <privileges.hpp>\n\n") registry.write("namespace redfish::privileges{\n") @@ -154,8 +163,11 @@ def make_privilege_registry(): for index, key in enumerate(privilege_dict): (privilege_list, ) = privilege_dict[key] name = get_variable_name_for_privilege_set(privilege_list) - registry.write("const std::array<Privileges, {}> privilegeSet{} = {};\n".format( - len(privilege_list), name, key)) + registry.write( + "const std::array<Privileges, {}> ".format( + len(privilege_list))) + registry.write( + "privilegeSet{} = {};\n".format(name, key)) privilege_dict[key] = (privilege_list, name) registry.write("// clang-format on\n\n") @@ -167,8 +179,11 @@ def make_privilege_registry(): privilege_list) operation = operation.lower() - registry.write("const static auto& {}{} = privilegeSet{};\n".format( - operation, entity , privilege_dict[privilege_string][1])) + registry.write( + "const static auto& {}{} = privilegeSet{};\n".format( + operation, + entity, + privilege_dict[privilege_string][1])) registry.write("\n") registry.write("} // namespace redfish::privileges\n") clang_format(path) diff --git a/scripts/update_schemas.py b/scripts/update_schemas.py index ade0550670..3ce4173965 100755 --- a/scripts/update_schemas.py +++ b/scripts/update_schemas.py @@ -39,7 +39,7 @@ include_list = [ 'EventService', 'IPAddresses', 'JsonSchemaFile', - 'JsonSchemaFileCollection', #redfish/v1/JsonSchemas + 'JsonSchemaFileCollection', # redfish/v1/JsonSchemas 'LogEntry', 'LogEntryCollection', 'LogService', @@ -69,7 +69,7 @@ include_list = [ 'PCIeFunction', 'PCIeFunctionCollection', 'Power', - 'Privileges', #Used in Role + 'Privileges', # Used in Role 'Processor', 'ProcessorCollection', 'RedfishError', @@ -156,13 +156,14 @@ with open(metadata_index_path, 'w') as metadata_index: metadata_index.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n") metadata_index.write( - "<edmx:Edmx xmlns:edmx=\"http://docs.oasis-open.org/odata/ns/edmx\" Version=\"4.0\">\n") + "<edmx:Edmx xmlns:edmx=" + "\"http://docs.oasis-open.org/odata/ns/edmx\"" + " Version=\"4.0\">\n") for zip_filepath in zip_ref.namelist(): - if zip_filepath.startswith(VERSION + - '/csdl/') & (zip_filepath != VERSION + - "/csdl/") & (zip_filepath != VERSION + - "/csdl/"): + if zip_filepath.startswith(VERSION + '/csdl/') and \ + (zip_filepath != VERSION + "/csdl/") and \ + (zip_filepath != VERSION + "/csdl/"): filename = os.path.basename(zip_filepath) # filename looks like Zone_v1.xml @@ -171,7 +172,7 @@ with open(metadata_index_path, 'w') as metadata_index: print("excluding schema: " + filename) continue - with open(os.path.join(schema_path, filename), 'wb') as schema_file: + with open(os.path.join(schema_path, filename), 'wb') as schema_out: metadata_index.write( " <edmx:Reference Uri=\"/redfish/v1/schema/" + @@ -181,29 +182,38 @@ with open(metadata_index_path, 'w') as metadata_index: content = zip_ref.read(zip_filepath) content = content.replace(b'\r\n', b'\n') xml_root = ET.fromstring(content) - + edmx = "{http://docs.oasis-open.org/odata/ns/edmx}" for edmx_child in xml_root: - - if edmx_child.tag == "{http://docs.oasis-open.org/odata/ns/edmx}DataServices": + if edmx_child.tag == edmx + "DataServices": for data_child in edmx_child: - if data_child.tag == "{http://docs.oasis-open.org/odata/ns/edm}Schema": + if data_child.tag == edmx + "Schema": namespace = data_child.attrib["Namespace"] if namespace.startswith("RedfishExtensions"): metadata_index.write( - " <edmx:Include Namespace=\"" + namespace + "\" Alias=\"Redfish\"/>\n") + " " + "<edmx:Include Namespace=\"" + + namespace + + "\" Alias=\"Redfish\"/>\n" + ) else: metadata_index.write( - " <edmx:Include Namespace=\"" + namespace + "\"/>\n") - schema_file.write(content) + " " + "<edmx:Include Namespace=\"" + + namespace + "\"/>\n" + ) + schema_out.write(content) metadata_index.write(" </edmx:Reference>\n") - metadata_index.write(""" <edmx:DataServices> - <Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="Service"> - <EntityContainer Name="Service" Extends="ServiceRoot.v1_0_0.ServiceContainer"/> - </Schema> - </edmx:DataServices> -""") + metadata_index.write(" <edmx:DataServices>\n" + " <Schema " + "xmlns=\"http://docs.oasis-open.org/odata/ns/edm\" " + "Namespace=\"Service\">\n" + " <EntityContainer Name=\"Service\" " + "Extends=\"ServiceRoot.v1_0_0.ServiceContainer\"/>\n" + " </Schema>\n" + " </edmx:DataServices>\n" + ) # TODO:Issue#32 There's a bug in the script that currently deletes this # schema (because it's an OEM schema). Because it's the only six, and we # don't update schemas very often, we just manually fix it. Need a @@ -214,26 +224,35 @@ with open(metadata_index_path, 'w') as metadata_index: metadata_index.write(" </edmx:Reference>\n") metadata_index.write( - " <edmx:Reference Uri=\"/redfish/v1/schema/OemComputerSystem_v1.xml\">\n") - metadata_index.write(" <edmx:Include Namespace=\"OemComputerSystem\"/>\n") + " <edmx:Reference Uri=\"" + "/redfish/v1/schema/OemComputerSystem_v1.xml\">\n") + metadata_index.write( + " <edmx:Include Namespace=\"OemComputerSystem\"/>\n") metadata_index.write(" </edmx:Reference>\n") metadata_index.write( - " <edmx:Reference Uri=\"/redfish/v1/schema/OemVirtualMedia_v1.xml\">\n") - metadata_index.write(" <edmx:Include Namespace=\"OemVirtualMedia\"/>\n") - metadata_index.write(" <edmx:Include Namespace=\"OemVirtualMedia.v1_0_0\"/>\n") + " <edmx:Reference Uri=\"" + "/redfish/v1/schema/OemVirtualMedia_v1.xml\">\n") + metadata_index.write( + " <edmx:Include Namespace=\"OemVirtualMedia\"/>\n") + metadata_index.write( + " <edmx:Include Namespace=\"OemVirtualMedia.v1_0_0\"/>\n") metadata_index.write(" </edmx:Reference>\n") metadata_index.write( - " <edmx:Reference Uri=\"/redfish/v1/schema/OemAccountService_v1.xml\">\n") - metadata_index.write(" <edmx:Include Namespace=\"OemAccountService\"/>\n") - metadata_index.write(" <edmx:Include Namespace=\"OemAccountService.v1_0_0\"/>\n") + " <edmx:Reference Uri=\"" + "/redfish/v1/schema/OemAccountService_v1.xml\">\n") + metadata_index.write( + " <edmx:Include Namespace=\"OemAccountService\"/>\n") + metadata_index.write( + " <edmx:Include Namespace=\"OemAccountService.v1_0_0\"/>\n") metadata_index.write(" </edmx:Reference>\n") metadata_index.write( " <edmx:Reference Uri=\"/redfish/v1/schema/OemSession_v1.xml\">\n") metadata_index.write(" <edmx:Include Namespace=\"OemSession\"/>\n") - metadata_index.write(" <edmx:Include Namespace=\"OemSession.v1_0_0\"/>\n") + metadata_index.write( + " <edmx:Include Namespace=\"OemSession.v1_0_0\"/>\n") metadata_index.write(" </edmx:Reference>\n") metadata_index.write("</edmx:Edmx>\n") @@ -272,7 +291,8 @@ for schema, version in schema_files.items(): "/redfish/v1/JsonSchemas/" + schema + "/" + schema + ".json") index_json = OrderedDict() - index_json["@odata.context"] = "/redfish/v1/$metadata#JsonSchemaFile.JsonSchemaFile" + index_json["@odata.context"] = \ + "/redfish/v1/$metadata#JsonSchemaFile.JsonSchemaFile" index_json["@odata.id"] = "/redfish/v1/JsonSchemas/" + schema index_json["@odata.type"] = "#JsonSchemaFile.v1_0_2.JsonSchemaFile" index_json["Name"] = schema + " Schema File" diff --git a/scripts/websocket_test.py b/scripts/websocket_test.py index f99ddac8ea..c76a0141d6 100755 --- a/scripts/websocket_test.py +++ b/scripts/websocket_test.py @@ -37,7 +37,9 @@ async def hello(): 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) as websocket: + async with \ + websockets.connect(uri, ssl=ssl_context, extra_headers=headers) \ + as websocket: request = json.dumps({ "paths": ["/xyz/openbmc_project/sensors"], "interfaces": ["xyz.openbmc_project.Sensor.Value"] diff --git a/setup.cfg b/setup.cfg new file mode 100644 index 0000000000..d9fc1485f5 --- /dev/null +++ b/setup.cfg @@ -0,0 +1 @@ +# Empty config to trigger pycodestyle. |