def load_environment(conf): """ Configure the Pylons environment via the ``pylons.config`` object. This code should only need to be run once. """ os.environ['CKAN_CONFIG'] = conf['__file__'] # Pylons paths root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) valid_base_public_folder_names = ['public'] static_files = conf.get('ckan.base_public_folder', 'public') conf['ckan.base_public_folder'] = static_files if static_files not in valid_base_public_folder_names: raise CkanConfigurationException( 'You provided an invalid value for ckan.base_public_folder. ' 'Possible values are: "public".' ) log.info('Loading static files from %s' % static_files) paths = dict(root=root, controllers=os.path.join(root, 'controllers'), static_files=os.path.join(root, static_files), templates=[]) # Initialize main CKAN config object config.update(conf) # Setup the SQLAlchemy database engine # Suppress a couple of sqlalchemy warnings msgs = ['^Unicode type received non-unicode bind param value', "^Did not recognize type 'BIGINT' of column 'size'", "^Did not recognize type 'tsvector' of column 'search_vector'" ] for msg in msgs: warnings.filterwarnings('ignore', msg, sqlalchemy.exc.SAWarning) # load all CKAN plugins p.load_all() # Check Redis availability if not is_redis_available(): log.critical('Could not connect to Redis.') app_globals.reset() # issue #3260: remove idle transaction # Session that was used for getting all config params nor committed, # neither removed and we have idle connection as result model.Session.commit() # Build JavaScript translations. Must be done after plugins have # been loaded. build_js_translations()
def build_js_translations(self): u""" Build JS translations in temporary directory. """ old_translations_dir = i18n._JS_TRANSLATIONS_DIR i18n._JS_TRANSLATIONS_DIR = self.temp_dir try: return i18n.build_js_translations() finally: i18n._JS_TRANSLATIONS_DIR = old_translations_dir
def build_js_translations(self): u''' Build JS translations in temporary directory. ''' old_translations_dir = i18n._JS_TRANSLATIONS_DIR i18n._JS_TRANSLATIONS_DIR = self.temp_dir try: return i18n.build_js_translations() finally: i18n._JS_TRANSLATIONS_DIR = old_translations_dir
def load_environment(conf: Union[Config, CKANConfig]): """ Configure the Pylons environment via the ``pylons.config`` object. This code should only need to be run once. """ os.environ['CKAN_CONFIG'] = cast(str, conf['__file__']) valid_base_public_folder_names = ['public', 'public-bs3'] static_files = conf.get('ckan.base_public_folder', 'public') conf['ckan.base_public_folder'] = static_files if static_files not in valid_base_public_folder_names: raise CkanConfigurationException( 'You provided an invalid value for ckan.base_public_folder. ' 'Possible values are: "public" and "public-bs3".') log.info('Loading static files from %s' % static_files) # Initialize main CKAN config object config.update(conf) # Setup the SQLAlchemy database engine # Suppress a couple of sqlalchemy warnings msgs = [ '^Unicode type received non-unicode bind param value', "^Did not recognize type 'BIGINT' of column 'size'", "^Did not recognize type 'tsvector' of column 'search_vector'" ] for msg in msgs: warnings.filterwarnings('ignore', msg, sqlalchemy.exc.SAWarning) # load all CKAN plugins p.load_all() # Check Redis availability if not is_redis_available(): log.critical('Could not connect to Redis.') app_globals.reset() # Build JavaScript translations. Must be done after plugins have # been loaded. build_js_translations()
def load_environment(conf): """ Configure the Pylons environment via the ``pylons.config`` object. This code should only need to be run once. """ if six.PY2: # this must be run at a time when the env is semi-setup, thus inlined # here. Required by the deliverance plugin and iATI from pylons.wsgiapp import PylonsApp import pkg_resources find_controller_generic = getattr(PylonsApp.find_controller, '_old_find_controller', PylonsApp.find_controller) # This is from pylons 1.0 source, will monkey-patch into 0.9.7 def find_controller(self, controller): if controller in self.controller_classes: return self.controller_classes[controller] # Check to see if its a dotted name if '.' in controller or ':' in controller: ep = pkg_resources.EntryPoint.parse('x={0}'.format(controller)) if hasattr(ep, 'resolve'): # setuptools >= 10.2 mycontroller = ep.resolve() else: # setuptools >= 11.3 mycontroller = ep.load(False) self.controller_classes[controller] = mycontroller return mycontroller return find_controller_generic(self, controller) find_controller._old_find_controller = find_controller_generic PylonsApp.find_controller = find_controller os.environ['CKAN_CONFIG'] = conf['__file__'] # Pylons paths root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) valid_base_public_folder_names = ['public'] static_files = conf.get('ckan.base_public_folder', 'public') conf['ckan.base_public_folder'] = static_files if static_files not in valid_base_public_folder_names: raise CkanConfigurationException( 'You provided an invalid value for ckan.base_public_folder. ' 'Possible values are: "public".') log.info('Loading static files from %s' % static_files) paths = dict(root=root, controllers=os.path.join(root, 'controllers'), static_files=os.path.join(root, static_files), templates=[]) # Initialize main CKAN config object config.update(conf) if six.PY2: # Initialize Pylons own config object pylons_config.init_app(conf['global_conf'], conf, package='ckan', paths=paths) # Update the main CKAN config object with the Pylons specific stuff, # as it is quite hard to keep them separated. This should be removed # once Pylons support is dropped config.update(pylons_config) # Setup the SQLAlchemy database engine # Suppress a couple of sqlalchemy warnings msgs = [ '^Unicode type received non-unicode bind param value', "^Did not recognize type 'BIGINT' of column 'size'", "^Did not recognize type 'tsvector' of column 'search_vector'" ] for msg in msgs: warnings.filterwarnings('ignore', msg, sqlalchemy.exc.SAWarning) # load all CKAN plugins p.load_all() if not p.plugin_loaded('managed_search_schema'): search.check_solr_schema_version() # Check Redis availability if not is_redis_available(): log.critical('Could not connect to Redis.') app_globals.reset() # issue #3260: remove idle transaction # Session that was used for getting all config params nor committed, # neither removed and we have idle connection as result model.Session.commit() # Build JavaScript translations. Must be done after plugins have # been loaded. build_js_translations()
def load_environment(global_conf, app_conf): """ Configure the Pylons environment via the ``pylons.config`` object. This code should only need to be run once. """ # this must be run at a time when the env is semi-setup, thus inlined here. # Required by the deliverance plugin and iATI from pylons.wsgiapp import PylonsApp import pkg_resources find_controller_generic = PylonsApp.find_controller # This is from pylons 1.0 source, will monkey-patch into 0.9.7 def find_controller(self, controller): if controller in self.controller_classes: return self.controller_classes[controller] # Check to see if its a dotted name if '.' in controller or ':' in controller: ep = pkg_resources.EntryPoint.parse('x={0}'.format(controller)) if hasattr(ep, 'resolve'): # setuptools >= 10.2 mycontroller = ep.resolve() else: # setuptools >= 11.3 mycontroller = ep.load(False) self.controller_classes[controller] = mycontroller return mycontroller return find_controller_generic(self, controller) PylonsApp.find_controller = find_controller os.environ['CKAN_CONFIG'] = global_conf['__file__'] # Pylons paths root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) valid_base_public_folder_names = ['public', 'public-bs2'] static_files = app_conf.get('ckan.base_public_folder', 'public') app_conf['ckan.base_public_folder'] = static_files if static_files not in valid_base_public_folder_names: raise CkanConfigurationException( 'You provided an invalid value for ckan.base_public_folder. ' 'Possible values are: "public" and "public-bs2".' ) log.info('Loading static files from %s' % static_files) paths = dict(root=root, controllers=os.path.join(root, 'controllers'), static_files=os.path.join(root, static_files), templates=[]) # Initialize main CKAN config object config.update(global_conf) config.update(app_conf) # Initialize Pylons own config object pylons_config.init_app(global_conf, app_conf, package='ckan', paths=paths) # Update the main CKAN config object with the Pylons specific stuff, as it # quite hard to keep them separated. This should be removed once Pylons # support is dropped config.update(pylons_config) # Setup the SQLAlchemy database engine # Suppress a couple of sqlalchemy warnings msgs = ['^Unicode type received non-unicode bind param value', "^Did not recognize type 'BIGINT' of column 'size'", "^Did not recognize type 'tsvector' of column 'search_vector'" ] for msg in msgs: warnings.filterwarnings('ignore', msg, sqlalchemy.exc.SAWarning) # load all CKAN plugins p.load_all() # Check Redis availability if not is_redis_available(): log.critical('Could not connect to Redis.') app_globals.reset() # issue #3260: remove idle transaction # Session that was used for getting all config params nor committed, # neither removed and we have idle connection as result model.Session.commit() # Build JavaScript translations. Must be done after plugins have # been loaded. build_js_translations()
def js(): build_js_translations() click.secho(u'JS translation build: SUCCESS', fg=u'green', bold=True)
def load_environment(global_conf, app_conf): """ Configure the Pylons environment via the ``pylons.config`` object. This code should only need to be run once. """ # this must be run at a time when the env is semi-setup, thus inlined here. # Required by the deliverance plugin and iATI from pylons.wsgiapp import PylonsApp import pkg_resources find_controller_generic = PylonsApp.find_controller # This is from pylons 1.0 source, will monkey-patch into 0.9.7 def find_controller(self, controller): if controller in self.controller_classes: return self.controller_classes[controller] # Check to see if its a dotted name if '.' in controller or ':' in controller: ep = pkg_resources.EntryPoint.parse('x={0}'.format(controller)) if hasattr(ep, 'resolve'): # setuptools >= 10.2 mycontroller = ep.resolve() else: # setuptools >= 11.3 mycontroller = ep.load(False) self.controller_classes[controller] = mycontroller return mycontroller return find_controller_generic(self, controller) PylonsApp.find_controller = find_controller os.environ['CKAN_CONFIG'] = global_conf['__file__'] # Pylons paths root = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) paths = dict(root=root, controllers=os.path.join(root, 'controllers'), static_files=os.path.join(root, 'public'), templates=[]) # Initialize main CKAN config object config.update(global_conf) config.update(app_conf) # Initialize Pylons own config object pylons_config.init_app(global_conf, app_conf, package='ckan', paths=paths) # Update the main CKAN config object with the Pylons specific stuff, as it # quite hard to keep them separated. This should be removed once Pylons # support is dropped config.update(pylons_config) # Setup the SQLAlchemy database engine # Suppress a couple of sqlalchemy warnings msgs = [ '^Unicode type received non-unicode bind param value', "^Did not recognize type 'BIGINT' of column 'size'", "^Did not recognize type 'tsvector' of column 'search_vector'" ] for msg in msgs: warnings.filterwarnings('ignore', msg, sqlalchemy.exc.SAWarning) # Check Redis availability if not is_redis_available(): log.critical('Could not connect to Redis.') # load all CKAN plugins p.load_all() app_globals.reset() # Build JavaScript translations. Must be done after plugins have # been loaded. build_js_translations()