Skip to content

Commit 20f3871

Browse files
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 <[email protected]> Change-Id: I944f1915ece753f72a3fa654902d445a9749d0f9
1 parent 999964d commit 20f3871

File tree

103 files changed

+8583
-5807
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

103 files changed

+8583
-5807
lines changed

bin/auto_status_file.py

+87-55
Original file line numberDiff line numberDiff line change
@@ -4,86 +4,101 @@
44
See help text for details.
55
"""
66

7-
import sys
8-
import subprocess
97
import re
8+
import subprocess
9+
import sys
1010

1111
save_dir_path = sys.path.pop(0)
1212

13-
modules = ['gen_arg', 'gen_print', 'gen_valid', 'gen_misc', 'gen_cmd', 'var_funcs']
13+
modules = [
14+
"gen_arg",
15+
"gen_print",
16+
"gen_valid",
17+
"gen_misc",
18+
"gen_cmd",
19+
"var_funcs",
20+
]
1421
for module in modules:
1522
exec("from " + module + " import *")
1623

1724
sys.path.insert(0, save_dir_path)
1825

1926
parser = argparse.ArgumentParser(
20-
usage='%(prog)s [OPTIONS]',
27+
usage="%(prog)s [OPTIONS]",
2128
description="%(prog)s will create a status file path name adhering to the"
22-
+ " following pattern: <status dir path>/<prefix>.yymmdd."
23-
+ "hhmmss.status. It will then run the command string and"
24-
+ " direct its stdout/stderr to the status file and optionally"
25-
+ " to stdout. This dual output streaming will be"
26-
+ " accomplished using either the \"script\" or the \"tee\""
27-
+ " program. %(prog)s will also set and export environment"
28-
+ " variable \"AUTO_STATUS_FILE_PATH\" for the benefit of"
29-
+ " child programs.",
29+
+ " following pattern: <status dir path>/<prefix>.yymmdd."
30+
+ "hhmmss.status. It will then run the command string and"
31+
+ " direct its stdout/stderr to the status file and optionally"
32+
+ " to stdout. This dual output streaming will be"
33+
+ ' accomplished using either the "script" or the "tee"'
34+
+ " program. %(prog)s will also set and export environment"
35+
+ ' variable "AUTO_STATUS_FILE_PATH" for the benefit of'
36+
+ " child programs.",
3037
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
31-
prefix_chars='-+')
38+
prefix_chars="-+",
39+
)
3240

3341
parser.add_argument(
34-
'--status_dir_path',
35-
default='',
42+
"--status_dir_path",
43+
default="",
3644
help="The path to the directory where the status file will be created."
37-
+ "%(default)s The default value is obtained from environment"
38-
+ " variable \"${STATUS_DIR_PATH}\", if set or from \"${HOME}/"
39-
+ "status/\".")
45+
+ "%(default)s The default value is obtained from environment"
46+
+ ' variable "${STATUS_DIR_PATH}", if set or from "${HOME}/'
47+
+ 'status/".',
48+
)
4049

4150
parser.add_argument(
42-
'--prefix',
43-
default='',
51+
"--prefix",
52+
default="",
4453
help="The prefix for the generated file name.%(default)s The default value"
45-
+ " is the command portion (i.e. the first token) of the command"
46-
+ " string.")
54+
+ " is the command portion (i.e. the first token) of the command"
55+
+ " string.",
56+
)
4757

4858
parser.add_argument(
49-
'--status_file_name',
50-
default='',
59+
"--status_file_name",
60+
default="",
5161
help="This allows the user to explicitly specify the status file name. If"
52-
+ " this argument is not used, %(prog)s composes a status file name."
53-
+ " If this argument is specified, the \"--prefix\" argument is"
54-
+ " ignored.")
62+
+ " this argument is not used, %(prog)s composes a status file name."
63+
+ ' If this argument is specified, the "--prefix" argument is'
64+
+ " ignored.",
65+
)
5566

5667
parser.add_argument(
57-
'--stdout',
68+
"--stdout",
5869
default=1,
5970
type=int,
6071
choices=[1, 0],
6172
help="Indicates that stdout/stderr from the command string execution"
62-
+ " should be written to stdout as well as to the status file.")
73+
+ " should be written to stdout as well as to the status file.",
74+
)
6375

6476
parser.add_argument(
65-
'--tee',
77+
"--tee",
6678
default=1,
6779
type=int,
6880
choices=[1, 0],
69-
help="Indicates that \"tee\" rather than \"script\" should be used.")
81+
help='Indicates that "tee" rather than "script" should be used.',
82+
)
7083

7184
parser.add_argument(
72-
'--show_url',
85+
"--show_url",
7386
default=0,
7487
type=int,
7588
choices=[1, 0],
7689
help="Indicates that the status file path shown should be shown in the"
77-
+ " form of a url. If the output is to be viewed from a browser,"
78-
+ " this may well become a clickable link. Note that the"
79-
+ " get_file_path_url.py program must be found in the \"PATH\""
80-
+ " environment variable for this argument to be effective.")
90+
+ " form of a url. If the output is to be viewed from a browser,"
91+
+ " this may well become a clickable link. Note that the"
92+
+ ' get_file_path_url.py program must be found in the "PATH"'
93+
+ " environment variable for this argument to be effective.",
94+
)
8195

8296
parser.add_argument(
83-
'command_string',
84-
default='',
85-
nargs='*',
86-
help="The command string to be run.%(default)s")
97+
"command_string",
98+
default="",
99+
nargs="*",
100+
help="The command string to be run.%(default)s",
101+
)
87102

88103
# Populate stock_list with options we want.
89104
stock_list = [("test_mode", 0), ("quiet", 1), ("debug", 0)]
@@ -103,9 +118,9 @@ def validate_parms():
103118
valid_value(command_string)
104119

105120
if status_dir_path == "":
106-
status_dir_path = \
107-
os.environ.get("STATUS_DIR_PATH",
108-
os.environ.get("HOME") + "/status/")
121+
status_dir_path = os.environ.get(
122+
"STATUS_DIR_PATH", os.environ.get("HOME") + "/status/"
123+
)
109124
status_dir_path = add_trailing_slash(status_dir_path)
110125
set_pgm_arg(status_dir_path)
111126
valid_dir_path(status_dir_path)
@@ -126,9 +141,9 @@ def validate_parms():
126141

127142
status_file_path = status_dir_path + status_file_name
128143
# Set environment variable for the benefit of child programs.
129-
os.environ['AUTO_STATUS_FILE_PATH'] = status_file_path
144+
os.environ["AUTO_STATUS_FILE_PATH"] = status_file_path
130145
# Set deprecated but still used AUTOSCRIPT_STATUS_FILE_PATH value.
131-
os.environ['AUTOSCRIPT_STATUS_FILE_PATH'] = status_file_path
146+
os.environ["AUTOSCRIPT_STATUS_FILE_PATH"] = status_file_path
132147

133148

134149
def script_func(command_string, status_file_path):
@@ -141,9 +156,15 @@ def script_func(command_string, status_file_path):
141156
status_file_path The path to the status file which is to contain a copy of all stdout.
142157
"""
143158

144-
cmd_buf = "script -a -q -f " + status_file_path + " -c '" \
145-
+ escape_bash_quotes(command_string) + " ; printf \"\\n" \
146-
+ sprint_varx(ret_code_str, "${?}").rstrip("\n") + "\\n\"'"
159+
cmd_buf = (
160+
"script -a -q -f "
161+
+ status_file_path
162+
+ " -c '"
163+
+ escape_bash_quotes(command_string)
164+
+ ' ; printf "\\n'
165+
+ sprint_varx(ret_code_str, "${?}").rstrip("\n")
166+
+ "\\n\"'"
167+
)
147168
qprint_issuing(cmd_buf)
148169
sub_proc = subprocess.Popen(cmd_buf, shell=True)
149170
sub_proc.communicate()
@@ -152,8 +173,13 @@ def script_func(command_string, status_file_path):
152173
# Retrieve return code by examining ret_code_str output statement from status file.
153174
# Example text to be analyzed.
154175
# auto_status_file_ret_code: 127
155-
cmd_buf = "tail -n 10 " + status_file_path + " | egrep -a \"" \
156-
+ ret_code_str + ":[ ]+\""
176+
cmd_buf = (
177+
"tail -n 10 "
178+
+ status_file_path
179+
+ ' | egrep -a "'
180+
+ ret_code_str
181+
+ ':[ ]+"'
182+
)
157183
rc, output = shell_cmd(cmd_buf)
158184
key, value = parse_key_value(output)
159185
shell_rc = int(value)
@@ -170,8 +196,12 @@ def tee_func(command_string, status_file_path):
170196
status_file_path The path to the status file which is to contain a copy of all stdout.
171197
"""
172198

173-
cmd_buf = "set -o pipefail ; " + command_string + " 2>&1 | tee -a " \
199+
cmd_buf = (
200+
"set -o pipefail ; "
201+
+ command_string
202+
+ " 2>&1 | tee -a "
174203
+ status_file_path
204+
)
175205
qprint_issuing(cmd_buf)
176206
sub_proc = subprocess.Popen(cmd_buf, shell=True)
177207
sub_proc.communicate()
@@ -187,10 +217,11 @@ def tee_func(command_string, status_file_path):
187217

188218

189219
def main():
190-
191220
gen_setup()
192221

193-
set_term_options(term_requests={'pgm_names': [command_string.split(" ")[0]]})
222+
set_term_options(
223+
term_requests={"pgm_names": [command_string.split(" ")[0]]}
224+
)
194225

195226
global ret_code_str
196227
ret_code_str = re.sub("\\.py$", "", pgm_name) + "_ret_code"
@@ -202,8 +233,9 @@ def main():
202233
show_url = 0
203234
set_pgm_arg(show_url)
204235
else:
205-
shell_rc, status_file_url = shell_cmd("get_file_path_url.py "
206-
+ status_file_path)
236+
shell_rc, status_file_url = shell_cmd(
237+
"get_file_path_url.py " + status_file_path
238+
)
207239
status_file_url = status_file_url.rstrip("\n")
208240

209241
# Print status file path/url to stdout and to status file.

bin/event_notification_util.py

+20-18
Original file line numberDiff line numberDiff line change
@@ -8,39 +8,41 @@
88

99
save_dir_path = sys.path.pop(0)
1010

11-
modules = ['gen_arg', 'gen_print', 'gen_valid', 'event_notification']
11+
modules = ["gen_arg", "gen_print", "gen_valid", "event_notification"]
1212
for module in modules:
1313
exec("from " + module + " import *")
1414

1515
sys.path.insert(0, save_dir_path)
1616

1717
parser = argparse.ArgumentParser(
18-
usage='%(prog)s [OPTIONS]',
18+
usage="%(prog)s [OPTIONS]",
1919
description="%(prog)s will subscribe and receive event notifications when "
20-
+ "properties change for the given dbus path.",
20+
+ "properties change for the given dbus path.",
2121
formatter_class=argparse.ArgumentDefaultsHelpFormatter,
22-
prefix_chars='-+')
22+
prefix_chars="-+",
23+
)
2324
parser.add_argument(
24-
'--host',
25-
default='',
26-
help='The host name or IP of the system to subscribe to.')
25+
"--host",
26+
default="",
27+
help="The host name or IP of the system to subscribe to.",
28+
)
2729
parser.add_argument(
28-
'--username',
29-
default='root',
30-
help='The username for the host system.')
30+
"--username", default="root", help="The username for the host system."
31+
)
3132
parser.add_argument(
32-
'--password',
33-
default='',
34-
help='The password for the host system.')
33+
"--password", default="", help="The password for the host system."
34+
)
3535
parser.add_argument(
36-
'--dbus_path',
37-
default='',
38-
help='The path to be monitored (e.g. "/xyz/openbmc_project/sensors").')
36+
"--dbus_path",
37+
default="",
38+
help='The path to be monitored (e.g. "/xyz/openbmc_project/sensors").',
39+
)
3940
parser.add_argument(
40-
'--enable_trace',
41+
"--enable_trace",
4142
choices=[0, 1],
4243
default=0,
43-
help='Indicates that trace needs to be enabled.')
44+
help="Indicates that trace needs to be enabled.",
45+
)
4446

4547

4648
# Populate stock_list with options we want.

0 commit comments

Comments
 (0)