def __init__(self): TypeConvertor.__init__(self) import deltapy.communication.ice.utils as ice_utils ice_utils.set_encodings( config.get_app_config_store().get('global', 'encoding', 'utf-8'), 'utf-8')
def start(self, **options): ''' Starts request processor. @keyword processor_name: Processor to start. If it not provided, default processor in configs will be used. @note: Other options will directly pass to the processor. ''' # Getting configuration store config_store = config.get_app_config_store('request_processor') default_processor_name = config_store.get('global', 'default', None) processor_name = options.get('processor_name') if processor_name is not None: self.set_default_processor(processor_name) options.pop('processor_name') elif default_processor_name is not None: self.set_default_processor(default_processor_name) params = config_store.get_section_data(self._default_processor_name) params.update(**options) processor = self.get_processor() processor.configure(params) self._event.set() RequestProcessorManager.logger.info('Request processor started.')
def load(self): ''' Loads all channels. ''' try: message = 'Loading channels' ChannelManager.LOGGER.debug(message) config_store = config_services.get_app_config_store('channel') self._enabled = config_store.get('global', 'enabled') if self._enabled is not None: self._enabled = eval(self._enabled) else: self._enabled = True if self._enabled: for section in config_store.get_sections(): if section != 'global': section_data = config_store.get_section_data(section) channel_id = section for key in section_data: section_data[key] = eval(str(section_data[key])) certificate = self._get_certificate( channel_id, **section_data) self.register(channel_id, certificate, **section_data) else: message = 'Channel manager is disabled' ChannelManager.LOGGER.info(message) except ConfigFileNotFoundException: message = 'Channel settings not found and channel manager is disabled' ChannelManager.LOGGER.info(message) self._enabled = False
def __init__(self): CultureManager.__init__(self) config_store = config_services.get_app_config_store() if config_store.has_key('global', 'locale'): locale = config_store.get('global', 'locale') encoding = config_store.get('global', 'encoding') self.set_locale(locale, encoding=encoding)
def reload(self): ''' Re-reads configs from the config file and applying them. ''' config_store = \ config_services.get_app_config_store('request_processor') params = config_store.get_section_data(self._default_processor_name) processor = self.get_processor() processor.resize(int(params.get("max_processes")))
def get_config_data(self, cache_type_name): ''' Returns configuration data for specified cache. @param cache_type_name: cache type name @return: DynamicObject ''' try: config_store = config_services.get_app_config_store('caching') return config_store.get_section_data(cache_type_name) except: return {}
def make_defined_pools(self): ''' Makes connection pools by database configuration. ''' # Getting a configuration store on database settings config_store = config.get_app_config_store('database') # Getting default pool name default_pool_name = config_store.get('global', 'default', None) if default_pool_name is None: raise DatabaseManagerException( 'Default connection pool is not determined.') # Getting all sections in database settings sections = config_store.get_sections() for name in sections: if name != 'global': data = config_store.get_section_data(name) connection_string = data.get('connection', None) if not connection_string: raise DatabaseManagerException( 'Connection pool[%s] has not connection string.' % name) connection_string = application.get_real_path( connection_string) pool_name = name if name == default_pool_name: pool_name = StoreConnectionPool.DEFAULT min_connections = int(data.get('min', 0)) max_connections = int(data.get('max', 0)) growup = int(data.get('growup', 0)) encrypted_password = data.get('encrypted_password', None) life_time = data.get('life_time', None) pool = StoreConnectionPool( pool_name, connection_string, min_connections, max_connections, growup, encrypted_password=encrypted_password, life_time=life_time) self.add_pool(pool)
def __get_process_unit_config__(self, name): ''' Returns process unit configuration from batch.config file. @param name: process unit name ''' # Getting batch configuration store config_store = config.get_app_config_store('batch') # Getting default parameters from configuration file. if config_store.has_section(name): return config_store.get_section_data(name) return DynamicObject(thread_count=1)
def get_default_cache_type_name(self): ''' Returns default cache type @return: str ''' if self._default_cache_type_name is None: try: config_store = config_services.get_app_config_store('caching') self._default_cache_type_name = config_store.get( 'global', 'default') except: self._default_cache_type_name = MemoryCache.CACHE_TYPE_NAME return self._default_cache_type_name
def get_trusted_ips(self): ''' Returns a list of IPs that can be trusted. @return: List of trusted IPs. @rtype: list(str) ''' result = set() configs = config_services.get_app_config_store() if configs.has_key('security', 'trusted_ips'): option_str = configs.get('security', 'trusted_ips') for trusted_ip in option_str.split(','): result.add(trusted_ip.strip()) return result
def setup(self, name, **params): ''' Setups all providers. @param name: initialization name. @param **params: ip: cache server IP port: cache server main port auth_key: authentication key cache_port: cache service port ''' config_store = config_services.get_app_config_store('caching') enable = eval(config_store.get('remote_cache', 'enable', 'False')) if not config_store.has_section('remote_cache') or not enable: return None config_params = config_store.get_section_data('remote_cache') config_params.update(params) # Reading configurations ip = config_params.get('ip', None) port = config_params.get('port', 0) if port is not None: port = int(config_params.get('port', 0)) data = {} data['name'] = name data['ip'] = ip data['port'] = port data['auth_key'] = config_params.get('auth_key', None) data['cache_port'] = config_params.get('cache_port', 0) if data['cache_port']: data['cache_port'] = int(data['cache_port']) # Creating socket sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM) sock.connect((ip, port)) connection_data = self._create_cache_(sock, ip, name, data) connection_data['port'] = port connection_data['ip'] = ip self._connection_data = connection_data return connection_data
def get_timeout(self): ''' Returns get global timeout value. @rtype: int @return: timeout value ''' session = get_current_session() timeout = session.get_context().get('timeout') if timeout is None: config_store = \ config_services.get_app_config_store('request_processor') timeout = config_store.get('global', 'timeout') if timeout is not None: timeout = int(timeout) return timeout
def get_real_path(environmental_path): ''' Returns replaced path with environmental paths for example : $DELTA_HOME/test.db -> /opt/deltapy/test.db @param path: environmental path @return: str ''' result = environmental_path config_store = config.get_app_config_store() if config_store.has_section('path'): paths = config_store.get_section_data('path') for pth in paths: rpath = '$%s%s' % (pth, os.path.sep) value = '%s%s' % (paths[pth], os.path.sep) result = result.replace(rpath.upper(), value) result = result.replace(rpath.lower(), value) return result
def init_func(): settings = config_services.get_app_config_store('request_processor') backend_port = int(settings.get('zmq', 'backend_port')) max_threads = int(settings.get('zmq', 'max_threads')) if max_threads == 0: max_threads = 4 io_threads = multiprocessing.cpu_count() - 1 if io_threads < 2: io_threads = 2 ZMQRequestProcessor.LOGGER.info( "Process [{0}] is started as a subscriber by [{1}] greenlets.". format(os.getpid(), max_threads)) database_services.reset_pools() context = zmq.Context(io_threads) workers = [Worker(context, backend_port) for i in xrange(max_threads)] for worker in workers: worker.start() for worker in workers: worker.join()
def __init__(self): DeltaObject.__init__(self) self._internal_encoding = config_services.get_app_config_store().get( 'global', 'encoding', 'utf-8') self._external_encoding = 'utf-8'
def __init__(self): config_store = config.get_app_config_store('logging') if not config_store: raise Exception( 'The application has not logging configuration file.') LoggingManager.__init__(self, config_store.get_file_name())