<commit_before>#!/usr/bin/env python
# encoding: utf-8
"""
configuration.py

Created by <NAME> on 2011-11-29.
Copyright (c) 2011 Exa Networks. All rights reserved.
"""

from .util.version import version

import os
import sys
import syslog

from .util.logger import logger
from .util.version import version

_enabled = ('1','yes','on','enable')
_all = os.environ.get('DEBUG_ALL','0') != '0'

_priorities = {
	'LOG_EMERG'    : syslog.LOG_EMERG,
	'LOG_ALERT'    : syslog.LOG_ALERT,
	'LOG_CRIT'     : syslog.LOG_CRIT,
	'LOG_ERR'      : syslog.LOG_ERR,
	'LOG_WARNING'  : syslog.LOG_WARNING,
	'LOG_NOTICE'   : syslog.LOG_NOTICE,
	'LOG_INFO'     : syslog.LOG_INFO,
	'LOG_DEBUG'    : syslog.LOG_DEBUG,
}

class log:
	LOG_DEBUG    = syslog.LOG_DEBUG
	LOG_INFO     = syslog.LOG_INFO
	LOG_NOTICE   = syslog.LOG_NOTICE
	LOG_WARNING  = syslog.LOG_WARNING
	LOG_ERR      = syslog.LOG_ERR
	LOG_CRIT     = syslog.LOG_CRIT
	LOG_ALERT    = syslog.LOG_ALERT
	LOG_EMERG    = syslog.LOG_EMERG
	

class _Configuration (object):
	_instance = None
	
	PID       = os.environ.get('PID','')
	USER      = os.environ.get('USER','nobody')
	DAEMONIZE = os.environ.get('DAEMONIZE','0') not in ['','1','yes','Yes','YES']
	VERSION   = version
	PROGRAM   = (sys.argv + ['', ''])[1] # I don't like perl :)
	SPEED     = 2 # 0.01
	CONNECT   = os.environ.get('CONNECT','1').lower() in _enabled
	PROFILE   = os.environ.get('PROFILE','0')
	RESOLV    = os.environ.get('RESOLV', '/etc/resolv.conf')
	MIN_WORK  = int(os.environ.get('MIN_WORKERS','1')) if os.environ.get('MIN_WORKERS','1').isdigit() else 5
	MAX_WORK  = int(os.environ.get('MAX_WORKERS','1')) if os.environ.get('MAX_WORKERS','1').isdigit() else 25

	_location = os.path.normpath(sys.argv[0]) if sys.argv[0].startswith('/') else os.path.normpath(os.path.join(cwd,sys.argv[0]))
	_paths = (
		os.path.join(os.path.join(os.sep,*os.path.join(_location.split(os.sep)[:-3])),'etc','exaproxy','html'),
		os.path.normpath('/etc/exaproxy/html'),
	)

	HTML      = [path for path in _paths if os.path.exists(path)][0] # XXX: This will fail if we can not find a configuration location

	def __init__ (self):
		if os.environ.get('SYSLOG',None):
			logger.syslog()
		logger.level = _priorities.get(os.environ.get('LOG',None),syslog.LOG_DEBUG if _all else syslog.LOG_ERR)
		
		for section in ('main','supervisor','daemon','server','client','manager','worker','download','http','client'):
			enabled = os.environ.get('DEBUG_%s' % section.upper(),'0').lower() in _enabled or _all
			logger.status[section] = enabled

def Configuration ():
	if _Configuration._instance:
		return _Configuration._instance
	instance = _Configuration()
	_Configuration._instance = instance
	return instance<commit_msg>fix configuration option to read worker number<commit_after>#!/usr/bin/env python
# encoding: utf-8
"""
configuration.py

Created by <NAME> on 2011-11-29.
Copyright (c) 2011 Exa Networks. All rights reserved.
"""

from .util.version import version

import os
import sys
import syslog

from .util.logger import logger
from .util.version import version

_enabled = ('1','yes','on','enable')
_all = os.environ.get('DEBUG_ALL','0') != '0'

_priorities = {
	'LOG_EMERG'    : syslog.LOG_EMERG,
	'LOG_ALERT'    : syslog.LOG_ALERT,
	'LOG_CRIT'     : syslog.LOG_CRIT,
	'LOG_ERR'      : syslog.LOG_ERR,
	'LOG_WARNING'  : syslog.LOG_WARNING,
	'LOG_NOTICE'   : syslog.LOG_NOTICE,
	'LOG_INFO'     : syslog.LOG_INFO,
	'LOG_DEBUG'    : syslog.LOG_DEBUG,
}

class log:
	LOG_DEBUG    = syslog.LOG_DEBUG
	LOG_INFO     = syslog.LOG_INFO
	LOG_NOTICE   = syslog.LOG_NOTICE
	LOG_WARNING  = syslog.LOG_WARNING
	LOG_ERR      = syslog.LOG_ERR
	LOG_CRIT     = syslog.LOG_CRIT
	LOG_ALERT    = syslog.LOG_ALERT
	LOG_EMERG    = syslog.LOG_EMERG
	

class _Configuration (object):
	_instance = None
	
	PID       = os.environ.get('PID','')
	USER      = os.environ.get('USER','nobody')
	DAEMONIZE = os.environ.get('DAEMONIZE','0') not in ['','1','yes','Yes','YES']
	VERSION   = version
	PROGRAM   = (sys.argv + ['', ''])[1] # I don't like perl :)
	SPEED     = 2 # 0.01
	CONNECT   = os.environ.get('CONNECT','1').lower() in _enabled
	PROFILE   = os.environ.get('PROFILE','0')
	RESOLV    = os.environ.get('RESOLV', '/etc/resolv.conf')
	MIN_WORK  = int(os.environ.get('MIN_WORKERS')) if os.environ.get('MIN_WORKERS','').isdigit() else 5
	MAX_WORK  = int(os.environ.get('MAX_WORKERS')) if os.environ.get('MAX_WORKERS','').isdigit() else 25

	_location = os.path.normpath(sys.argv[0]) if sys.argv[0].startswith('/') else os.path.normpath(os.path.join(cwd,sys.argv[0]))
	_paths = (
		os.path.join(os.path.join(os.sep,*os.path.join(_location.split(os.sep)[:-3])),'etc','exaproxy','html'),
		os.path.normpath('/etc/exaproxy/html'),
	)

	HTML      = [path for path in _paths if os.path.exists(path)][0] # XXX: This will fail if we can not find a configuration location

	def __init__ (self):
		if os.environ.get('SYSLOG',None):
			logger.syslog()
		logger.level = _priorities.get(os.environ.get('LOG',None),syslog.LOG_DEBUG if _all else syslog.LOG_ERR)
		
		for section in ('main','supervisor','daemon','server','client','manager','worker','download','http','client'):
			enabled = os.environ.get('DEBUG_%s' % section.upper(),'0').lower() in _enabled or _all
			logger.status[section] = enabled

def Configuration ():
	if _Configuration._instance:
		return _Configuration._instance
	instance = _Configuration()
	_Configuration._instance = instance
	return instance
{'fraction_non_alphanumeric': 0.16749677181331857, 'fraction_numerical': 0.013281682346430549, 'mean_word_length': 4.279454722492697, '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': 2, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6586738', 'n_tokens_mistral': 2107, 'n_tokens_neox': 2042, 'n_words': 383}