python: fix flake8 warnings and format with black
Most of the flake8 warnings in this repository were fairly trivial,
so fixed them. The "openbmctool" is 7000+ lines of pretty heavily
warned code, so just disabling that one. Format everything with
black.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: Icb3f6ee9bf03dece58785f7af00617c87a84aa65
diff --git a/dbusView/dbusView.py b/dbusView/dbusView.py
index fa2396d..a8e357f 100755
--- a/dbusView/dbusView.py
+++ b/dbusView/dbusView.py
@@ -3,94 +3,98 @@
# SPDX-License-Identifier: Apache-2.0
# Copyright 2020 Intel Corp.
-import subprocess
-from flask import Flask
-from flask import send_file
import argparse
+import subprocess
-REPLACE_CHAR = '~'
+from flask import Flask
+
+REPLACE_CHAR = "~"
app = Flask(__name__)
-parser = argparse.ArgumentParser(description='Remote DBus Viewer')
-parser.add_argument('-u', '--username', default='root')
-parser.add_argument('-p', '--password', default='0penBmc')
-parser.add_argument('-a', '--address', required=True)
-parser.add_argument('-x', '--port', required=True)
+parser = argparse.ArgumentParser(description="Remote DBus Viewer")
+parser.add_argument("-u", "--username", default="root")
+parser.add_argument("-p", "--password", default="0penBmc")
+parser.add_argument("-a", "--address", required=True)
+parser.add_argument("-x", "--port", required=True)
args = parser.parse_args()
-busctl = 'sshpass -p {} busctl -H {}@{} '.format(
- args.password, args.username, args.address)
-header = '<head><link rel="icon" href="https://avatars1.githubusercontent.com/u/13670043?s=200&v=4" /></head>'
+busctl = "sshpass -p {} busctl -H {}@{} ".format(
+ args.password, args.username, args.address
+)
+AVATAR_URL = "https://avatars1.githubusercontent.com/u/13670043?s=200&v=4"
+header = f'<head><link rel="icon" href="{AVATAR_URL}" /></head>'
def getBusNames():
- out = subprocess.check_output(busctl + 'list --acquired', shell=True)
- out = out.split(b'\n')
+ out = subprocess.check_output(busctl + "list --acquired", shell=True)
+ out = out.split(b"\n")
out = out[1:]
names = []
for line in out:
- name = line.split(b' ')[0]
+ name = line.split(b" ")[0]
if name:
names.append(name.decode())
return names
def doTree(busname):
- out = subprocess.check_output(busctl + 'tree ' + busname, shell=True)
- out = out.split(b'\n')
+ out = subprocess.check_output(busctl + "tree " + busname, shell=True)
+ out = out.split(b"\n")
tree = []
for line in out:
- path = line.split(b'/', 1)[-1].decode()
- path = '/' + path
+ path = line.split(b"/", 1)[-1].decode()
+ path = "/" + path
tree.append(path)
return tree
def doIntrospect(busname, path):
out = subprocess.check_output(
- busctl + 'introspect {} {}'.format(busname, path), shell=True)
- return out.decode().split('\n')
+ busctl + "introspect {} {}".format(busname, path), shell=True
+ )
+ return out.decode().split("\n")
-@app.route('/')
+@app.route("/")
def root():
out = header
- out += '<div><H2>Bus Names {}</H2></div>'.format(args.address)
+ out += "<div><H2>Bus Names {}</H2></div>".format(args.address)
for name in getBusNames():
- out += '<div> '
+ out += "<div> "
out += '<a href="{}"> {} </a>'.format(name, name)
- out += '</div>'
+ out += "</div>"
return out
-@app.route('/favicon.ico')
+@app.route("/favicon.ico")
def favicon():
- return '<link rel="icon" type="image/png" href="https://avatars1.githubusercontent.com/u/13670043?s=200&v=4" />'
+ return f'<link rel="icon" type="image/png" href="{AVATAR_URL}" />'
-@app.route('/<name>')
+@app.route("/<name>")
def busname(name):
out = header
- out += '<div><H2>tree {}</H2></div>'.format(name)
+ out += "<div><H2>tree {}</H2></div>".format(name)
for path in doTree(name):
- out += '<div> '
+ out += "<div> "
out += '<a href="{}/{}"> {} </a>'.format(
- name, path.replace('/', REPLACE_CHAR), path)
- out += '</div>'
+ name, path.replace("/", REPLACE_CHAR), path
+ )
+ out += "</div>"
return out
-@app.route('/<name>/<path>')
+@app.route("/<name>/<path>")
def path(name, path):
- path = path.replace(REPLACE_CHAR, '/')
+ path = path.replace(REPLACE_CHAR, "/")
out = header
- out += '<div><H2>introspect {} {}</H2></div>'.format(name, path)
+ out += "<div><H2>introspect {} {}</H2></div>".format(name, path)
for line in doIntrospect(name, path):
- out += '<div> '
- out += '<pre> {} </pre>'.format(line)
- out += '</div>'
+ out += "<div> "
+ out += "<pre> {} </pre>".format(line)
+ out += "</div>"
return out
-app.run(port=args.port, host='0.0.0.0')
+app.run(port=args.port, host="0.0.0.0")