def setup_logging(config_uri, global_conf=None, fileConfig=fileConfig, configparser=configparser): """ Set up logging via :func:`logging.config.fileConfig` with the filename specified via ``config_uri`` (a string in the form ``filename#sectionname``). ConfigParser defaults are specified for the special ``__file__`` and ``here`` variables, similar to PasteDeploy config loading. Extra defaults can optionally be specified as a dict in ``global_conf``. """ path, _ = _getpathsec(config_uri, None) parser = configparser.ConfigParser() parser.read([path]) if parser.has_section('loggers'): config_file = os.path.abspath(path) if global_conf: # Copy to avoid side effects global_conf = dict(global_conf) else: global_conf = {} global_conf.update(__file__=config_file, here=os.path.dirname(config_file)) return fileConfig(config_file, global_conf)
def load_settings(configurationPath, basePath): 'Load sensitive settings from hidden configuration file' settings = {} defaultByKey = {'here': basePath} configParser = configparser.ConfigParser(defaultByKey) if not configParser.read(configurationPath): raise Exception('Could not open %s' % configurationPath) for section in configParser.sections(): try: settings.update(configParser.items(section)) except InterpolationMissingOptionError: pass return settings
def setUp(self): self._tmpdir = tempfile.mkdtemp() dbpath = os.path.join(self._tmpdir, 'test.db') uri = "file://" + dbpath config = configparser.ConfigParser() config.read(os.path.join(CONFIG_PATH, "testing.ini")) settings = dict(config['app:main']) settings['zodbconn.uri'] = uri settings['profile.store'] = self._tmpdir app = main({}, **settings) self.db = app.registry._zodb_databases[''] from webtest import TestApp self.testapp = TestApp(app)
def run(self): # print defaults if self.options.printcfg: data = config.get_cfg_storage(SETTINGS_OB_ID).export(True) parser = configparser.ConfigParser(dict_type=OrderedDict) for key, val in sorted(data.items()): parser.set(configparser.DEFAULTSECT, key, val.replace('%', '%%')) fp = NativeIO() try: parser.write(fp) finally: pass print (fp.getvalue()) return if self.options.all: section = '' else: section = self.options.section # print description groups = sorted(config.get_cfg_storage(ID_SETTINGS_GROUP).items()) for name, group in groups: if section and name != section: continue print ('') title = group.__title__ or name print (grpTitleWrap.fill(title)) if group.__description__: print (grpDescriptionWrap.fill( group.__description__)) print ('') for node in group.__fields__.values(): default = '<required>' if node.required else node.default print (nameWrap.fill( ('%s.%s: %s (%s: %s)' % ( name, node.name, node.title, node.__class__.__name__, default)))) print (nameTitleWrap.fill(node.description)) print ('')
def logging_file_config(config_file, fileConfig=fileConfig, configparser=configparser): """ Setup logging via the logging module's fileConfig function with the specified ``config_file``, if applicable. ConfigParser defaults are specified for the special ``__file__`` and ``here`` variables, similar to PasteDeploy config loading. """ parser = configparser.ConfigParser() parser.read([config_file]) if parser.has_section('loggers'): config_file = os.path.abspath(config_file) return fileConfig( config_file, dict(__file__=config_file, here=os.path.dirname(config_file)))
def setUpModule(): # Load the test settings settings = SETTINGS config = configparser.ConfigParser() config.read('test.ini') for option in config.options('app:main'): settings[option] = config.get('app:main', option) SETTINGS.update(settings) # Set up the database connection engine = engine_from_config(settings, 'sqlalchemy.') DBSession.configure(bind=engine) Base.metadata.bind = engine # Initialize the query property Base.query = DBSession.query_property() # Initialize the database Base.metadata.create_all()
def setup_logging(config_uri, fileConfig=fileConfig, configparser=configparser): """ Set up logging via the logging module's fileConfig function with the filename specified via ``config_uri`` (a string in the form ``filename#sectionname``). ConfigParser defaults are specified for the special ``__file__`` and ``here`` variables, similar to PasteDeploy config loading. """ path, _ = _getpathsec(config_uri, None) parser = configparser.ConfigParser() parser.read([path]) if parser.has_section('loggers'): config_file = os.path.abspath(path) return fileConfig( config_file, dict(__file__=config_file, here=os.path.dirname(config_file)))
import sys import logging from pyramid.compat import configparser from pyramid.util import DottedNameResolver from pyramid.paster import bootstrap # pshellintellij uses first two arguments as ports to connect shell if len(sys.argv) > 3: config_file = sys.argv[3] else: config_file = 'development.ini' bootstrap = (bootstrap, ) config = configparser.ConfigParser() config.read(config_file) resolver = DottedNameResolver(None) loaded_objects = {} object_help = {} setup = None try: items = config.items('pshell') for k, v in items: if k == 'setup': setup = v else: loaded_objects[k] = resolver.maybe_resolve(v) object_help[k] = v except configparser.NoSectionError: pass