python: fix flake8 warnings and format with black
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I3a07938b0768e093d04abedeaf96b63b2e8e9ec7
diff --git a/condense_policy.py b/condense_policy.py
index 4614781..70c2c98 100755
--- a/condense_policy.py
+++ b/condense_policy.py
@@ -1,6 +1,6 @@
#!/usr/bin/env python3
-'''Condenses the error policy table down to only the fields used by
+"""Condenses the error policy table down to only the fields used by
the BMC Code.
This script pulls the following 4 fields out of the full JSON policy
@@ -35,83 +35,91 @@
],
"err":"xyz.openbmc_project.Thermal.Error.PowerSupplyHot"
}
-'''
+"""
import argparse
-import sys
import json
def add_details(error, details, condensed):
- '''Adds a details entry to an error'''
+ """Adds a details entry to an error"""
found = False
for errors in condensed:
- if errors['err'] == error:
- errors['dtls'].append(details)
+ if errors["err"] == error:
+ errors["dtls"].append(details)
found = True
break
if not found:
group = {}
- group['err'] = error
- group['dtls'] = []
- group['dtls'].append(details)
+ group["err"] = error
+ group["dtls"] = []
+ group["dtls"].append(details)
condensed.append(group)
-if __name__ == '__main__':
+if __name__ == "__main__":
+ parser = argparse.ArgumentParser(description="Error log policy condenser")
- parser = argparse.ArgumentParser(description='Error log policy condenser')
-
- parser.add_argument('-p', '--policy',
- dest='policy_file',
- default='policyTable.json',
- help='Policy Table in JSON')
- parser.add_argument('-c', '--condensed_policy',
- dest='condensed_file',
- default='condensed.json',
- help='Condensed policy output file in JSON')
- parser.add_argument('-t', '--prettify_json',
- dest='prettify',
- default=False,
- action='store_true',
- help='Prettify the output JSON')
+ parser.add_argument(
+ "-p",
+ "--policy",
+ dest="policy_file",
+ default="policyTable.json",
+ help="Policy Table in JSON",
+ )
+ parser.add_argument(
+ "-c",
+ "--condensed_policy",
+ dest="condensed_file",
+ default="condensed.json",
+ help="Condensed policy output file in JSON",
+ )
+ parser.add_argument(
+ "-t",
+ "--prettify_json",
+ dest="prettify",
+ default=False,
+ action="store_true",
+ help="Prettify the output JSON",
+ )
args = parser.parse_args()
- with open(args.policy_file, 'r') as table:
+ with open(args.policy_file, "r") as table:
contents = json.load(table)
- policytable = contents['events']
+ policytable = contents["events"]
condensed = []
for name in policytable:
details = {}
- #Parse the error||modifer line. The modifier is optional.
- separatorPos = name.find('||')
+ # Parse the error||modifer line. The modifier is optional.
+ separatorPos = name.find("||")
if separatorPos != -1:
error = name[0:separatorPos]
modifier = name[separatorPos + 2:]
- details['mod'] = modifier
+ details["mod"] = modifier
else:
error = name
- details['mod'] = ''
+ details["mod"] = ""
- #The table has some nonBMC errors - they have spaces - skip them
- if ' ' in error:
+ # The table has some nonBMC errors - they have spaces - skip them
+ if " " in error:
print("Skipping error %s because of spaces" % error)
continue
- details['msg'] = policytable[name]['Message']
- details['CEID'] = policytable[name]['CommonEventID']
+ details["msg"] = policytable[name]["Message"]
+ details["CEID"] = policytable[name]["CommonEventID"]
add_details(error, details, condensed)
- #if prettified there will be newlines
+ # if prettified there will be newlines
indent_value = 2 if args.prettify else None
- with open(args.condensed_file, 'w') as outfile:
- json.dump(condensed, outfile, separators=(',', ':'),
- indent=indent_value)
+ with open(args.condensed_file, "w") as outfile:
+ json.dump(
+ condensed, outfile, separators=(",", ":"), indent=indent_value
+ )