-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sourcery refactored a11/master branch #1
base: a11/master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Due to GitHub API limits, only the first 60 comments can be shown.
1991fa2
to
de5dd5e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Due to GitHub API limits, only the first 60 comments can be shown.
print('gen_version_h: processing [%s]' % version_makefile) | ||
print(f'gen_version_h: processing [{version_makefile}]') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function gen_version_h
refactored with the following changes:
- Swap positions of nested conditionals [×84] (
swap-nested-ifs
) - Replace interpolated string formatting with f-string [×3] (
replace-interpolation-with-fstring
) - Use named expression to simplify assignment and conditional [×3] (
use-named-expression
) - Replace m.group(x) with m[x] for re.Match objects [×3] (
use-getitem-for-re-match-groups
) - Remove redundant continue statement (
remove-redundant-continue
)
print('scan_arch_kbuild: processing [%s]' % arch_asm_kbuild) | ||
print(f'scan_arch_kbuild: processing [{arch_asm_kbuild}]') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function scan_arch_kbuild
refactored with the following changes:
- Replace interpolated string formatting with f-string [×7] (
replace-interpolation-with-fstring
) - Use named expression to simplify assignment and conditional [×3] (
use-named-expression
) - Replace m.group(x) with m[x] for re.Match objects [×3] (
use-getitem-for-re-match-groups
)
match = abi_re.match(generated) | ||
|
||
if match: | ||
abi = match.group(1) | ||
if match := abi_re.match(generated): | ||
abi = match[1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function gen_arch_headers
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
) - Replace m.group(x) with m[x] for re.Match objects (
use-getitem-for-re-match-groups
) - Replace interpolated string formatting with f-string [×2] (
replace-interpolation-with-fstring
)
print('error: expected prefix [%s] on header [%s]' % (prefix, h)) | ||
print(f'error: expected prefix [{prefix}] on header [{h}]') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function run_headers_install
refactored with the following changes:
- Replace interpolated string formatting with f-string [×2] (
replace-interpolation-with-fstring
)
print('find_out: module_dir_sep [%s]' % module_dir_sep) | ||
print('find_out: prefix_sep [%s]' % prefix_sep) | ||
print(f'find_out: module_dir_sep [{module_dir_sep}]') | ||
print(f'find_out: prefix_sep [{prefix_sep}]') | ||
|
||
error_count = 0 | ||
|
||
for full_src in full_srcs: | ||
if verbose: | ||
print('find_out: full_src [%s]' % full_src) | ||
print(f'find_out: full_src [{full_src}]') | ||
|
||
if not full_src.startswith(module_dir_sep): | ||
print('error: expected %s to start with %s' % (full_src, module_dir_sep)) | ||
print(f'error: expected {full_src} to start with {module_dir_sep}') | ||
error_count += 1 | ||
continue | ||
|
||
local_src = full_src[len(module_dir_sep):] | ||
|
||
if verbose: | ||
print('find_out: local_src [%s]' % local_src) | ||
print(f'find_out: local_src [{local_src}]') | ||
|
||
if not local_src.startswith(prefix_sep): | ||
print('error: expected %s to start with %s' % (local_src, prefix_sep)) | ||
print(f'error: expected {local_src} to start with {prefix_sep}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function find_out
refactored with the following changes:
- Replace interpolated string formatting with f-string [×7] (
replace-interpolation-with-fstring
)
if (isinstance(child , nodes.comment) | ||
or isinstance(child, nodes.system_message)): | ||
if isinstance(child, (nodes.comment, nodes.system_message)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function ListTableBuilder.parseRowItem
refactored with the following changes:
- Merge isinstance calls (
merge-isinstance
)
f = fabric_mod_dir_var + "/" + fabric_mod_name + "_base.h" | ||
print "Writing file: " + f | ||
|
||
p = open(f, 'w'); | ||
if not p: | ||
tcm_mod_err("Unable to open file: " + f) | ||
|
||
buf = "#define " + fabric_mod_name.upper() + "_VERSION \"v0.1\"\n" | ||
buf += "#define " + fabric_mod_name.upper() + "_NAMELEN 32\n" | ||
buf += "\n" | ||
buf += "struct " + fabric_mod_name + "_tpg {\n" | ||
buf += " /* FC lport target portal group tag for TCM */\n" | ||
buf += " u16 lport_tpgt;\n" | ||
buf += " /* Pointer back to " + fabric_mod_name + "_lport */\n" | ||
buf += " struct " + fabric_mod_name + "_lport *lport;\n" | ||
buf += " /* Returned by " + fabric_mod_name + "_make_tpg() */\n" | ||
buf += " struct se_portal_group se_tpg;\n" | ||
buf += "};\n" | ||
buf += "\n" | ||
buf += "struct " + fabric_mod_name + "_lport {\n" | ||
buf += " /* Binary World Wide unique Port Name for FC Target Lport */\n" | ||
buf += " u64 lport_wwpn;\n" | ||
buf += " /* ASCII formatted WWPN for FC Target Lport */\n" | ||
buf += " char lport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n" | ||
buf += " /* Returned by " + fabric_mod_name + "_make_lport() */\n" | ||
buf += " struct se_wwn lport_wwn;\n" | ||
buf += "};\n" | ||
|
||
ret = p.write(buf) | ||
if ret: | ||
tcm_mod_err("Unable to write f: " + f) | ||
|
||
p.close() | ||
f = f"{fabric_mod_dir_var}/{fabric_mod_name}_base.h" | ||
global fabric_mod_port | ||
with open(f, 'w') as p: | ||
if not p: | ||
tcm_mod_err(f"Unable to open file: {f}") | ||
|
||
buf = f"#define {fabric_mod_name.upper()}" + "_VERSION \"v0.1\"\n" | ||
buf += f"#define {fabric_mod_name.upper()}" + "_NAMELEN 32\n" | ||
buf += "\n" | ||
buf += f"struct {fabric_mod_name}" + "_tpg {\n" | ||
buf += " /* FC lport target portal group tag for TCM */\n" | ||
buf += " u16 lport_tpgt;\n" | ||
buf += " /* Pointer back to " + fabric_mod_name + "_lport */\n" | ||
buf += " struct " + fabric_mod_name + "_lport *lport;\n" | ||
buf += " /* Returned by " + fabric_mod_name + "_make_tpg() */\n" | ||
buf += " struct se_portal_group se_tpg;\n" | ||
buf += "};\n" | ||
buf += "\n" | ||
buf += f"struct {fabric_mod_name}" + "_lport {\n" | ||
buf += " /* Binary World Wide unique Port Name for FC Target Lport */\n" | ||
buf += " u64 lport_wwpn;\n" | ||
buf += " /* ASCII formatted WWPN for FC Target Lport */\n" | ||
buf += " char lport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n" | ||
buf += " /* Returned by " + fabric_mod_name + "_make_lport() */\n" | ||
buf += " struct se_wwn lport_wwn;\n" | ||
buf += "};\n" | ||
|
||
if ret := p.write(buf): | ||
tcm_mod_err(f"Unable to write f: {f}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function tcm_mod_build_FC_include
refactored with the following changes:
- Use f-string instead of string concatenation [×9] (
use-fstring-for-concatenation
) - Use
with
when opening file to ensure closure (ensure-file-closed
) - Use named expression to simplify assignment and conditional (
use-named-expression
)
f = fabric_mod_dir_var + "/" + fabric_mod_name + "_base.h" | ||
print "Writing file: " + f | ||
|
||
p = open(f, 'w'); | ||
if not p: | ||
tcm_mod_err("Unable to open file: " + f) | ||
|
||
buf = "#define " + fabric_mod_name.upper() + "_VERSION \"v0.1\"\n" | ||
buf += "#define " + fabric_mod_name.upper() + "_NAMELEN 32\n" | ||
buf += "\n" | ||
buf += "struct " + fabric_mod_name + "_tpg {\n" | ||
buf += " /* SAS port target portal group tag for TCM */\n" | ||
buf += " u16 tport_tpgt;\n" | ||
buf += " /* Pointer back to " + fabric_mod_name + "_tport */\n" | ||
buf += " struct " + fabric_mod_name + "_tport *tport;\n" | ||
buf += " /* Returned by " + fabric_mod_name + "_make_tpg() */\n" | ||
buf += " struct se_portal_group se_tpg;\n" | ||
buf += "};\n\n" | ||
buf += "struct " + fabric_mod_name + "_tport {\n" | ||
buf += " /* Binary World Wide unique Port Name for SAS Target port */\n" | ||
buf += " u64 tport_wwpn;\n" | ||
buf += " /* ASCII formatted WWPN for SAS Target port */\n" | ||
buf += " char tport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n" | ||
buf += " /* Returned by " + fabric_mod_name + "_make_tport() */\n" | ||
buf += " struct se_wwn tport_wwn;\n" | ||
buf += "};\n" | ||
|
||
ret = p.write(buf) | ||
if ret: | ||
tcm_mod_err("Unable to write f: " + f) | ||
|
||
p.close() | ||
f = f"{fabric_mod_dir_var}/{fabric_mod_name}_base.h" | ||
global fabric_mod_port | ||
with open(f, 'w') as p: | ||
if not p: | ||
tcm_mod_err(f"Unable to open file: {f}") | ||
|
||
buf = f"#define {fabric_mod_name.upper()}" + "_VERSION \"v0.1\"\n" | ||
buf += f"#define {fabric_mod_name.upper()}" + "_NAMELEN 32\n" | ||
buf += "\n" | ||
buf += f"struct {fabric_mod_name}" + "_tpg {\n" | ||
buf += " /* SAS port target portal group tag for TCM */\n" | ||
buf += " u16 tport_tpgt;\n" | ||
buf += " /* Pointer back to " + fabric_mod_name + "_tport */\n" | ||
buf += " struct " + fabric_mod_name + "_tport *tport;\n" | ||
buf += " /* Returned by " + fabric_mod_name + "_make_tpg() */\n" | ||
buf += " struct se_portal_group se_tpg;\n" | ||
buf += "};\n\n" | ||
buf += f"struct {fabric_mod_name}" + "_tport {\n" | ||
buf += " /* Binary World Wide unique Port Name for SAS Target port */\n" | ||
buf += " u64 tport_wwpn;\n" | ||
buf += " /* ASCII formatted WWPN for SAS Target port */\n" | ||
buf += " char tport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n" | ||
buf += " /* Returned by " + fabric_mod_name + "_make_tport() */\n" | ||
buf += " struct se_wwn tport_wwn;\n" | ||
buf += "};\n" | ||
|
||
if ret := p.write(buf): | ||
tcm_mod_err(f"Unable to write f: {f}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function tcm_mod_build_SAS_include
refactored with the following changes:
- Use f-string instead of string concatenation [×9] (
use-fstring-for-concatenation
) - Use
with
when opening file to ensure closure (ensure-file-closed
) - Use named expression to simplify assignment and conditional (
use-named-expression
)
f = fabric_mod_dir_var + "/" + fabric_mod_name + "_base.h" | ||
print "Writing file: " + f | ||
|
||
p = open(f, 'w'); | ||
if not p: | ||
tcm_mod_err("Unable to open file: " + f) | ||
|
||
buf = "#define " + fabric_mod_name.upper() + "_VERSION \"v0.1\"\n" | ||
buf += "#define " + fabric_mod_name.upper() + "_NAMELEN 32\n" | ||
buf += "\n" | ||
buf += "struct " + fabric_mod_name + "_tpg {\n" | ||
buf += " /* iSCSI target portal group tag for TCM */\n" | ||
buf += " u16 tport_tpgt;\n" | ||
buf += " /* Pointer back to " + fabric_mod_name + "_tport */\n" | ||
buf += " struct " + fabric_mod_name + "_tport *tport;\n" | ||
buf += " /* Returned by " + fabric_mod_name + "_make_tpg() */\n" | ||
buf += " struct se_portal_group se_tpg;\n" | ||
buf += "};\n\n" | ||
buf += "struct " + fabric_mod_name + "_tport {\n" | ||
buf += " /* ASCII formatted TargetName for IQN */\n" | ||
buf += " char tport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n" | ||
buf += " /* Returned by " + fabric_mod_name + "_make_tport() */\n" | ||
buf += " struct se_wwn tport_wwn;\n" | ||
buf += "};\n" | ||
|
||
ret = p.write(buf) | ||
if ret: | ||
tcm_mod_err("Unable to write f: " + f) | ||
|
||
p.close() | ||
f = f"{fabric_mod_dir_var}/{fabric_mod_name}_base.h" | ||
global fabric_mod_port | ||
with open(f, 'w') as p: | ||
if not p: | ||
tcm_mod_err(f"Unable to open file: {f}") | ||
|
||
buf = f"#define {fabric_mod_name.upper()}" + "_VERSION \"v0.1\"\n" | ||
buf += f"#define {fabric_mod_name.upper()}" + "_NAMELEN 32\n" | ||
buf += "\n" | ||
buf += f"struct {fabric_mod_name}" + "_tpg {\n" | ||
buf += " /* iSCSI target portal group tag for TCM */\n" | ||
buf += " u16 tport_tpgt;\n" | ||
buf += " /* Pointer back to " + fabric_mod_name + "_tport */\n" | ||
buf += " struct " + fabric_mod_name + "_tport *tport;\n" | ||
buf += " /* Returned by " + fabric_mod_name + "_make_tpg() */\n" | ||
buf += " struct se_portal_group se_tpg;\n" | ||
buf += "};\n\n" | ||
buf += f"struct {fabric_mod_name}" + "_tport {\n" | ||
buf += " /* ASCII formatted TargetName for IQN */\n" | ||
buf += " char tport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n" | ||
buf += " /* Returned by " + fabric_mod_name + "_make_tport() */\n" | ||
buf += " struct se_wwn tport_wwn;\n" | ||
buf += "};\n" | ||
|
||
if ret := p.write(buf): | ||
tcm_mod_err(f"Unable to write f: {f}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function tcm_mod_build_iSCSI_include
refactored with the following changes:
- Use f-string instead of string concatenation [×9] (
use-fstring-for-concatenation
) - Use
with
when opening file to ensure closure (ensure-file-closed
) - Use named expression to simplify assignment and conditional (
use-named-expression
)
+ "_drop_tpg(struct se_portal_group *se_tpg)\n" | ||
) | ||
|
||
buf += "{\n" | ||
buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n" | ||
buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n\n" | ||
buf += " core_tpg_deregister(se_tpg);\n" | ||
buf += " kfree(tpg);\n" | ||
buf += "}\n\n" | ||
|
||
buf += ( | ||
f"static struct se_wwn *{fabric_mod_name}_make_{fabric_mod_port}" + "(\n" | ||
) | ||
|
||
buf += " struct target_fabric_configfs *tf,\n" | ||
buf += " struct config_group *group,\n" | ||
buf += " const char *name)\n" | ||
buf += "{\n" | ||
buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + ";\n" | ||
|
||
if proto_ident in ["FC", "SAS"]: | ||
buf += " u64 wwpn = 0;\n\n" | ||
|
||
buf += " /* if (" + fabric_mod_name + "_parse_wwn(name, &wwpn, 1) < 0)\n" | ||
buf += " return ERR_PTR(-EINVAL); */\n\n" | ||
buf += " " + fabric_mod_port + " = kzalloc(sizeof(struct " + fabric_mod_name + "_" + fabric_mod_port + "), GFP_KERNEL);\n" | ||
buf += " if (!" + fabric_mod_port + ") {\n" | ||
buf += " printk(KERN_ERR \"Unable to allocate struct " + fabric_mod_name + "_" + fabric_mod_port + "\");\n" | ||
buf += " return ERR_PTR(-ENOMEM);\n" | ||
buf += " }\n" | ||
|
||
if proto_ident in ["FC", "SAS"]: | ||
buf += " " + fabric_mod_port + "->" + fabric_mod_port + "_wwpn = wwpn;\n" | ||
|
||
buf += " /* " + fabric_mod_name + "_format_wwn(&" + fabric_mod_port + "->" + fabric_mod_port + "_name[0], " + fabric_mod_name.upper() + "_NAMELEN, wwpn); */\n\n" | ||
buf += " return &" + fabric_mod_port + "->" + fabric_mod_port + "_wwn;\n" | ||
buf += "}\n\n" | ||
buf += ( | ||
f"static void {fabric_mod_name}_drop_{fabric_mod_port}" | ||
+ "(struct se_wwn *wwn)\n" | ||
) | ||
|
||
buf += "{\n" | ||
buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = container_of(wwn,\n" | ||
buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + ", " + fabric_mod_port + "_wwn);\n" | ||
buf += " kfree(" + fabric_mod_port + ");\n" | ||
buf += "}\n\n" | ||
|
||
buf += ( | ||
f"static const struct target_core_fabric_ops {fabric_mod_name}" | ||
+ "_ops = {\n" | ||
) | ||
|
||
buf += " .module = THIS_MODULE,\n" | ||
buf += " .name = \"" + fabric_mod_name + "\",\n" | ||
buf += " .get_fabric_name = " + fabric_mod_name + "_get_fabric_name,\n" | ||
buf += " .tpg_get_wwn = " + fabric_mod_name + "_get_fabric_wwn,\n" | ||
buf += " .tpg_get_tag = " + fabric_mod_name + "_get_tag,\n" | ||
buf += " .tpg_check_demo_mode = " + fabric_mod_name + "_check_false,\n" | ||
buf += " .tpg_check_demo_mode_cache = " + fabric_mod_name + "_check_true,\n" | ||
buf += " .tpg_check_demo_mode_write_protect = " + fabric_mod_name + "_check_true,\n" | ||
buf += " .tpg_check_prod_mode_write_protect = " + fabric_mod_name + "_check_false,\n" | ||
buf += " .tpg_get_inst_index = " + fabric_mod_name + "_tpg_get_inst_index,\n" | ||
buf += " .release_cmd = " + fabric_mod_name + "_release_cmd,\n" | ||
buf += " .sess_get_index = " + fabric_mod_name + "_sess_get_index,\n" | ||
buf += " .sess_get_initiator_sid = NULL,\n" | ||
buf += " .write_pending = " + fabric_mod_name + "_write_pending,\n" | ||
buf += " .write_pending_status = " + fabric_mod_name + "_write_pending_status,\n" | ||
buf += " .set_default_node_attributes = " + fabric_mod_name + "_set_default_node_attrs,\n" | ||
buf += " .get_cmd_state = " + fabric_mod_name + "_get_cmd_state,\n" | ||
buf += " .queue_data_in = " + fabric_mod_name + "_queue_data_in,\n" | ||
buf += " .queue_status = " + fabric_mod_name + "_queue_status,\n" | ||
buf += " .queue_tm_rsp = " + fabric_mod_name + "_queue_tm_rsp,\n" | ||
buf += " .aborted_task = " + fabric_mod_name + "_aborted_task,\n" | ||
buf += " /*\n" | ||
buf += " * Setup function pointers for generic logic in target_core_fabric_configfs.c\n" | ||
buf += " */\n" | ||
buf += " .fabric_make_wwn = " + fabric_mod_name + "_make_" + fabric_mod_port + ",\n" | ||
buf += " .fabric_drop_wwn = " + fabric_mod_name + "_drop_" + fabric_mod_port + ",\n" | ||
buf += " .fabric_make_tpg = " + fabric_mod_name + "_make_tpg,\n" | ||
buf += " .fabric_drop_tpg = " + fabric_mod_name + "_drop_tpg,\n" | ||
buf += "};\n\n" | ||
|
||
buf += f"static int __init {fabric_mod_name}" + "_init(void)\n" | ||
buf += "{\n" | ||
buf += " return target_register_template(&" + fabric_mod_name + "_ops);\n" | ||
buf += "};\n\n" | ||
|
||
buf += f"static void __exit {fabric_mod_name}" + "_exit(void)\n" | ||
buf += "{\n" | ||
buf += " target_unregister_template(&" + fabric_mod_name + "_ops);\n" | ||
buf += "};\n\n" | ||
|
||
buf += "MODULE_DESCRIPTION(\"" + fabric_mod_name.upper() + " series fabric driver\");\n" | ||
buf += "MODULE_LICENSE(\"GPL\");\n" | ||
buf += f"module_init({fabric_mod_name}" + "_init);\n" | ||
buf += f"module_exit({fabric_mod_name}" + "_exit);\n" | ||
|
||
if ret := p.write(buf): | ||
tcm_mod_err(f"Unable to write f: {f}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function tcm_mod_build_configfs
refactored with the following changes:
- Use f-string instead of string concatenation [×19] (
use-fstring-for-concatenation
) - Use
with
when opening file to ensure closure (ensure-file-closed
) - Replace assignment and augmented assignment with single assignment (
merge-assign-and-aug-assign
) - Simplify conditional into switch-like form [×23] (
switch
) - Replace multiple comparisons of same variable with
in
operator [×2] (merge-comparisons
) - Use named expression to simplify assignment and conditional (
use-named-expression
)
|
||
fabric_ops_api = f"{tcm_dir}include/target/target_core_fabric.h" | ||
|
||
fabric_ops_api = tcm_dir + "include/target/target_core_fabric.h" | ||
|
||
print "Using tcm_mod_scan_fabric_ops: " + fabric_ops_api | ||
process_fo = 0; | ||
|
||
p = open(fabric_ops_api, 'r') | ||
with open(fabric_ops_api, 'r') as p: | ||
line = p.readline() | ||
while line: | ||
if process_fo == 0 and re.search('struct target_core_fabric_ops {', line): | ||
line = p.readline() | ||
continue | ||
|
||
if process_fo == 0: | ||
process_fo = 1; | ||
line = p.readline() | ||
# Search for function pointer | ||
if not re.search('\(\*', line): | ||
continue | ||
|
||
line = p.readline() | ||
while line: | ||
if process_fo == 0 and re.search('struct target_core_fabric_ops {', line): | ||
line = p.readline() | ||
continue | ||
fabric_ops.append(line.rstrip()) | ||
continue | ||
|
||
if process_fo == 0: | ||
process_fo = 1; | ||
line = p.readline() | ||
# Search for function pointer | ||
if not re.search('\(\*', line): | ||
continue | ||
|
||
fabric_ops.append(line.rstrip()) | ||
continue | ||
|
||
line = p.readline() | ||
# Search for function pointer | ||
if not re.search('\(\*', line): | ||
continue | ||
|
||
fabric_ops.append(line.rstrip()) | ||
|
||
p.close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function tcm_mod_scan_fabric_ops
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
) - Use
with
when opening file to ensure closure (ensure-file-closed
)
msrs = dict() | ||
msrs = {} | ||
|
||
with open(sys.argv[1] if len(sys.argv) > 1 else "msr-index.h", "r") as f: | ||
for j in f: | ||
m = re.match(r'#define (MSR_\w+)\s+(0x[0-9a-fA-F]+)', j) | ||
if m: | ||
msrs[int(m.group(2), 16)] = m.group(1) | ||
if m := re.match(r'#define (MSR_\w+)\s+(0x[0-9a-fA-F]+)', j): | ||
msrs[int(m[2], 16)] = m[1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 7-35
refactored with the following changes:
- Replace dict() with {} (
dict-literal
) - Use named expression to simplify assignment and conditional [×2] (
use-named-expression
) - Replace m.group(x) with m[x] for re.Match objects [×5] (
use-getitem-for-re-match-groups
) - Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation
)
f = open(path, "r"); | ||
val = f.read(); | ||
f.close() | ||
with open(path, "r") as f: | ||
val = f.read(); | ||
return int(val) | ||
except IOError as e: | ||
print("I/O error({0}): {1}".format(e.errno, e.strerror)) | ||
print("Invalid path %s" % path) | ||
print(f"Invalid path {path}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function read_sysfs_int
refactored with the following changes:
- Use
with
when opening file to ensure closure (ensure-file-closed
) - Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
f = open(path, "r+") | ||
f.write(val) | ||
f.close() | ||
with open(path, "r+") as f: | ||
f.write(val) | ||
except IOError as e: | ||
print("I/O error({0}): {1}".format(e.errno, e.strerror)) | ||
print("Invalid path %s" % path) | ||
print(f"Invalid path {path}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function write_sysfs_val
refactored with the following changes:
- Use
with
when opening file to ensure closure (ensure-file-closed
) - Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
fname = test_name + '_' + size + '_' + str(iteration_max) + '.csv' | ||
fname = f'{test_name}_{size}_{str(iteration_max)}.csv' | ||
|
||
try: | ||
# gather data set | ||
date = str(datetime.datetime.now()) | ||
error = read_sysfs_int(sys_pfx + 'error') | ||
request_min = read_sysfs_int(sys_pfx + 'requests_per_second_min') | ||
request_max = read_sysfs_int(sys_pfx + 'requests_per_second_max') | ||
request_avg = read_sysfs_int(sys_pfx + 'requests_per_second_avg') | ||
latency_min = read_sysfs_int(sys_pfx + 'latency_min') | ||
latency_max = read_sysfs_int(sys_pfx + 'latency_max') | ||
latency_avg = read_sysfs_int(sys_pfx + 'latency_avg') | ||
throughput_min = read_sysfs_int(sys_pfx + 'throughput_min') | ||
throughput_max = read_sysfs_int(sys_pfx + 'throughput_max') | ||
throughput_avg = read_sysfs_int(sys_pfx + 'throughput_avg') | ||
error = read_sysfs_int(f'{sys_pfx}error') | ||
request_min = read_sysfs_int(f'{sys_pfx}requests_per_second_min') | ||
request_max = read_sysfs_int(f'{sys_pfx}requests_per_second_max') | ||
request_avg = read_sysfs_int(f'{sys_pfx}requests_per_second_avg') | ||
latency_min = read_sysfs_int(f'{sys_pfx}latency_min') | ||
latency_max = read_sysfs_int(f'{sys_pfx}latency_max') | ||
latency_avg = read_sysfs_int(f'{sys_pfx}latency_avg') | ||
throughput_min = read_sysfs_int(f'{sys_pfx}throughput_min') | ||
throughput_max = read_sysfs_int(f'{sys_pfx}throughput_max') | ||
throughput_avg = read_sysfs_int(f'{sys_pfx}throughput_avg') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function log_csv
refactored with the following changes:
- Use f-string instead of string concatenation [×15] (
use-fstring-for-concatenation
)
if re.match(self.kprobes[name]['mask'], target): | ||
return True | ||
return False | ||
return bool(re.match(self.kprobes[name]['mask'], target)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function SystemValues.kprobeMatch
refactored with the following changes:
- Simplify boolean if expression (
boolean-if-exp-identity
) - Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
self.kprobes[name] = {'name': name,'func': name,'args': dict(),'format': name,'mask': name} | ||
self.kprobes[name] = { | ||
'name': name, | ||
'func': name, | ||
'args': {}, | ||
'format': name, | ||
'mask': name, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function SystemValues.basicKprobe
refactored with the following changes:
- Replace dict() with {} (
dict-literal
)
archargs = 'args_'+platform.machine() | ||
archargs = f'args_{platform.machine()}' | ||
if archargs in k: | ||
k['args'] = k[archargs] | ||
else: | ||
k['args'] = dict() | ||
k['args'] = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function SystemValues.defaultKprobe
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
) - Replace dict() with {} (
dict-literal
)
arglist = dict() | ||
arglist = {} | ||
# now process the args | ||
for arg in sorted(args): | ||
arglist[arg] = '' | ||
m = re.match('.* '+arg+'=(?P<arg>.*) ', data); | ||
if m: | ||
arglist[arg] = m.group('arg') | ||
else: | ||
m = re.match('.* '+arg+'=(?P<arg>.*)', data); | ||
if m: | ||
arglist[arg] = m.group('arg') | ||
if m := re.match(f'.* {arg}=(?P<arg>.*) ', data): | ||
arglist[arg] = m['arg'] | ||
elif m := re.match(f'.* {arg}=(?P<arg>.*)', data): | ||
arglist[arg] = m['arg'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function SystemValues.kprobeDisplayName
refactored with the following changes:
- Merge else clause's nested if statement into elif (
merge-else-if-into-elif
) - Replace dict() with {} (
dict-literal
) - Use named expression to simplify assignment and conditional [×2] (
use-named-expression
) - Use f-string instead of string concatenation [×4] (
use-fstring-for-concatenation
) - Replace m.group(x) with m[x] for re.Match objects [×2] (
use-getitem-for-re-match-groups
)
val = 'p:%s_cal %s' % (name, func) | ||
val = f'p:{name}_cal {func}' | ||
for i in sorted(args): | ||
val += ' %s=%s' % (i, args[i]) | ||
val += f' {i}={args[i]}' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function SystemValues.kprobeText
refactored with the following changes:
- Replace interpolated string formatting with f-string [×2] (
replace-interpolation-with-fstring
)
rejects = [] | ||
for name in sorted(self.kprobes): | ||
if not self.testKprobe(self.kprobes[name]): | ||
rejects.append(name) | ||
rejects = [ | ||
name | ||
for name in sorted(self.kprobes) | ||
if not self.testKprobe(self.kprobes[name]) | ||
] | ||
|
||
# remove all failed ones from the list | ||
for name in rejects: | ||
vprint('Skipping KPROBE: %s' % name) | ||
vprint(f'Skipping KPROBE: {name}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function SystemValues.addKprobes
refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension
) - Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
if linesack < linesout: | ||
return False | ||
return True | ||
return linesack >= linesout |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function SystemValues.testKprobe
refactored with the following changes:
- Simplify boolean if expression (
boolean-if-exp-identity
) - Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast
) - Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
fp = open(file, mode) | ||
fp.write(val) | ||
fp.close() | ||
with open(file, mode) as fp: | ||
fp.write(val) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function SystemValues.fsetVal
refactored with the following changes:
- Use
with
when opening file to ensure closure (ensure-file-closed
)
fp = open(file, 'r') | ||
res = fp.read() | ||
fp.close() | ||
with open(file, 'r') as fp: | ||
res = fp.read() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function SystemValues.fgetVal
refactored with the following changes:
- Use
with
when opening file to ensure closure (ensure-file-closed
)
if name in funclist: | ||
return True | ||
return False | ||
return name in funclist |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function SystemValues.isCallgraphFunc
refactored with the following changes:
- Simplify boolean if expression (
boolean-if-exp-identity
) - Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast
) - Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
slist = [] | ||
tmp = dict() | ||
tmp = {} | ||
for devname in list: | ||
dev = list[devname] | ||
tmp[dev['start']] = devname | ||
for t in sorted(tmp): | ||
slist.append(tmp[t]) | ||
return slist | ||
return [tmp[t] for t in sorted(tmp)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Data.sortedDevices
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
) - Move assignment closer to its usage within a block (
move-assign-in-block
) - Replace dict() with {} (
dict-literal
) - Convert for loop into list comprehension (
list-comprehension
)
if(dev['end'] < 0): | ||
if (dev['end'] < 0): | ||
for p in self.phases: | ||
if self.dmesg[p]['end'] > dev['start']: | ||
dev['end'] = self.dmesg[p]['end'] | ||
break | ||
vprint('%s (%s): callback didnt return' % (devname, phase)) | ||
vprint(f'{devname} ({phase}): callback didnt return') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Data.fixupInitcalls
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
if(self.start <= start and self.end > start): | ||
return True | ||
return False | ||
return self.start <= start and self.end > start |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Data.isInsideTimeline
refactored with the following changes:
- Simplify boolean if expression (
boolean-if-exp-identity
) - Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast
) - Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
length = -1.0 | ||
if(start >= 0 and end >= 0): | ||
length = end - start | ||
length = end - start if (start >= 0 and end >= 0) else -1.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Data.newAction
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
) - Move setting of default value for variable into
else
branch (introduce-default-else
)
idlist = [] | ||
list = self.dmesg[phase]['list'] | ||
for devname in list: | ||
if devname in devlist: | ||
idlist.append(list[devname]['id']) | ||
return idlist | ||
return [list[devname]['id'] for devname in list if devname in devlist] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Data.deviceIDs
refactored with the following changes:
- Move assignment closer to its usage within a block (
move-assign-in-block
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
) - Convert for loop into list comprehension (
list-comprehension
)
de5dd5e
to
f1ffe6d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Due to GitHub API limits, only the first 60 comments can be shown.
print('gen_version_h: processing [%s]' % version_makefile) | ||
print(f'gen_version_h: processing [{version_makefile}]') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function gen_version_h
refactored with the following changes:
- Swap positions of nested conditionals [×84] (
swap-nested-ifs
) - Replace interpolated string formatting with f-string [×3] (
replace-interpolation-with-fstring
) - Use named expression to simplify assignment and conditional [×3] (
use-named-expression
) - Replace m.group(x) with m[x] for re.Match objects [×3] (
use-getitem-for-re-match-groups
) - Remove redundant continue statement (
remove-redundant-continue
)
print('scan_arch_kbuild: processing [%s]' % arch_asm_kbuild) | ||
print(f'scan_arch_kbuild: processing [{arch_asm_kbuild}]') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function scan_arch_kbuild
refactored with the following changes:
- Replace interpolated string formatting with f-string [×7] (
replace-interpolation-with-fstring
) - Use named expression to simplify assignment and conditional [×3] (
use-named-expression
) - Replace m.group(x) with m[x] for re.Match objects [×3] (
use-getitem-for-re-match-groups
)
match = abi_re.match(generated) | ||
|
||
if match: | ||
abi = match.group(1) | ||
if match := abi_re.match(generated): | ||
abi = match[1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function gen_arch_headers
refactored with the following changes:
- Use named expression to simplify assignment and conditional (
use-named-expression
) - Replace m.group(x) with m[x] for re.Match objects (
use-getitem-for-re-match-groups
) - Replace interpolated string formatting with f-string [×2] (
replace-interpolation-with-fstring
)
print('error: expected prefix [%s] on header [%s]' % (prefix, h)) | ||
print(f'error: expected prefix [{prefix}] on header [{h}]') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function run_headers_install
refactored with the following changes:
- Replace interpolated string formatting with f-string [×2] (
replace-interpolation-with-fstring
)
print('find_out: module_dir_sep [%s]' % module_dir_sep) | ||
print('find_out: prefix_sep [%s]' % prefix_sep) | ||
print(f'find_out: module_dir_sep [{module_dir_sep}]') | ||
print(f'find_out: prefix_sep [{prefix_sep}]') | ||
|
||
error_count = 0 | ||
|
||
for full_src in full_srcs: | ||
if verbose: | ||
print('find_out: full_src [%s]' % full_src) | ||
print(f'find_out: full_src [{full_src}]') | ||
|
||
if not full_src.startswith(module_dir_sep): | ||
print('error: expected %s to start with %s' % (full_src, module_dir_sep)) | ||
print(f'error: expected {full_src} to start with {module_dir_sep}') | ||
error_count += 1 | ||
continue | ||
|
||
local_src = full_src[len(module_dir_sep):] | ||
|
||
if verbose: | ||
print('find_out: local_src [%s]' % local_src) | ||
print(f'find_out: local_src [{local_src}]') | ||
|
||
if not local_src.startswith(prefix_sep): | ||
print('error: expected %s to start with %s' % (local_src, prefix_sep)) | ||
print(f'error: expected {local_src} to start with {prefix_sep}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function find_out
refactored with the following changes:
- Replace interpolated string formatting with f-string [×7] (
replace-interpolation-with-fstring
)
if (isinstance(child , nodes.comment) | ||
or isinstance(child, nodes.system_message)): | ||
if isinstance(child, (nodes.comment, nodes.system_message)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function ListTableBuilder.parseRowItem
refactored with the following changes:
- Merge isinstance calls (
merge-isinstance
)
f = fabric_mod_dir_var + "/" + fabric_mod_name + "_base.h" | ||
print "Writing file: " + f | ||
|
||
p = open(f, 'w'); | ||
if not p: | ||
tcm_mod_err("Unable to open file: " + f) | ||
|
||
buf = "#define " + fabric_mod_name.upper() + "_VERSION \"v0.1\"\n" | ||
buf += "#define " + fabric_mod_name.upper() + "_NAMELEN 32\n" | ||
buf += "\n" | ||
buf += "struct " + fabric_mod_name + "_tpg {\n" | ||
buf += " /* FC lport target portal group tag for TCM */\n" | ||
buf += " u16 lport_tpgt;\n" | ||
buf += " /* Pointer back to " + fabric_mod_name + "_lport */\n" | ||
buf += " struct " + fabric_mod_name + "_lport *lport;\n" | ||
buf += " /* Returned by " + fabric_mod_name + "_make_tpg() */\n" | ||
buf += " struct se_portal_group se_tpg;\n" | ||
buf += "};\n" | ||
buf += "\n" | ||
buf += "struct " + fabric_mod_name + "_lport {\n" | ||
buf += " /* Binary World Wide unique Port Name for FC Target Lport */\n" | ||
buf += " u64 lport_wwpn;\n" | ||
buf += " /* ASCII formatted WWPN for FC Target Lport */\n" | ||
buf += " char lport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n" | ||
buf += " /* Returned by " + fabric_mod_name + "_make_lport() */\n" | ||
buf += " struct se_wwn lport_wwn;\n" | ||
buf += "};\n" | ||
|
||
ret = p.write(buf) | ||
if ret: | ||
tcm_mod_err("Unable to write f: " + f) | ||
|
||
p.close() | ||
f = f"{fabric_mod_dir_var}/{fabric_mod_name}_base.h" | ||
global fabric_mod_port | ||
with open(f, 'w') as p: | ||
if not p: | ||
tcm_mod_err(f"Unable to open file: {f}") | ||
|
||
buf = f"#define {fabric_mod_name.upper()}" + "_VERSION \"v0.1\"\n" | ||
buf += f"#define {fabric_mod_name.upper()}" + "_NAMELEN 32\n" | ||
buf += "\n" | ||
buf += f"struct {fabric_mod_name}" + "_tpg {\n" | ||
buf += " /* FC lport target portal group tag for TCM */\n" | ||
buf += " u16 lport_tpgt;\n" | ||
buf += " /* Pointer back to " + fabric_mod_name + "_lport */\n" | ||
buf += " struct " + fabric_mod_name + "_lport *lport;\n" | ||
buf += " /* Returned by " + fabric_mod_name + "_make_tpg() */\n" | ||
buf += " struct se_portal_group se_tpg;\n" | ||
buf += "};\n" | ||
buf += "\n" | ||
buf += f"struct {fabric_mod_name}" + "_lport {\n" | ||
buf += " /* Binary World Wide unique Port Name for FC Target Lport */\n" | ||
buf += " u64 lport_wwpn;\n" | ||
buf += " /* ASCII formatted WWPN for FC Target Lport */\n" | ||
buf += " char lport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n" | ||
buf += " /* Returned by " + fabric_mod_name + "_make_lport() */\n" | ||
buf += " struct se_wwn lport_wwn;\n" | ||
buf += "};\n" | ||
|
||
if ret := p.write(buf): | ||
tcm_mod_err(f"Unable to write f: {f}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function tcm_mod_build_FC_include
refactored with the following changes:
- Use f-string instead of string concatenation [×9] (
use-fstring-for-concatenation
) - Use
with
when opening file to ensure closure (ensure-file-closed
) - Use named expression to simplify assignment and conditional (
use-named-expression
)
f = fabric_mod_dir_var + "/" + fabric_mod_name + "_base.h" | ||
print "Writing file: " + f | ||
|
||
p = open(f, 'w'); | ||
if not p: | ||
tcm_mod_err("Unable to open file: " + f) | ||
|
||
buf = "#define " + fabric_mod_name.upper() + "_VERSION \"v0.1\"\n" | ||
buf += "#define " + fabric_mod_name.upper() + "_NAMELEN 32\n" | ||
buf += "\n" | ||
buf += "struct " + fabric_mod_name + "_tpg {\n" | ||
buf += " /* SAS port target portal group tag for TCM */\n" | ||
buf += " u16 tport_tpgt;\n" | ||
buf += " /* Pointer back to " + fabric_mod_name + "_tport */\n" | ||
buf += " struct " + fabric_mod_name + "_tport *tport;\n" | ||
buf += " /* Returned by " + fabric_mod_name + "_make_tpg() */\n" | ||
buf += " struct se_portal_group se_tpg;\n" | ||
buf += "};\n\n" | ||
buf += "struct " + fabric_mod_name + "_tport {\n" | ||
buf += " /* Binary World Wide unique Port Name for SAS Target port */\n" | ||
buf += " u64 tport_wwpn;\n" | ||
buf += " /* ASCII formatted WWPN for SAS Target port */\n" | ||
buf += " char tport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n" | ||
buf += " /* Returned by " + fabric_mod_name + "_make_tport() */\n" | ||
buf += " struct se_wwn tport_wwn;\n" | ||
buf += "};\n" | ||
|
||
ret = p.write(buf) | ||
if ret: | ||
tcm_mod_err("Unable to write f: " + f) | ||
|
||
p.close() | ||
f = f"{fabric_mod_dir_var}/{fabric_mod_name}_base.h" | ||
global fabric_mod_port | ||
with open(f, 'w') as p: | ||
if not p: | ||
tcm_mod_err(f"Unable to open file: {f}") | ||
|
||
buf = f"#define {fabric_mod_name.upper()}" + "_VERSION \"v0.1\"\n" | ||
buf += f"#define {fabric_mod_name.upper()}" + "_NAMELEN 32\n" | ||
buf += "\n" | ||
buf += f"struct {fabric_mod_name}" + "_tpg {\n" | ||
buf += " /* SAS port target portal group tag for TCM */\n" | ||
buf += " u16 tport_tpgt;\n" | ||
buf += " /* Pointer back to " + fabric_mod_name + "_tport */\n" | ||
buf += " struct " + fabric_mod_name + "_tport *tport;\n" | ||
buf += " /* Returned by " + fabric_mod_name + "_make_tpg() */\n" | ||
buf += " struct se_portal_group se_tpg;\n" | ||
buf += "};\n\n" | ||
buf += f"struct {fabric_mod_name}" + "_tport {\n" | ||
buf += " /* Binary World Wide unique Port Name for SAS Target port */\n" | ||
buf += " u64 tport_wwpn;\n" | ||
buf += " /* ASCII formatted WWPN for SAS Target port */\n" | ||
buf += " char tport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n" | ||
buf += " /* Returned by " + fabric_mod_name + "_make_tport() */\n" | ||
buf += " struct se_wwn tport_wwn;\n" | ||
buf += "};\n" | ||
|
||
if ret := p.write(buf): | ||
tcm_mod_err(f"Unable to write f: {f}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function tcm_mod_build_SAS_include
refactored with the following changes:
- Use f-string instead of string concatenation [×9] (
use-fstring-for-concatenation
) - Use
with
when opening file to ensure closure (ensure-file-closed
) - Use named expression to simplify assignment and conditional (
use-named-expression
)
f = fabric_mod_dir_var + "/" + fabric_mod_name + "_base.h" | ||
print "Writing file: " + f | ||
|
||
p = open(f, 'w'); | ||
if not p: | ||
tcm_mod_err("Unable to open file: " + f) | ||
|
||
buf = "#define " + fabric_mod_name.upper() + "_VERSION \"v0.1\"\n" | ||
buf += "#define " + fabric_mod_name.upper() + "_NAMELEN 32\n" | ||
buf += "\n" | ||
buf += "struct " + fabric_mod_name + "_tpg {\n" | ||
buf += " /* iSCSI target portal group tag for TCM */\n" | ||
buf += " u16 tport_tpgt;\n" | ||
buf += " /* Pointer back to " + fabric_mod_name + "_tport */\n" | ||
buf += " struct " + fabric_mod_name + "_tport *tport;\n" | ||
buf += " /* Returned by " + fabric_mod_name + "_make_tpg() */\n" | ||
buf += " struct se_portal_group se_tpg;\n" | ||
buf += "};\n\n" | ||
buf += "struct " + fabric_mod_name + "_tport {\n" | ||
buf += " /* ASCII formatted TargetName for IQN */\n" | ||
buf += " char tport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n" | ||
buf += " /* Returned by " + fabric_mod_name + "_make_tport() */\n" | ||
buf += " struct se_wwn tport_wwn;\n" | ||
buf += "};\n" | ||
|
||
ret = p.write(buf) | ||
if ret: | ||
tcm_mod_err("Unable to write f: " + f) | ||
|
||
p.close() | ||
f = f"{fabric_mod_dir_var}/{fabric_mod_name}_base.h" | ||
global fabric_mod_port | ||
with open(f, 'w') as p: | ||
if not p: | ||
tcm_mod_err(f"Unable to open file: {f}") | ||
|
||
buf = f"#define {fabric_mod_name.upper()}" + "_VERSION \"v0.1\"\n" | ||
buf += f"#define {fabric_mod_name.upper()}" + "_NAMELEN 32\n" | ||
buf += "\n" | ||
buf += f"struct {fabric_mod_name}" + "_tpg {\n" | ||
buf += " /* iSCSI target portal group tag for TCM */\n" | ||
buf += " u16 tport_tpgt;\n" | ||
buf += " /* Pointer back to " + fabric_mod_name + "_tport */\n" | ||
buf += " struct " + fabric_mod_name + "_tport *tport;\n" | ||
buf += " /* Returned by " + fabric_mod_name + "_make_tpg() */\n" | ||
buf += " struct se_portal_group se_tpg;\n" | ||
buf += "};\n\n" | ||
buf += f"struct {fabric_mod_name}" + "_tport {\n" | ||
buf += " /* ASCII formatted TargetName for IQN */\n" | ||
buf += " char tport_name[" + fabric_mod_name.upper() + "_NAMELEN];\n" | ||
buf += " /* Returned by " + fabric_mod_name + "_make_tport() */\n" | ||
buf += " struct se_wwn tport_wwn;\n" | ||
buf += "};\n" | ||
|
||
if ret := p.write(buf): | ||
tcm_mod_err(f"Unable to write f: {f}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function tcm_mod_build_iSCSI_include
refactored with the following changes:
- Use f-string instead of string concatenation [×9] (
use-fstring-for-concatenation
) - Use
with
when opening file to ensure closure (ensure-file-closed
) - Use named expression to simplify assignment and conditional (
use-named-expression
)
+ "_drop_tpg(struct se_portal_group *se_tpg)\n" | ||
) | ||
|
||
buf += "{\n" | ||
buf += " struct " + fabric_mod_name + "_tpg *tpg = container_of(se_tpg,\n" | ||
buf += " struct " + fabric_mod_name + "_tpg, se_tpg);\n\n" | ||
buf += " core_tpg_deregister(se_tpg);\n" | ||
buf += " kfree(tpg);\n" | ||
buf += "}\n\n" | ||
|
||
buf += ( | ||
f"static struct se_wwn *{fabric_mod_name}_make_{fabric_mod_port}" + "(\n" | ||
) | ||
|
||
buf += " struct target_fabric_configfs *tf,\n" | ||
buf += " struct config_group *group,\n" | ||
buf += " const char *name)\n" | ||
buf += "{\n" | ||
buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + ";\n" | ||
|
||
if proto_ident in ["FC", "SAS"]: | ||
buf += " u64 wwpn = 0;\n\n" | ||
|
||
buf += " /* if (" + fabric_mod_name + "_parse_wwn(name, &wwpn, 1) < 0)\n" | ||
buf += " return ERR_PTR(-EINVAL); */\n\n" | ||
buf += " " + fabric_mod_port + " = kzalloc(sizeof(struct " + fabric_mod_name + "_" + fabric_mod_port + "), GFP_KERNEL);\n" | ||
buf += " if (!" + fabric_mod_port + ") {\n" | ||
buf += " printk(KERN_ERR \"Unable to allocate struct " + fabric_mod_name + "_" + fabric_mod_port + "\");\n" | ||
buf += " return ERR_PTR(-ENOMEM);\n" | ||
buf += " }\n" | ||
|
||
if proto_ident in ["FC", "SAS"]: | ||
buf += " " + fabric_mod_port + "->" + fabric_mod_port + "_wwpn = wwpn;\n" | ||
|
||
buf += " /* " + fabric_mod_name + "_format_wwn(&" + fabric_mod_port + "->" + fabric_mod_port + "_name[0], " + fabric_mod_name.upper() + "_NAMELEN, wwpn); */\n\n" | ||
buf += " return &" + fabric_mod_port + "->" + fabric_mod_port + "_wwn;\n" | ||
buf += "}\n\n" | ||
buf += ( | ||
f"static void {fabric_mod_name}_drop_{fabric_mod_port}" | ||
+ "(struct se_wwn *wwn)\n" | ||
) | ||
|
||
buf += "{\n" | ||
buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + " *" + fabric_mod_port + " = container_of(wwn,\n" | ||
buf += " struct " + fabric_mod_name + "_" + fabric_mod_port + ", " + fabric_mod_port + "_wwn);\n" | ||
buf += " kfree(" + fabric_mod_port + ");\n" | ||
buf += "}\n\n" | ||
|
||
buf += ( | ||
f"static const struct target_core_fabric_ops {fabric_mod_name}" | ||
+ "_ops = {\n" | ||
) | ||
|
||
buf += " .module = THIS_MODULE,\n" | ||
buf += " .name = \"" + fabric_mod_name + "\",\n" | ||
buf += " .get_fabric_name = " + fabric_mod_name + "_get_fabric_name,\n" | ||
buf += " .tpg_get_wwn = " + fabric_mod_name + "_get_fabric_wwn,\n" | ||
buf += " .tpg_get_tag = " + fabric_mod_name + "_get_tag,\n" | ||
buf += " .tpg_check_demo_mode = " + fabric_mod_name + "_check_false,\n" | ||
buf += " .tpg_check_demo_mode_cache = " + fabric_mod_name + "_check_true,\n" | ||
buf += " .tpg_check_demo_mode_write_protect = " + fabric_mod_name + "_check_true,\n" | ||
buf += " .tpg_check_prod_mode_write_protect = " + fabric_mod_name + "_check_false,\n" | ||
buf += " .tpg_get_inst_index = " + fabric_mod_name + "_tpg_get_inst_index,\n" | ||
buf += " .release_cmd = " + fabric_mod_name + "_release_cmd,\n" | ||
buf += " .sess_get_index = " + fabric_mod_name + "_sess_get_index,\n" | ||
buf += " .sess_get_initiator_sid = NULL,\n" | ||
buf += " .write_pending = " + fabric_mod_name + "_write_pending,\n" | ||
buf += " .write_pending_status = " + fabric_mod_name + "_write_pending_status,\n" | ||
buf += " .set_default_node_attributes = " + fabric_mod_name + "_set_default_node_attrs,\n" | ||
buf += " .get_cmd_state = " + fabric_mod_name + "_get_cmd_state,\n" | ||
buf += " .queue_data_in = " + fabric_mod_name + "_queue_data_in,\n" | ||
buf += " .queue_status = " + fabric_mod_name + "_queue_status,\n" | ||
buf += " .queue_tm_rsp = " + fabric_mod_name + "_queue_tm_rsp,\n" | ||
buf += " .aborted_task = " + fabric_mod_name + "_aborted_task,\n" | ||
buf += " /*\n" | ||
buf += " * Setup function pointers for generic logic in target_core_fabric_configfs.c\n" | ||
buf += " */\n" | ||
buf += " .fabric_make_wwn = " + fabric_mod_name + "_make_" + fabric_mod_port + ",\n" | ||
buf += " .fabric_drop_wwn = " + fabric_mod_name + "_drop_" + fabric_mod_port + ",\n" | ||
buf += " .fabric_make_tpg = " + fabric_mod_name + "_make_tpg,\n" | ||
buf += " .fabric_drop_tpg = " + fabric_mod_name + "_drop_tpg,\n" | ||
buf += "};\n\n" | ||
|
||
buf += f"static int __init {fabric_mod_name}" + "_init(void)\n" | ||
buf += "{\n" | ||
buf += " return target_register_template(&" + fabric_mod_name + "_ops);\n" | ||
buf += "};\n\n" | ||
|
||
buf += f"static void __exit {fabric_mod_name}" + "_exit(void)\n" | ||
buf += "{\n" | ||
buf += " target_unregister_template(&" + fabric_mod_name + "_ops);\n" | ||
buf += "};\n\n" | ||
|
||
buf += "MODULE_DESCRIPTION(\"" + fabric_mod_name.upper() + " series fabric driver\");\n" | ||
buf += "MODULE_LICENSE(\"GPL\");\n" | ||
buf += f"module_init({fabric_mod_name}" + "_init);\n" | ||
buf += f"module_exit({fabric_mod_name}" + "_exit);\n" | ||
|
||
if ret := p.write(buf): | ||
tcm_mod_err(f"Unable to write f: {f}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function tcm_mod_build_configfs
refactored with the following changes:
- Use f-string instead of string concatenation [×19] (
use-fstring-for-concatenation
) - Use
with
when opening file to ensure closure (ensure-file-closed
) - Replace assignment and augmented assignment with single assignment (
merge-assign-and-aug-assign
) - Simplify conditional into switch-like form [×23] (
switch
) - Replace multiple comparisons of same variable with
in
operator [×2] (merge-comparisons
) - Use named expression to simplify assignment and conditional (
use-named-expression
)
|
||
fabric_ops_api = f"{tcm_dir}include/target/target_core_fabric.h" | ||
|
||
fabric_ops_api = tcm_dir + "include/target/target_core_fabric.h" | ||
|
||
print "Using tcm_mod_scan_fabric_ops: " + fabric_ops_api | ||
process_fo = 0; | ||
|
||
p = open(fabric_ops_api, 'r') | ||
with open(fabric_ops_api, 'r') as p: | ||
line = p.readline() | ||
while line: | ||
if process_fo == 0 and re.search('struct target_core_fabric_ops {', line): | ||
line = p.readline() | ||
continue | ||
|
||
if process_fo == 0: | ||
process_fo = 1; | ||
line = p.readline() | ||
# Search for function pointer | ||
if not re.search('\(\*', line): | ||
continue | ||
|
||
line = p.readline() | ||
while line: | ||
if process_fo == 0 and re.search('struct target_core_fabric_ops {', line): | ||
line = p.readline() | ||
continue | ||
fabric_ops.append(line.rstrip()) | ||
continue | ||
|
||
if process_fo == 0: | ||
process_fo = 1; | ||
line = p.readline() | ||
# Search for function pointer | ||
if not re.search('\(\*', line): | ||
continue | ||
|
||
fabric_ops.append(line.rstrip()) | ||
continue | ||
|
||
line = p.readline() | ||
# Search for function pointer | ||
if not re.search('\(\*', line): | ||
continue | ||
|
||
fabric_ops.append(line.rstrip()) | ||
|
||
p.close() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function tcm_mod_scan_fabric_ops
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
) - Use
with
when opening file to ensure closure (ensure-file-closed
)
msrs = dict() | ||
msrs = {} | ||
|
||
with open(sys.argv[1] if len(sys.argv) > 1 else "msr-index.h", "r") as f: | ||
for j in f: | ||
m = re.match(r'#define (MSR_\w+)\s+(0x[0-9a-fA-F]+)', j) | ||
if m: | ||
msrs[int(m.group(2), 16)] = m.group(1) | ||
if m := re.match(r'#define (MSR_\w+)\s+(0x[0-9a-fA-F]+)', j): | ||
msrs[int(m[2], 16)] = m[1] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Lines 7-35
refactored with the following changes:
- Replace dict() with {} (
dict-literal
) - Use named expression to simplify assignment and conditional [×2] (
use-named-expression
) - Replace m.group(x) with m[x] for re.Match objects [×5] (
use-getitem-for-re-match-groups
) - Use f-string instead of string concatenation [×2] (
use-fstring-for-concatenation
)
f = open(path, "r"); | ||
val = f.read(); | ||
f.close() | ||
with open(path, "r") as f: | ||
val = f.read(); | ||
return int(val) | ||
except IOError as e: | ||
print("I/O error({0}): {1}".format(e.errno, e.strerror)) | ||
print("Invalid path %s" % path) | ||
print(f"Invalid path {path}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function read_sysfs_int
refactored with the following changes:
- Use
with
when opening file to ensure closure (ensure-file-closed
) - Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
f = open(path, "r+") | ||
f.write(val) | ||
f.close() | ||
with open(path, "r+") as f: | ||
f.write(val) | ||
except IOError as e: | ||
print("I/O error({0}): {1}".format(e.errno, e.strerror)) | ||
print("Invalid path %s" % path) | ||
print(f"Invalid path {path}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function write_sysfs_val
refactored with the following changes:
- Use
with
when opening file to ensure closure (ensure-file-closed
) - Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
fname = test_name + '_' + size + '_' + str(iteration_max) + '.csv' | ||
fname = f'{test_name}_{size}_{str(iteration_max)}.csv' | ||
|
||
try: | ||
# gather data set | ||
date = str(datetime.datetime.now()) | ||
error = read_sysfs_int(sys_pfx + 'error') | ||
request_min = read_sysfs_int(sys_pfx + 'requests_per_second_min') | ||
request_max = read_sysfs_int(sys_pfx + 'requests_per_second_max') | ||
request_avg = read_sysfs_int(sys_pfx + 'requests_per_second_avg') | ||
latency_min = read_sysfs_int(sys_pfx + 'latency_min') | ||
latency_max = read_sysfs_int(sys_pfx + 'latency_max') | ||
latency_avg = read_sysfs_int(sys_pfx + 'latency_avg') | ||
throughput_min = read_sysfs_int(sys_pfx + 'throughput_min') | ||
throughput_max = read_sysfs_int(sys_pfx + 'throughput_max') | ||
throughput_avg = read_sysfs_int(sys_pfx + 'throughput_avg') | ||
error = read_sysfs_int(f'{sys_pfx}error') | ||
request_min = read_sysfs_int(f'{sys_pfx}requests_per_second_min') | ||
request_max = read_sysfs_int(f'{sys_pfx}requests_per_second_max') | ||
request_avg = read_sysfs_int(f'{sys_pfx}requests_per_second_avg') | ||
latency_min = read_sysfs_int(f'{sys_pfx}latency_min') | ||
latency_max = read_sysfs_int(f'{sys_pfx}latency_max') | ||
latency_avg = read_sysfs_int(f'{sys_pfx}latency_avg') | ||
throughput_min = read_sysfs_int(f'{sys_pfx}throughput_min') | ||
throughput_max = read_sysfs_int(f'{sys_pfx}throughput_max') | ||
throughput_avg = read_sysfs_int(f'{sys_pfx}throughput_avg') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function log_csv
refactored with the following changes:
- Use f-string instead of string concatenation [×15] (
use-fstring-for-concatenation
)
if re.match(self.kprobes[name]['mask'], target): | ||
return True | ||
return False | ||
return bool(re.match(self.kprobes[name]['mask'], target)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function SystemValues.kprobeMatch
refactored with the following changes:
- Simplify boolean if expression (
boolean-if-exp-identity
) - Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
self.kprobes[name] = {'name': name,'func': name,'args': dict(),'format': name,'mask': name} | ||
self.kprobes[name] = { | ||
'name': name, | ||
'func': name, | ||
'args': {}, | ||
'format': name, | ||
'mask': name, | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function SystemValues.basicKprobe
refactored with the following changes:
- Replace dict() with {} (
dict-literal
)
archargs = 'args_'+platform.machine() | ||
archargs = f'args_{platform.machine()}' | ||
if archargs in k: | ||
k['args'] = k[archargs] | ||
else: | ||
k['args'] = dict() | ||
k['args'] = {} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function SystemValues.defaultKprobe
refactored with the following changes:
- Use f-string instead of string concatenation (
use-fstring-for-concatenation
) - Replace dict() with {} (
dict-literal
)
arglist = dict() | ||
arglist = {} | ||
# now process the args | ||
for arg in sorted(args): | ||
arglist[arg] = '' | ||
m = re.match('.* '+arg+'=(?P<arg>.*) ', data); | ||
if m: | ||
arglist[arg] = m.group('arg') | ||
else: | ||
m = re.match('.* '+arg+'=(?P<arg>.*)', data); | ||
if m: | ||
arglist[arg] = m.group('arg') | ||
if m := re.match(f'.* {arg}=(?P<arg>.*) ', data): | ||
arglist[arg] = m['arg'] | ||
elif m := re.match(f'.* {arg}=(?P<arg>.*)', data): | ||
arglist[arg] = m['arg'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function SystemValues.kprobeDisplayName
refactored with the following changes:
- Merge else clause's nested if statement into elif (
merge-else-if-into-elif
) - Replace dict() with {} (
dict-literal
) - Use named expression to simplify assignment and conditional [×2] (
use-named-expression
) - Use f-string instead of string concatenation [×4] (
use-fstring-for-concatenation
) - Replace m.group(x) with m[x] for re.Match objects [×2] (
use-getitem-for-re-match-groups
)
val = 'p:%s_cal %s' % (name, func) | ||
val = f'p:{name}_cal {func}' | ||
for i in sorted(args): | ||
val += ' %s=%s' % (i, args[i]) | ||
val += f' {i}={args[i]}' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function SystemValues.kprobeText
refactored with the following changes:
- Replace interpolated string formatting with f-string [×2] (
replace-interpolation-with-fstring
)
rejects = [] | ||
for name in sorted(self.kprobes): | ||
if not self.testKprobe(self.kprobes[name]): | ||
rejects.append(name) | ||
rejects = [ | ||
name | ||
for name in sorted(self.kprobes) | ||
if not self.testKprobe(self.kprobes[name]) | ||
] | ||
|
||
# remove all failed ones from the list | ||
for name in rejects: | ||
vprint('Skipping KPROBE: %s' % name) | ||
vprint(f'Skipping KPROBE: {name}') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function SystemValues.addKprobes
refactored with the following changes:
- Convert for loop into list comprehension (
list-comprehension
) - Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
if linesack < linesout: | ||
return False | ||
return True | ||
return linesack >= linesout |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function SystemValues.testKprobe
refactored with the following changes:
- Simplify boolean if expression (
boolean-if-exp-identity
) - Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast
) - Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
fp = open(file, mode) | ||
fp.write(val) | ||
fp.close() | ||
with open(file, mode) as fp: | ||
fp.write(val) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function SystemValues.fsetVal
refactored with the following changes:
- Use
with
when opening file to ensure closure (ensure-file-closed
)
fp = open(file, 'r') | ||
res = fp.read() | ||
fp.close() | ||
with open(file, 'r') as fp: | ||
res = fp.read() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function SystemValues.fgetVal
refactored with the following changes:
- Use
with
when opening file to ensure closure (ensure-file-closed
)
if name in funclist: | ||
return True | ||
return False | ||
return name in funclist |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function SystemValues.isCallgraphFunc
refactored with the following changes:
- Simplify boolean if expression (
boolean-if-exp-identity
) - Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast
) - Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
slist = [] | ||
tmp = dict() | ||
tmp = {} | ||
for devname in list: | ||
dev = list[devname] | ||
tmp[dev['start']] = devname | ||
for t in sorted(tmp): | ||
slist.append(tmp[t]) | ||
return slist | ||
return [tmp[t] for t in sorted(tmp)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Data.sortedDevices
refactored with the following changes:
- Inline variable that is immediately returned (
inline-immediately-returned-variable
) - Move assignment closer to its usage within a block (
move-assign-in-block
) - Replace dict() with {} (
dict-literal
) - Convert for loop into list comprehension (
list-comprehension
)
if(dev['end'] < 0): | ||
if (dev['end'] < 0): | ||
for p in self.phases: | ||
if self.dmesg[p]['end'] > dev['start']: | ||
dev['end'] = self.dmesg[p]['end'] | ||
break | ||
vprint('%s (%s): callback didnt return' % (devname, phase)) | ||
vprint(f'{devname} ({phase}): callback didnt return') |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Data.fixupInitcalls
refactored with the following changes:
- Replace interpolated string formatting with f-string (
replace-interpolation-with-fstring
)
if(self.start <= start and self.end > start): | ||
return True | ||
return False | ||
return self.start <= start and self.end > start |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Data.isInsideTimeline
refactored with the following changes:
- Simplify boolean if expression (
boolean-if-exp-identity
) - Remove unnecessary casts to int, str, float or bool (
remove-unnecessary-cast
) - Lift code into else after jump in control flow (
reintroduce-else
) - Replace if statement with if expression (
assign-if-exp
)
length = -1.0 | ||
if(start >= 0 and end >= 0): | ||
length = end - start | ||
length = end - start if (start >= 0 and end >= 0) else -1.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Data.newAction
refactored with the following changes:
- Replace if statement with if expression (
assign-if-exp
) - Move setting of default value for variable into
else
branch (introduce-default-else
)
idlist = [] | ||
list = self.dmesg[phase]['list'] | ||
for devname in list: | ||
if devname in devlist: | ||
idlist.append(list[devname]['id']) | ||
return idlist | ||
return [list[devname]['id'] for devname in list if devname in devlist] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Function Data.deviceIDs
refactored with the following changes:
- Move assignment closer to its usage within a block (
move-assign-in-block
) - Inline variable that is immediately returned (
inline-immediately-returned-variable
) - Convert for loop into list comprehension (
list-comprehension
)
Branch
a11/master
refactored by Sourcery.If you're happy with these changes, merge this Pull Request using the Squash and merge strategy.
See our documentation here.
Run Sourcery locally
Reduce the feedback loop during development by using the Sourcery editor plugin:
Review changes via command line
To manually merge these changes, make sure you're on the
a11/master
branch, then run:Help us improve this pull request!