python: fix flake8 warnings and format with black

Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I3a07938b0768e093d04abedeaf96b63b2e8e9ec7
diff --git a/create_error_reports.py b/create_error_reports.py
index d8264e1..c3e10da 100755
--- a/create_error_reports.py
+++ b/create_error_reports.py
@@ -1,6 +1,6 @@
 #!/usr/bin/env python3
 
-'''Generates 2 reports about OpenBMC error logs:
+"""Generates 2 reports about OpenBMC error logs:
 
     1) Dumps every error defined in the errors.yaml files passed in
        into a single JSON file that looks like:
@@ -19,21 +19,21 @@
     2) Crosschecks this generated JSON with the IBM error policy table,
        showing if any errors are in one file but not the other.
 
-'''
+"""
 
 import argparse
-import os
 import json
+import os
+
 import yaml
 
 
 def get_errors(yaml_dirs):
-    '''Finds all of the errors in all of the error YAML files in
-       the directories passed in.'''
+    """Finds all of the errors in all of the error YAML files in
+    the directories passed in."""
 
     all_errors = []
     for yaml_dir in yaml_dirs:
-        error_data = []
         yaml_files = get_yaml(yaml_dir)
 
         for yaml_file in yaml_files:
@@ -43,17 +43,17 @@
 
 
 def read_error_yaml(yaml_dir, yaml_file):
-    '''Returns a list of dictionary objects reflecting the error YAML.'''
+    """Returns a list of dictionary objects reflecting the error YAML."""
 
     all_errors = []
 
-    #xyz/openbmc_project/x.errors.yaml -> xyz.openbmc_project.x.Error
-    error_base = yaml_file.replace(os.sep, '.')
-    error_base = error_base.replace('.errors.yaml', '')
-    error_base += '.Error.'
+    # xyz/openbmc_project/x.errors.yaml -> xyz.openbmc_project.x.Error
+    error_base = yaml_file.replace(os.sep, ".")
+    error_base = error_base.replace(".errors.yaml", "")
+    error_base += ".Error."
 
-    #Also needs to look up the metadata from the .metadata.yaml files
-    metadata_file = yaml_file.replace('errors.yaml', 'metadata.yaml')
+    # Also needs to look up the metadata from the .metadata.yaml files
+    metadata_file = yaml_file.replace("errors.yaml", "metadata.yaml")
     metadata = []
 
     if os.path.exists(os.path.join(yaml_dir, metadata_file)):
@@ -65,80 +65,80 @@
 
         for e in data:
             error = {}
-            error['error'] = error_base + e['name']
-            error['desc'] = e['description']
-            error['metadata'] = get_metadata(e['name'], metadata)
-            error['file'] = yaml_file
+            error["error"] = error_base + e["name"]
+            error["desc"] = e["description"]
+            error["metadata"] = get_metadata(e["name"], metadata)
+            error["file"] = yaml_file
             all_errors.append(error)
 
     return all_errors
 
 
 def add_error(val):
-    '''Adds the '.Error' before the last segment of an error string.'''
-    dot = val.rfind('.')
-    return val[:dot] + '.Error' + val[dot:]
+    """Adds the '.Error' before the last segment of an error string."""
+    dot = val.rfind(".")
+    return val[:dot] + ".Error" + val[dot:]
 
 
 def get_metadata(name, metadata):
-    '''Finds metadata entries for the error in the metadata
-       dictionary parsed out of the *.metadata.yaml files.
+    """Finds metadata entries for the error in the metadata
+    dictionary parsed out of the *.metadata.yaml files.
 
-       The metadata YAML looks something like:
-            - name: SlaveDetectionFailure
-              meta:
-                - str: "ERRNO=%d"
-                  type: int32
-              inherits:
-                - xyz.openbmc_project.Callout
-      '''
+    The metadata YAML looks something like:
+         - name: SlaveDetectionFailure
+           meta:
+             - str: "ERRNO=%d"
+               type: int32
+           inherits:
+             - xyz.openbmc_project.Callout
+    """
 
     data = []
     for m in metadata:
-        if m['name'] == name:
-            if 'meta' in m:
-                for entry in m['meta']:
-                    #Get the name from name=value
-                    n = entry['str'].split('=')[0]
+        if m["name"] == name:
+            if "meta" in m:
+                for entry in m["meta"]:
+                    # Get the name from name=value
+                    n = entry["str"].split("=")[0]
                     data.append(n)
 
-            #inherits is a list, return it comma separated
-            if 'inherits' in m:
-                vals = list(map(add_error, m['inherits']))
-                i = ','.join(vals)
+            # inherits is a list, return it comma separated
+            if "inherits" in m:
+                vals = list(map(add_error, m["inherits"]))
+                i = ",".join(vals)
                 data.append("Inherits %s" % i)
 
     return data
 
 
 def get_yaml(yaml_dir):
-    '''Finds all of the *.errors.yaml files in the directory passed in.
-       Returns a list of entries like xyz/openbmc_project/Common.Errors.yaml.
-    '''
+    """Finds all of the *.errors.yaml files in the directory passed in.
+    Returns a list of entries like xyz/openbmc_project/Common.Errors.yaml.
+    """
 
     err_files = []
-    metadata_files = []
     if os.path.exists(yaml_dir):
         for directory, _, files in os.walk(yaml_dir):
             if not files:
                 continue
 
-            err_files += [os.path.relpath(
-                    os.path.join(directory, f), yaml_dir)
-                    for f in [f for f in files if f.endswith('.errors.yaml')]]
+            err_files += [
+                os.path.relpath(os.path.join(directory, f), yaml_dir)
+                for f in [f for f in files if f.endswith(".errors.yaml")]
+            ]
 
     return err_files
 
 
 def crosscheck(errors, policy, outfile):
-    '''Crosschecks that the errors found in the YAML are in the
-       policy file, and vice versa.
-    '''
+    """Crosschecks that the errors found in the YAML are in the
+    policy file, and vice versa.
+    """
 
-    policy_errors = [x['err'] for x in policy]
-    yaml_errors = [x['error'] for x in errors]
+    policy_errors = [x["err"] for x in policy]
+    yaml_errors = [x["error"] for x in errors]
 
-    out = open(outfile, 'w')
+    out = open(outfile, "w")
     out.write("YAML errors not in policy table:\n\n")
 
     for e in yaml_errors:
@@ -154,40 +154,55 @@
 
     num_details = 0
     for e in policy:
-        for d in e['dtls']:
+        for d in e["dtls"]:
             num_details += 1
 
-    out.write("\n%d total errors (with %d total details blocks) in the "
-              "policy table\n\n" % (len(policy_errors), num_details))
+    out.write(
+        "\n%d total errors (with %d total details blocks) in the "
+        "policy table\n\n" % (len(policy_errors), num_details)
+    )
 
-if __name__ == '__main__':
 
-    parser = argparse.ArgumentParser(description='Error log policy reports')
+if __name__ == "__main__":
+    parser = argparse.ArgumentParser(description="Error log policy reports")
 
-    parser.add_argument('-y', '--yaml_dirs',
-                        dest='yaml_dirs',
-                        default='.',
-                        help='Comma separated list of error YAML dirs')
-    parser.add_argument('-e', '--error_file',
-                        dest='error_file',
-                        default='obmc-errors.json',
-                        help='Output Error report file')
-    parser.add_argument('-p', '--policy',
-                        dest='policy_file',
-                        default='condensed.json',
-                        help='Condensed policy in JSON')
-    parser.add_argument('-x', '--crosscheck',
-                        dest='crosscheck_file',
-                        help='YAML vs policy table crosscheck output file')
+    parser.add_argument(
+        "-y",
+        "--yaml_dirs",
+        dest="yaml_dirs",
+        default=".",
+        help="Comma separated list of error YAML dirs",
+    )
+    parser.add_argument(
+        "-e",
+        "--error_file",
+        dest="error_file",
+        default="obmc-errors.json",
+        help="Output Error report file",
+    )
+    parser.add_argument(
+        "-p",
+        "--policy",
+        dest="policy_file",
+        default="condensed.json",
+        help="Condensed policy in JSON",
+    )
+    parser.add_argument(
+        "-x",
+        "--crosscheck",
+        dest="crosscheck_file",
+        help="YAML vs policy table crosscheck output file",
+    )
 
     args = parser.parse_args()
 
-    dirs = args.yaml_dirs.split(',')
+    dirs = args.yaml_dirs.split(",")
     errors = get_errors(dirs)
 
-    with open(args.error_file, 'w') as outfile:
-        json.dump(errors, outfile, sort_keys=True,
-                  indent=2, separators=(',', ':'))
+    with open(args.error_file, "w") as outfile:
+        json.dump(
+            errors, outfile, sort_keys=True, indent=2, separators=(",", ":")
+        )
 
     if args.crosscheck_file:
         with open(args.policy_file) as pf: