Exemple #1
0
    def __init__ (self):
        if self._instance.get('class',None) is not None:
            return

        self._instance['class'] = self

        command = environment.settings()
        self.short = command.log.short
        self.level = command.log.level

        self._option = HashTable()
        self._option.pdb           = command.debug.pdb
        self._option.reactor       = command.log.enable and (command.log.all or command.log.reactor)
        self._option.daemon        = command.log.enable and (command.log.all or command.log.daemon)
        self._option.processes     = command.log.enable and (command.log.all or command.log.processes)
        self._option.configuration = command.log.enable and (command.log.all or command.log.configuration)
        self._option.network       = command.log.enable and (command.log.all or command.log.network)
        self._option.wire          = command.log.enable and (command.log.all or command.log.packets)
        self._option.message       = command.log.enable and (command.log.all or command.log.message)
        self._option.rib           = command.log.enable and (command.log.all or command.log.rib)
        self._option.timer         = command.log.enable and (command.log.all or command.log.timers)
        self._option.routes        = command.log.enable and (command.log.all or command.log.routes)
        self._option.parser        = command.log.enable and (command.log.all or command.log.parser)
        self._option.BGPSEC        = command.log.enable and (command.log.all or command.log.BGPSEC)

        if not command.log.enable:
            self.destination = ''
            return

        self.destination = command.log.destination

        self.restart(True)
Exemple #2
0
def _env (conf):
	here = os.path.join(os.sep,os.path.join(*environment.location.split(os.sep)))

	location, directory = os.path.split(here)
	while directory:
		if directory == 'lib':
			location = os.path.join(location,'lib')
			break
		location, directory = os.path.split(location)
	# we did not break - ie, we did not find the location in the normal path.
	else:
		# let's try to see if we are running from the QA folder (for unittesting)
		location, directory = os.path.split(here)
		while directory:
			if directory == 'dev':
				location = os.path.join(location,'lib')
				break
			location, directory = os.path.split(location)
		else:
			# oh ! bad, let set the path to something ...
			location = '/lib'

	_conf_paths = []
	if conf:
		_conf_paths.append(os.path.abspath(os.path.normpath(conf)))
	if location:
		_conf_paths.append(os.path.normpath(os.path.join(location,'etc',environment.application,'%s.env' % environment.application)))
	_conf_paths.append(os.path.normpath(os.path.join('/','etc',environment.application,'%s.env' % environment.application)))

	env = HashTable()
	ini = ConfigParser.ConfigParser()

	ini_files = [path for path in _conf_paths if os.path.exists(path)]
	if ini_files:
		ini.read(ini_files[0])

	for section in environment.configuration:
		default = environment.configuration[section]

		for option in default:
			convert = default[option]['read']
			try:
				proxy_section = '%s.%s' % (environment.application,section)
				env_name = '%s.%s' % (proxy_section,option)
				rep_name = env_name.replace('.','_')

				if env_name in os.environ:
					conf = os.environ.get(env_name)
				elif rep_name in os.environ:
					conf = os.environ.get(rep_name)
				else:
					if sys.version_info[0] < 3:
						conf = environment.unquote(ini.get(proxy_section,option,nonedict))
					else:
						conf = environment.unquote(ini.get(proxy_section,option,vars=nonedict))
					# name without an = or : in the configuration and no value
					if conf is None:
						conf = default[option]['value']
			except (ConfigParser.NoSectionError,ConfigParser.NoOptionError):
				conf = default[option]['value']
			try:
				env.setdefault(section,HashTable())[option] = convert(conf)
			except TypeError:
				raise environment.Error('invalid value for %s.%s : %s' % (section,option,conf))

	return env
Exemple #3
0
def _env (conf):
	here = os.path.join(os.sep,*os.path.join(environment.location.split(os.sep)))

	location, directory = os.path.split(here)
	while directory:
		if directory == 'lib':
			location = os.path.join(location,'lib')
			break
		location, directory = os.path.split(location)
	# we did not break - ie, we did not find the location in the normal path.
	else:
		# let's try to see if we are running from the QA folder (for unittesting)
		location, directory = os.path.split(here)
		while directory:
			if directory == 'dev':
				location = os.path.join(location,'lib')
				break
			location, directory = os.path.split(location)
		else:
			# oh ! bad, let set the path to something ...
			location = '/lib'

	_conf_paths = []
	if conf:
		_conf_paths.append(os.path.abspath(os.path.normpath(conf)))
	if location:
		_conf_paths.append(os.path.normpath(os.path.join(location,'etc',environment.application,'%s.env' % environment.application)))
	_conf_paths.append(os.path.normpath(os.path.join('/','etc',environment.application,'%s.env' % environment.application)))

	env = HashTable()
	ini = ConfigParser.ConfigParser()

	ini_files = [path for path in _conf_paths if os.path.exists(path)]
	if ini_files:
		ini.read(ini_files[0])

	for section in environment.configuration:
		default = environment.configuration[section]

		for option in default:
			convert = default[option]['read']
			try:
				proxy_section = '%s.%s' % (environment.application,section)
				env_name = '%s.%s' % (proxy_section,option)
				rep_name = env_name.replace('.','_')

				if env_name in os.environ:
					conf = os.environ.get(env_name)
				elif rep_name in os.environ:
					conf = os.environ.get(rep_name)
				else:
					conf = environment.unquote(ini.get(proxy_section,option,nonedict))
					# name without an = or : in the configuration and no value
					if conf is None:
						conf = default[option]['value']
			except (ConfigParser.NoSectionError,ConfigParser.NoOptionError):
				conf = default[option]['value']
			try:
				env.setdefault(section,HashTable())[option] = convert(conf)
			except TypeError:
				raise environment.Error('invalid value for %s.%s : %s' % (section,option,conf))

	return env