Skip to content

Commit

Permalink
Fix python2 support
Browse files Browse the repository at this point in the history
  • Loading branch information
Honny1 committed Feb 28, 2024
1 parent c7855f8 commit 2d96df9
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 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
23 changes: 16 additions & 7 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 All @@ -33,6 +39,9 @@ def _get_profiles_for_product(ctrls_mgr, product):


def _process_all_products_from_controls(rules):
if PYTHON_2:
raise Exception("This feature is not supported for python2.")

for product in get_available_products():
controls_manager = load_controls_manager("./controls/", product)
for profile in _get_profiles_for_product(controls_manager, product):
Expand All @@ -50,7 +59,7 @@ def _sorted_rules(rules):
def command_most_used_rules(args):
rules = {}

if len(args.BENCHMARKS) == 0:
if args.BENCHMARKS:
_process_all_products_from_controls(rules)
else:
for benchmark in args.BENCHMARKS:
Expand Down

0 comments on commit 2d96df9

Please sign in to comment.