<commit_before>import copy
import subprocess

import sys
import os
import re
import json 
import random 
import shutil

from anchore import anchore_utils
import logging
import anchore_image_db

from anchore.util import scripting, contexts

DEVNULL=open(os.devnull, 'wb')


class Controller(object):
    """
    Component that manages gate execution on images.
    """

    _logger = logging.getLogger(__name__)

    def __init__(self, anchore_config, imagelist, allimages, force=False):
        self.config = anchore_config
        self.allimages = allimages
        self.force = force        
        self.anchore_datadir = self.config['image_data_store']
        
        if len(imagelist) <= 0:
            raise Exception("No images given to evaluate")

        self.images = anchore_utils.image_context_add(imagelist, allimages, docker_cli=contexts['docker_cli'], anchore_datadir=self.anchore_datadir, tmproot=self.config['tmpdir'], anchore_db=contexts['anchore_db'], must_be_analyzed=True, must_load_all=True)

        self.anchoreDB = contexts['anchore_db']

        self.policy_override = None

    def read_policyfile(self, policyfile):
        FH=open(policyfile, 'r')
        policies = {}
        for l in FH.readlines():
            l = l.strip()
            patt = re.compile('^\s*#')

            if (l and not patt.match(l)):
                polinput = l.split(':')
                module = polinput[0]
                check = polinput[1]
                action = polinput[2]
                modparams = ""
                if (len(polinput) > 3):
                    modparams = polinput[3]

                if module not in policies:
                    policies[module] = {}

                if check not in policies[module]:<commit_msg>ensure that all params are passed from policy definition<commit_after>import copy
import subprocess

import sys
import os
import re
import json 
import random 
import shutil

from anchore import anchore_utils
import logging
import anchore_image_db

from anchore.util import scripting, contexts

DEVNULL=open(os.devnull, 'wb')


class Controller(object):
    """
    Component that manages gate execution on images.
    """

    _logger = logging.getLogger(__name__)

    def __init__(self, anchore_config, imagelist, allimages, force=False):
        self.config = anchore_config
        self.allimages = allimages
        self.force = force        
        self.anchore_datadir = self.config['image_data_store']
        
        if len(imagelist) <= 0:
            raise Exception("No images given to evaluate")

        self.images = anchore_utils.image_context_add(imagelist, allimages, docker_cli=contexts['docker_cli'], anchore_datadir=self.anchore_datadir, tmproot=self.config['tmpdir'], anchore_db=contexts['anchore_db'], must_be_analyzed=True, must_load_all=True)

        self.anchoreDB = contexts['anchore_db']

        self.policy_override = None

    def read_policyfile(self, policyfile):
        FH=open(policyfile, 'r')
        policies = {}
        for l in FH.readlines():
            l = l.strip()
            patt = re.compile('^\s*#')

            if (l and not patt.match(l)):
                polinput = l.split(':')
                module = polinput[0]
                check = polinput[1]
                action = polinput[2]
                modparams = ""
                if (len(polinput) > 3):
                    modparams = ':'.join(polinput[3:])

                if module not in policies:
                    policies[module] = {}

                if check not in policies[module]:
{'fraction_non_alphanumeric': 0.0973625140291807, 'fraction_numerical': 0.003367003367003367, 'mean_word_length': 2.338014981273408, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1962011', 'n_tokens_mistral': 1073, 'n_tokens_neox': 1017, 'n_words': 251}