<commit_before>"""
  Server Density Plugin
  ColdFusion stats
  https://github.com/MWers/sd-coldfusion-plugin/
  Version: 1.0.1
"""
import os
import platform
import subprocess


class ColdFusion:
    sd_cfstat_opt = 'coldfusion_cfstat_path'
    cfstat_locations = ['/opt/coldfusion11/bin/cfstat',
                        '/opt/coldfusion10/bin/cfstat',
                        '/opt/ColdFusion9/bin/cfstat',
                        '/opt/coldfusion8/bin/cfstat',
                        '/opt/coldfusionmx7/bin/cfstat']
    cfstat_keys_long = ['Pg/s Now', 'Pg/s Hi', 'DB/s Now', 'DB/s Hi',
                        'CP/s Now', 'CP/s Hi', 'Reqs Q''ed', 'Reqs Run''g',
                        'Reqs TO''ed', 'Tpl Q''ed', 'Tpl Run''g', 'Tpl TO''ed',
                        'Flash Q''ed', 'Flash Run''g', 'Flash TO''ed',
                        'CFC Q''ed', 'CFC Run''g', 'CFC TO''ed',
                        'WebSvc Q''ed', 'WebSvc Run''g', 'WebSvc TO''ed',
                        'Avg Q Time', 'Avg Req Time', 'Avg DB Time',
                        'Bytes In/s', 'Bytes Out/s']
    cfstat_keys_short = ['Pg/s Now', 'Pg/s Hi', 'DB/s Now', 'DB/s Hi',
                         'CP/s Now', 'CP/s Hi', 'Reqs Q''ed', 'Reqs Run''g',
                         'Reqs TO''ed', 'Avg Q Time', 'Avg Req Time',
                         'Avg DB Time', 'Bytes In/s', 'Bytes Out/s']
    python_version = platform.python_version_tuple()

    def __init__(self, agent_config, checks_logger, raw_config):
        self.agent_config = agent_config
        self.checks_logger = checks_logger
        self.raw_config = raw_config

    def run(self):
        # Determine location of cfstat and make sure it's executable
        cfstat = None
        if 'Main' in self.raw_config and \
                        self.sd_cfstat_opt in self.raw_config['Main']:
            cfstat = self.raw_config['Main'][self.sd_cfstat_opt]
            if not os.access(cfstat, os.X_OK):
                self.checks_logger.error('ColdFusion: The location of cfstat '
                                         'given in config (%s) either does '
                                         'not '
                                         'exist or is not executable' % cfstat)
                return False
            else:
                self.checks_logger.debug('ColdFusion: Using cfstat defined in '
                                         'config: %s' % cfstat)

        else:
            self.checks_logger.debug('ColdFusion: cfstat path not in config, '
                                     'checking standard locations')
            for location in self.cfstat_locations:
                if os.access(location, os.X_OK):
                    cfstat = location
                    self.checks_logger.debug('ColdFusion: Using cfstat found '
                                             'here: %s' % cfstat)
                    break
            if not cfstat:
                self.checks_logger.error('ColdFusion: Could not find cfstat')
                return False

        # Run cfstat and collect its data
        self.checks_logger.debug('ColdFusion: Getting stats from ColdFusion')
        proc = subprocess.Popen([cfstat, '-x', '-n', '-s'],
                                stdout=subprocess.PIPE, close_fds=True)
        stats = proc.communicate()[0]

        if int(self.python_version[1]) >= 6:
            try:
                proc.kill()
            except Exception, e:
                self.checks_logger.debug('ColdFusion: cfstat process already '<commit_msg>Minor formatting update<commit_after>"""
  Server Density Plugin
  ColdFusion stats
  https://github.com/MWers/sd-coldfusion-plugin/
  Version: 1.0.1
"""
import os
import platform
import subprocess


class ColdFusion:
    sd_cfstat_opt = 'coldfusion_cfstat_path'
    cfstat_locations = ['/opt/coldfusion11/bin/cfstat',
                        '/opt/coldfusion10/bin/cfstat',
                        '/opt/ColdFusion9/bin/cfstat',
                        '/opt/coldfusion8/bin/cfstat',
                        '/opt/coldfusionmx7/bin/cfstat']
    cfstat_keys_long = ['Pg/s Now', 'Pg/s Hi', 'DB/s Now', 'DB/s Hi',
                        'CP/s Now', 'CP/s Hi', 'Reqs Q''ed', 'Reqs Run''g',
                        'Reqs TO''ed', 'Tpl Q''ed', 'Tpl Run''g', 'Tpl TO''ed',
                        'Flash Q''ed', 'Flash Run''g', 'Flash TO''ed',
                        'CFC Q''ed', 'CFC Run''g', 'CFC TO''ed',
                        'WebSvc Q''ed', 'WebSvc Run''g', 'WebSvc TO''ed',
                        'Avg Q Time', 'Avg Req Time', 'Avg DB Time',
                        'Bytes In/s', 'Bytes Out/s']
    cfstat_keys_short = ['Pg/s Now', 'Pg/s Hi', 'DB/s Now', 'DB/s Hi',
                         'CP/s Now', 'CP/s Hi', 'Reqs Q''ed', 'Reqs Run''g',
                         'Reqs TO''ed', 'Avg Q Time', 'Avg Req Time',
                         'Avg DB Time', 'Bytes In/s', 'Bytes Out/s']
    python_version = platform.python_version_tuple()

    def __init__(self, agent_config, checks_logger, raw_config):
        self.agent_config = agent_config
        self.checks_logger = checks_logger
        self.raw_config = raw_config

    def run(self):
        # Determine location of cfstat and make sure it's executable
        cfstat = None
        if 'Main' in self.raw_config and \
                        self.sd_cfstat_opt in self.raw_config['Main']:
            cfstat = self.raw_config['Main'][self.sd_cfstat_opt]
            if not os.access(cfstat, os.X_OK):
                self.checks_logger.error('ColdFusion: The location of cfstat '
                                         'given in config (%s) either does '
                                         'not exist or is not executable'
                                         % cfstat)
                return False
            else:
                self.checks_logger.debug('ColdFusion: Using cfstat defined in '
                                         'config: %s' % cfstat)

        else:
            self.checks_logger.debug('ColdFusion: cfstat path not in config, '
                                     'checking standard locations')
            for location in self.cfstat_locations:
                if os.access(location, os.X_OK):
                    cfstat = location
                    self.checks_logger.debug('ColdFusion: Using cfstat found '
                                             'here: %s' % cfstat)
                    break
            if not cfstat:
                self.checks_logger.error('ColdFusion: Could not find cfstat')
                return False

        # Run cfstat and collect its data
        self.checks_logger.debug('ColdFusion: Getting stats from ColdFusion')
        proc = subprocess.Popen([cfstat, '-x', '-n', '-s'],
                                stdout=subprocess.PIPE, close_fds=True)
        stats = proc.communicate()[0]

        if int(self.python_version[1]) >= 6:
            try:
                proc.kill()
            except Exception, e:
                self.checks_logger.debug('ColdFusion: cfstat process already '
{'fraction_non_alphanumeric': 0.11669735164990795, 'fraction_numerical': 0.003682197988953406, 'mean_word_length': 1.476157082748948, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1419953', 'n_tokens_mistral': 2128, 'n_tokens_neox': 1968, 'n_words': 504}