Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions ruff.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ select = [
"T10", # flake8-debugger
"PLE", # pylint-error
"YTT", # flake8-2020
"FURB", # refurb
]

ignore = [
Expand Down
4 changes: 2 additions & 2 deletions ssg/ansible.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ def remove_too_many_blank_lines(ansible_src):
Returns:
str: The modified string with excessive blank lines reduced.
"""
return re.sub(r'\n{4,}', '\n\n\n', ansible_src, 0, flags=re.M)
return re.sub(r'\n{4,}', '\n\n\n', ansible_src, 0, flags=re.MULTILINE)


def remove_trailing_whitespace(ansible_src):
Expand All @@ -82,7 +82,7 @@ def remove_trailing_whitespace(ansible_src):
str: The Ansible source code with trailing whitespace removed from each line.
"""

return re.sub(r'[ \t]+$', '', ansible_src, 0, flags=re.M)
return re.sub(r'[ \t]+$', '', ansible_src, 0, flags=re.MULTILINE)


package_facts_task = collections.OrderedDict([
Expand Down
4 changes: 1 addition & 3 deletions ssg/build_guides.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,7 @@ def _is_skipped_profile(profile_id):
def _get_guide_filename(path_base, profile_id, benchmark_id, benchmarks):
profile_id_for_path = "default" if not profile_id else profile_id
benchmark_id_for_path = benchmark_id
if benchmark_id_for_path.startswith(OSCAP_DS_STRING):
benchmark_id_for_path = \
benchmark_id_for_path[len(OSCAP_DS_STRING):]
benchmark_id_for_path = benchmark_id_for_path.removeprefix(OSCAP_DS_STRING)

if len(benchmarks) == 1 or len(benchmark_id_for_path) == len("RHEL-X"):
# treat the base RHEL benchmark as a special case to preserve
Expand Down
3 changes: 1 addition & 2 deletions ssg/build_remediations.py
Original file line number Diff line number Diff line change
Expand Up @@ -535,8 +535,7 @@ def write_fix_to_file(fix, file_path):
"""
fix_contents, config = fix
with open(file_path, "w") as f:
for k, v in config.items():
f.write("# %s = %s\n" % (k, v))
f.writelines("# %s = %s\n" % (k, v) for k, v in config.items())
f.write(fix_contents)


Expand Down
3 changes: 1 addition & 2 deletions ssg/playbook_builder.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,8 +165,7 @@ def create_playbook(self, snippet_path, rule_id, variables,
playbook_path = os.path.join(output_dir, rule_id + ".yml")
with open(playbook_path, "w") as playbook_file:
# write remediation metadata (complexity, strategy, etc.) first
for k, v in fix.config.items():
playbook_file.write("# %s = %s\n" % (k, v))
playbook_file.writelines("# %s = %s\n" % (k, v) for k, v in fix.config.items())
ssg.yaml.ordered_dump(
playbook, playbook_file, default_flow_style=False
)
Expand Down
2 changes: 1 addition & 1 deletion tests/assert_reference_unique.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def print_refs(ref: str, refs_found: RefsFoundType) -> bool:
filenames = refs_found[dup]
if len(filenames) > 1:
okay = False
print("", file=sys.stderr)
print(file=sys.stderr)
print(f"{ref} {dup} is included in files: ", file=sys.stderr)
for filename in sorted(filenames):
print(f" - {filename}", file=sys.stderr)
Expand Down
2 changes: 1 addition & 1 deletion tests/cces-removed.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def _get_cces_in_use(data: dict, products: str) -> Set[str]:
def _get_avail_cces(cce_list: str) -> Set[str]:
avail_cces: Set[str] = set()
with open(cce_list) as f:
for line in f.readlines():
for line in f:
avail_cces.add(line.strip())
return avail_cces

Expand Down
8 changes: 4 additions & 4 deletions tests/test_machine_only_rules.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@


BASH_MACHINE_CONDITIONAL = re.compile(
r'^.*\[ ! -f /.dockerenv \] && \[ ! -f /run/.containerenv \].*$', re.M)
r'^.*\[ ! -f /.dockerenv \] && \[ ! -f /run/.containerenv \].*$', re.MULTILINE)
ANSIBLE_MACHINE_CONDITIONAL = re.compile(
r'ansible_virtualization_type not in \["docker",\s+"lxc",\s+"openvz",\s+"podman",\s+' +
r'"container"\]',
re.M)
re.MULTILINE)
MACHINE_PLATFORM_ONE_LINE = re.compile(
r'^\s*platform:\s+machine\s*$', re.M)
r'^\s*platform:\s+machine\s*$', re.MULTILINE)
MACHINE_PLATFORM_MULTILINE = re.compile(
r'^\s*platforms:\s*\n(\s+-\s+.*machine.*)+', re.M)
r'^\s*platforms:\s*\n(\s+-\s+.*machine.*)+', re.MULTILINE)


def main():
Expand Down
4 changes: 2 additions & 2 deletions utils/mod_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ def list_platforms(rule_obj):
for product in sorted(oval.get('products', [])):
print(" - %s" % product)

print("")
print()

print("Actual platforms:")
for oval_id in sorted(rule_obj.get('ovals', {})):
Expand All @@ -54,7 +54,7 @@ def list_platforms(rule_obj):
for platform in platforms:
print(" - %s" % platform)

print("")
print()


def add_platforms(rule_obj, platforms):
Expand Down
4 changes: 2 additions & 2 deletions utils/mod_fixes.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def list_platforms(rule_obj, lang):
for product in sorted(fix.get('products', [])):
print(" - %s" % product)

print("")
print()

print("Actual platforms:")
for rule_id in sorted(rule_obj['remediations'].get(lang, {})):
Expand All @@ -56,7 +56,7 @@ def list_platforms(rule_obj, lang):
for platform in platforms:
print(" - %s" % platform)

print("")
print()


def add_platforms(rule_obj, lang, platforms):
Expand Down
Loading