<commit_before>""" Module to handle squid configuration and setup """

import logging

from osg_configure.modules import utilities
from osg_configure.modules import configfile
from osg_configure.modules import validation
from osg_configure.modules.configurationbase import BaseConfiguration

__all__ = ['SquidConfiguration']


class SquidConfiguration(BaseConfiguration):
  """Class to handle attributes related to squid configuration and setup"""
  
  def __init__(self, *args, **kwargs):
    # pylint: disable-msg=W0142
    super(SquidConfiguration, self).__init__(*args, **kwargs)
    self.log('SquidConfiguration.__init__ started')
    self.options = {'location' : 
                      configfile.Option(name = 'location',
                                        default_value = 'None',
                                        mapping = 'OSG_SQUID_LOCATION'),
                    'policy' : 
                      configfile.Option(name = 'policy',
                                        required = configfile.Option.OPTIONAL,
                                        mapping = 'OSG_SQUID_POLICY'),
                    'cache_size' : 
                      configfile.Option(name = 'cache_size',
                                        required = configfile.Option.OPTIONAL,
                                        default_value = 0,
                                        opt_type = int,
                                        mapping = 'OSG_SQUID_CACHE_SIZE'),
                    'memory_size' : 
                      configfile.Option(name = 'memory_size',
                                        required = configfile.Option.OPTIONAL,
                                        default_value = 0,
                                        opt_type = int,
                                        mapping = 'OSG_SQUID_MEM_CACHE')}
    self.config_section = 'Squid'
    self.log('SquidConfiguration.__init__ completed')
      
  def parseConfiguration(self, configuration):
    """Try to get configuration information from ConfigParser or SafeConfigParser object given
    by configuration and write recognized settings to attributes dict
    """
    self.log('SquidConfiguration.parseConfiguration started')
    
    self.checkConfig(configuration)

    if not configuration.has_section(self.config_section):
      self.enabled = False
      self.log("%s section not in config file" % self.config_section)
      self.log('SquidConfiguration.parseConfiguration completed')
      return
    
    if not self.setStatus(configuration):
      self.log('SquidConfiguration.parseConfiguration completed')
      if not self.ignored and not self.enabled:
        return True

    self.getOptions(configuration, ignore_options = ['enabled'])
    
    if not (utilities.blank(self.options['location'].value) or 
            self.options['location'].value == 'None'):
      if ":" not in self.options['location'].value:        
        self.options['location'].value += ":3128"        
    
    if configuration.get(self.config_section, 'location').upper() == 'UNAVAILABLE':
      self.options['location'].value = 'UNAVAILABLE'
    self.log('SquidConfiguration.parseConfiguration completed')

  
# pylint: disable-msg=W0613
  def checkAttributes(self, attributes):
    """Check attributes currently stored and make sure that they are consistent"""
    self.log('SquidConfiguration.checkAttributes started')
    attributes_ok = True
    if utilities.ce_installed():
      return attributes_ok
    
    if not self.enabled:
      self.log("Squid is not enabled, sites must enable this \n" +
               "section, location can be set to UNAVAILABLE if squid is \n" +
               "not present",
               level = logging.WARNING)
      self.log('squid not enabled')<commit_msg>Bug fixes for squid detection of standalone rsv installs<commit_after>""" Module to handle squid configuration and setup """

import logging

from osg_configure.modules import utilities
from osg_configure.modules import configfile
from osg_configure.modules import validation
from osg_configure.modules.configurationbase import BaseConfiguration

__all__ = ['SquidConfiguration']


class SquidConfiguration(BaseConfiguration):
  """Class to handle attributes related to squid configuration and setup"""
  
  def __init__(self, *args, **kwargs):
    # pylint: disable-msg=W0142
    super(SquidConfiguration, self).__init__(*args, **kwargs)
    self.log('SquidConfiguration.__init__ started')
    self.options = {'location' : 
                      configfile.Option(name = 'location',
                                        default_value = 'None',
                                        mapping = 'OSG_SQUID_LOCATION'),
                    'policy' : 
                      configfile.Option(name = 'policy',
                                        required = configfile.Option.OPTIONAL,
                                        mapping = 'OSG_SQUID_POLICY'),
                    'cache_size' : 
                      configfile.Option(name = 'cache_size',
                                        required = configfile.Option.OPTIONAL,
                                        default_value = 0,
                                        opt_type = int,
                                        mapping = 'OSG_SQUID_CACHE_SIZE'),
                    'memory_size' : 
                      configfile.Option(name = 'memory_size',
                                        required = configfile.Option.OPTIONAL,
                                        default_value = 0,
                                        opt_type = int,
                                        mapping = 'OSG_SQUID_MEM_CACHE')}
    self.config_section = 'Squid'
    self.log('SquidConfiguration.__init__ completed')
      
  def parseConfiguration(self, configuration):
    """Try to get configuration information from ConfigParser or SafeConfigParser object given
    by configuration and write recognized settings to attributes dict
    """
    self.log('SquidConfiguration.parseConfiguration started')
    
    self.checkConfig(configuration)

    if not configuration.has_section(self.config_section):
      self.enabled = False
      self.log("%s section not in config file" % self.config_section)
      self.log('SquidConfiguration.parseConfiguration completed')
      return
    
    if not self.setStatus(configuration):
      self.log('SquidConfiguration.parseConfiguration completed')
      if not self.ignored and not self.enabled:
        return True

    self.getOptions(configuration, ignore_options = ['enabled'])
    
    if not (utilities.blank(self.options['location'].value) or 
            self.options['location'].value == 'None'):
      if ":" not in self.options['location'].value:        
        self.options['location'].value += ":3128"        
    
    if configuration.get(self.config_section, 'location').upper() == 'UNAVAILABLE':
      self.options['location'].value = 'UNAVAILABLE'
    self.log('SquidConfiguration.parseConfiguration completed')

  
# pylint: disable-msg=W0613
  def checkAttributes(self, attributes):
    """Check attributes currently stored and make sure that they are consistent"""
    self.log('SquidConfiguration.checkAttributes started')
    attributes_ok = True
    if not utilities.ce_installed():
      return attributes_ok
    
    if not self.enabled:
      self.log("Squid is not enabled, sites must enable this \n" +
               "section, location can be set to UNAVAILABLE if squid is \n" +
               "not present",
               level = logging.WARNING)
      self.log('squid not enabled')
{'fraction_non_alphanumeric': 0.08783694937541091, 'fraction_numerical': 0.0036817882971729127, 'mean_word_length': 2.015860428231562, 'pattern_counts': {'":': 4, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2221048', 'n_tokens_mistral': 1838, 'n_tokens_neox': 1762, 'n_words': 454}