black: re-format
black and isort are enabled in the openbmc-build-scripts on Python files
to have a consistent formatting. Re-run the formatter on the whole
repository.
Signed-off-by: Patrick Williams <patrick@stwcx.xyz>
Change-Id: I944f1915ece753f72a3fa654902d445a9749d0f9
diff --git a/bin/auto_status_file.py b/bin/auto_status_file.py
index d1614f3..c3f2544 100755
--- a/bin/auto_status_file.py
+++ b/bin/auto_status_file.py
@@ -4,86 +4,101 @@
See help text for details.
"""
-import sys
-import subprocess
import re
+import subprocess
+import sys
save_dir_path = sys.path.pop(0)
-modules = ['gen_arg', 'gen_print', 'gen_valid', 'gen_misc', 'gen_cmd', 'var_funcs']
+modules = [
+ "gen_arg",
+ "gen_print",
+ "gen_valid",
+ "gen_misc",
+ "gen_cmd",
+ "var_funcs",
+]
for module in modules:
exec("from " + module + " import *")
sys.path.insert(0, save_dir_path)
parser = argparse.ArgumentParser(
- usage='%(prog)s [OPTIONS]',
+ usage="%(prog)s [OPTIONS]",
description="%(prog)s will create a status file path name adhering to the"
- + " following pattern: <status dir path>/<prefix>.yymmdd."
- + "hhmmss.status. It will then run the command string and"
- + " direct its stdout/stderr to the status file and optionally"
- + " to stdout. This dual output streaming will be"
- + " accomplished using either the \"script\" or the \"tee\""
- + " program. %(prog)s will also set and export environment"
- + " variable \"AUTO_STATUS_FILE_PATH\" for the benefit of"
- + " child programs.",
+ + " following pattern: <status dir path>/<prefix>.yymmdd."
+ + "hhmmss.status. It will then run the command string and"
+ + " direct its stdout/stderr to the status file and optionally"
+ + " to stdout. This dual output streaming will be"
+ + ' accomplished using either the "script" or the "tee"'
+ + " program. %(prog)s will also set and export environment"
+ + ' variable "AUTO_STATUS_FILE_PATH" for the benefit of'
+ + " child programs.",
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
- prefix_chars='-+')
+ prefix_chars="-+",
+)
parser.add_argument(
- '--status_dir_path',
- default='',
+ "--status_dir_path",
+ default="",
help="The path to the directory where the status file will be created."
- + "%(default)s The default value is obtained from environment"
- + " variable \"${STATUS_DIR_PATH}\", if set or from \"${HOME}/"
- + "status/\".")
+ + "%(default)s The default value is obtained from environment"
+ + ' variable "${STATUS_DIR_PATH}", if set or from "${HOME}/'
+ + 'status/".',
+)
parser.add_argument(
- '--prefix',
- default='',
+ "--prefix",
+ default="",
help="The prefix for the generated file name.%(default)s The default value"
- + " is the command portion (i.e. the first token) of the command"
- + " string.")
+ + " is the command portion (i.e. the first token) of the command"
+ + " string.",
+)
parser.add_argument(
- '--status_file_name',
- default='',
+ "--status_file_name",
+ default="",
help="This allows the user to explicitly specify the status file name. If"
- + " this argument is not used, %(prog)s composes a status file name."
- + " If this argument is specified, the \"--prefix\" argument is"
- + " ignored.")
+ + " this argument is not used, %(prog)s composes a status file name."
+ + ' If this argument is specified, the "--prefix" argument is'
+ + " ignored.",
+)
parser.add_argument(
- '--stdout',
+ "--stdout",
default=1,
type=int,
choices=[1, 0],
help="Indicates that stdout/stderr from the command string execution"
- + " should be written to stdout as well as to the status file.")
+ + " should be written to stdout as well as to the status file.",
+)
parser.add_argument(
- '--tee',
+ "--tee",
default=1,
type=int,
choices=[1, 0],
- help="Indicates that \"tee\" rather than \"script\" should be used.")
+ help='Indicates that "tee" rather than "script" should be used.',
+)
parser.add_argument(
- '--show_url',
+ "--show_url",
default=0,
type=int,
choices=[1, 0],
help="Indicates that the status file path shown should be shown in the"
- + " form of a url. If the output is to be viewed from a browser,"
- + " this may well become a clickable link. Note that the"
- + " get_file_path_url.py program must be found in the \"PATH\""
- + " environment variable for this argument to be effective.")
+ + " form of a url. If the output is to be viewed from a browser,"
+ + " this may well become a clickable link. Note that the"
+ + ' get_file_path_url.py program must be found in the "PATH"'
+ + " environment variable for this argument to be effective.",
+)
parser.add_argument(
- 'command_string',
- default='',
- nargs='*',
- help="The command string to be run.%(default)s")
+ "command_string",
+ default="",
+ nargs="*",
+ help="The command string to be run.%(default)s",
+)
# Populate stock_list with options we want.
stock_list = [("test_mode", 0), ("quiet", 1), ("debug", 0)]
@@ -103,9 +118,9 @@
valid_value(command_string)
if status_dir_path == "":
- status_dir_path = \
- os.environ.get("STATUS_DIR_PATH",
- os.environ.get("HOME") + "/status/")
+ status_dir_path = os.environ.get(
+ "STATUS_DIR_PATH", os.environ.get("HOME") + "/status/"
+ )
status_dir_path = add_trailing_slash(status_dir_path)
set_pgm_arg(status_dir_path)
valid_dir_path(status_dir_path)
@@ -126,9 +141,9 @@
status_file_path = status_dir_path + status_file_name
# Set environment variable for the benefit of child programs.
- os.environ['AUTO_STATUS_FILE_PATH'] = status_file_path
+ os.environ["AUTO_STATUS_FILE_PATH"] = status_file_path
# Set deprecated but still used AUTOSCRIPT_STATUS_FILE_PATH value.
- os.environ['AUTOSCRIPT_STATUS_FILE_PATH'] = status_file_path
+ os.environ["AUTOSCRIPT_STATUS_FILE_PATH"] = status_file_path
def script_func(command_string, status_file_path):
@@ -141,9 +156,15 @@
status_file_path The path to the status file which is to contain a copy of all stdout.
"""
- cmd_buf = "script -a -q -f " + status_file_path + " -c '" \
- + escape_bash_quotes(command_string) + " ; printf \"\\n" \
- + sprint_varx(ret_code_str, "${?}").rstrip("\n") + "\\n\"'"
+ cmd_buf = (
+ "script -a -q -f "
+ + status_file_path
+ + " -c '"
+ + escape_bash_quotes(command_string)
+ + ' ; printf "\\n'
+ + sprint_varx(ret_code_str, "${?}").rstrip("\n")
+ + "\\n\"'"
+ )
qprint_issuing(cmd_buf)
sub_proc = subprocess.Popen(cmd_buf, shell=True)
sub_proc.communicate()
@@ -152,8 +173,13 @@
# Retrieve return code by examining ret_code_str output statement from status file.
# Example text to be analyzed.
# auto_status_file_ret_code: 127
- cmd_buf = "tail -n 10 " + status_file_path + " | egrep -a \"" \
- + ret_code_str + ":[ ]+\""
+ cmd_buf = (
+ "tail -n 10 "
+ + status_file_path
+ + ' | egrep -a "'
+ + ret_code_str
+ + ':[ ]+"'
+ )
rc, output = shell_cmd(cmd_buf)
key, value = parse_key_value(output)
shell_rc = int(value)
@@ -170,8 +196,12 @@
status_file_path The path to the status file which is to contain a copy of all stdout.
"""
- cmd_buf = "set -o pipefail ; " + command_string + " 2>&1 | tee -a " \
+ cmd_buf = (
+ "set -o pipefail ; "
+ + command_string
+ + " 2>&1 | tee -a "
+ status_file_path
+ )
qprint_issuing(cmd_buf)
sub_proc = subprocess.Popen(cmd_buf, shell=True)
sub_proc.communicate()
@@ -187,10 +217,11 @@
def main():
-
gen_setup()
- set_term_options(term_requests={'pgm_names': [command_string.split(" ")[0]]})
+ set_term_options(
+ term_requests={"pgm_names": [command_string.split(" ")[0]]}
+ )
global ret_code_str
ret_code_str = re.sub("\\.py$", "", pgm_name) + "_ret_code"
@@ -202,8 +233,9 @@
show_url = 0
set_pgm_arg(show_url)
else:
- shell_rc, status_file_url = shell_cmd("get_file_path_url.py "
- + status_file_path)
+ shell_rc, status_file_url = shell_cmd(
+ "get_file_path_url.py " + status_file_path
+ )
status_file_url = status_file_url.rstrip("\n")
# Print status file path/url to stdout and to status file.