Skip to content

Commit

Permalink
Fix python2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
Honny1 committed Jan 19, 2024
1 parent 140a4d6 commit cf9e5c4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 9 deletions.
3 changes: 3 additions & 0 deletions tests/unit/utils/test_generate_most_used_rules.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import os
import sys
import pytest
from argparse import Namespace
from utils.profile_tool import command_most_used_rules

Expand All @@ -14,6 +16,7 @@ def get_fake_args():
)


@pytest.mark.skipif(sys.version_info[0] < 3, reason="requires python3")
def test_command(capsys):
command_most_used_rules(get_fake_args())
captured = capsys.readouterr()
Expand Down
26 changes: 17 additions & 9 deletions utils/profile_tool/most_used_rules.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
import sys
import json

from ssg.build_profile import XCCDFBenchmark
from .profile import get_profile
from ..controleval import (
load_controls_manager,
get_available_products,
get_product_profiles_files,
)


PYTHON_2 = sys.version_info[0] < 3

if not PYTHON_2:
from .profile import get_profile
from ..controleval import (
load_controls_manager,
get_available_products,
get_product_profiles_files,
)


def _count_rules_per_rules_list(rules_list, rules):
Expand Down Expand Up @@ -52,10 +58,12 @@ def command_most_used_rules(args):
rules = {}

if len(args.BENCHMARKS) == 0:
if PYTHON_2:
raise Exception("This feature is not supported for python2.")
_process_all_products_from_controls(rules)
else:
for benchmark in args.BENCHMARKS:
_count_rules_per_benchmark(benchmark, rules)

for benchmark in args.BENCHMARKS:
_count_rules_per_benchmark(benchmark, rules)

sorted_rules = _sorted_rules(rules)

Expand Down

0 comments on commit cf9e5c4

Please sign in to comment.