def read_config_file_arg( argv, default, old_default, cwd=None ): config_file = None if '-c' in argv: pos = argv.index( '-c' ) argv.pop(pos) config_file = argv.pop( pos ) return find_config_file( default, old_default, config_file, cwd=cwd )
def read_config_file_arg(argv, config_names, cwd=None): if '-c' in argv: pos = argv.index('-c') argv.pop(pos) return argv.pop(pos) if cwd: cwd = [cwd, os.path.join(cwd, 'config')] return find_config_file(config_names, dirs=cwd)
def get_config(argv, use_argparse=True, cwd=None): """ Read sys.argv and parse out repository of migrations and database url. >>> import os >>> from six.moves.configparser import SafeConfigParser >>> from shutil import rmtree >>> from tempfile import mkdtemp >>> config_dir = mkdtemp() >>> os.makedirs(os.path.join(config_dir, 'config')) >>> def write_ini(path, property, value): ... p = SafeConfigParser() ... p.add_section('app:main') ... p.set('app:main', property, value) ... with open(os.path.join(config_dir, 'config', path), 'w') as f: p.write(f) >>> write_ini('tool_shed.ini', 'database_connection', 'sqlite:///pg/testdb1') >>> config = get_config(['manage_db.py', 'tool_shed'], cwd=config_dir) >>> config['repo'] 'lib/galaxy/webapps/tool_shed/model/migrate' >>> config['db_url'] 'sqlite:///pg/testdb1' >>> write_ini('galaxy.ini', 'database_file', 'moo.sqlite') >>> config = get_config(['manage_db.py'], cwd=config_dir) >>> config['db_url'] 'sqlite:///moo.sqlite?isolation_level=IMMEDIATE' >>> config['repo'] 'lib/galaxy/model/migrate' >>> rmtree(config_dir) """ config_file, config_section, database = _read_model_arguments(argv, use_argparse=use_argparse) database_defaults = DATABASE[database] if config_file is None: config_names = database_defaults.get('config_names', DEFAULT_CONFIG_NAMES) if cwd: cwd = [cwd, os.path.join(cwd, 'config')] config_file = find_config_file(config_names, dirs=cwd) repo = database_defaults['repo'] config_prefix = database_defaults.get('config_prefix', DEFAULT_CONFIG_PREFIX) config_override = database_defaults.get('config_override', 'GALAXY_CONFIG_') default_sqlite_file = database_defaults['default_sqlite_file'] if config_section is None: if not config_file or get_ext(config_file, ignore='sample') == 'yaml': config_section = database_defaults.get('config_section', None) else: # Just use the default found by load_app_properties. config_section = None properties = load_app_properties(config_file=config_file, config_prefix=config_override, config_section=config_section) if ("%sdatabase_connection" % config_prefix) in properties: db_url = properties["%sdatabase_connection" % config_prefix] elif ("%sdatabase_file" % config_prefix) in properties: database_file = properties["%sdatabase_file" % config_prefix] db_url = "sqlite:///%s?isolation_level=IMMEDIATE" % database_file else: db_url = "sqlite:///%s?isolation_level=IMMEDIATE" % default_sqlite_file return dict(db_url=db_url, repo=repo, config_file=config_file, database=database)
def optional(config_file=None): if not config_file: config_file = find_config_file(['galaxy', 'universe_wsgi']) if not config_file: print("galaxy.dependencies.optional: no config file found", file=sys.stderr) return [] rval = [] conditional = ConditionalDependencies(config_file) for opt in conditional.conditional_reqs: if conditional.check(opt.key): rval.append(str(opt)) return rval
def optional(config_file=None): if not config_file: config_file = find_config_file(['galaxy', 'universe_wsgi'], include_samples=True) if not config_file: print("galaxy.dependencies.optional: no config file found", file=sys.stderr) return [] rval = [] conditional = ConditionalDependencies(config_file) for opt in conditional.conditional_reqs: if conditional.check(opt.key): rval.append(str(opt)) return rval
def _resolve_config_file_path(self) -> str: config_file = self.app_kwds.get("config_file") if not config_file and os.environ.get(self.props.env_config_file): config_file = os.path.abspath(os.environ[self.props.env_config_file]) elif self.props.check_galaxy_root: galaxy_root = self.app_kwds.get("galaxy_root") or os.environ.get("GALAXY_ROOT_DIR") config_file = find_config(config_file, galaxy_root, app_name=self.props.app_name) config_file = absolute_config_path(config_file, galaxy_root=galaxy_root) else: config_file = find_config_file([self.props.app_name]) if not config_file or not os.path.exists(config_file): raise FileNotFoundError(f"Can not find a configuration file for {self.props.app_name}") return config_file
def _app_properties(args): config_file = find_config_file("config/galaxy.ini", "universe_wsgi.ini", args.config_file) app_properties = load_app_properties(ini_file=config_file) return app_properties
def get_config(argv, use_argparse=True, cwd=None): """ Read sys.argv and parse out repository of migrations and database url. >>> import os >>> from configparser import ConfigParser >>> from shutil import rmtree >>> from tempfile import mkdtemp >>> config_dir = mkdtemp() >>> os.makedirs(os.path.join(config_dir, 'config')) >>> def write_ini(path, property, value): ... p = ConfigParser() ... p.add_section('app:main') ... p.set('app:main', property, value) ... with open(os.path.join(config_dir, 'config', path), 'w') as f: p.write(f) >>> write_ini('tool_shed.ini', 'database_connection', 'sqlite:///pg/testdb1') >>> config = get_config(['manage_db.py', 'tool_shed'], cwd=config_dir) >>> config['repo'].endswith('tool_shed/webapp/model/migrate') True >>> config['db_url'] 'sqlite:///pg/testdb1' >>> write_ini('galaxy.ini', 'data_dir', '/moo') >>> config = get_config(['manage_db.py'], cwd=config_dir) >>> uri_with_env = os.getenv("GALAXY_TEST_DBURI", "sqlite:////moo/universe.sqlite?isolation_level=IMMEDIATE") >>> config['db_url'] == uri_with_env True >>> config['repo'].endswith('galaxy/model/migrate') True >>> rmtree(config_dir) """ config_file, config_section, database = _read_model_arguments( argv, use_argparse=use_argparse) database_defaults = DATABASE[database] if config_file is None: config_names = database_defaults.get('config_names', DEFAULT_CONFIG_NAMES) if cwd: cwd = [cwd, os.path.join(cwd, 'config')] else: cwd = [DEFAULT_CONFIG_DIR] config_file = find_config_file(config_names, dirs=cwd) repo = os.path.join(os.path.dirname(__file__), os.pardir, os.pardir, os.pardir, database_defaults['repo']) config_prefix = database_defaults.get('config_prefix', DEFAULT_CONFIG_PREFIX) config_override = database_defaults.get('config_override', 'GALAXY_CONFIG_') default_sqlite_file = database_defaults['default_sqlite_file'] if config_section is None: if not config_file or get_ext(config_file, ignore='sample') == 'yaml': config_section = database_defaults.get('config_section', None) else: # Just use the default found by load_app_properties. config_section = None properties = load_app_properties(config_file=config_file, config_prefix=config_override, config_section=config_section) if (f"{config_prefix}database_connection") in properties: db_url = properties[f"{config_prefix}database_connection"] else: db_url = f"sqlite:///{os.path.join(get_data_dir(properties), default_sqlite_file)}?isolation_level=IMMEDIATE" install_database_connection = properties.get('install_database_connection') return dict(db_url=db_url, repo=repo, config_file=config_file, database=database, install_database_connection=install_database_connection)
def config_file_from_args(args, legacy_config_override=None, app=None): app = app or getattr(args, "app", "galaxy") config_file = legacy_config_override or args.config_file or find_config_file( app) return config_file
def get_config(argv, use_argparse=True, cwd=None): """ Read sys.argv and parse out repository of migrations and database url. >>> import os >>> from six.moves.configparser import SafeConfigParser >>> from shutil import rmtree >>> from tempfile import mkdtemp >>> config_dir = mkdtemp() >>> os.makedirs(os.path.join(config_dir, 'config')) >>> def write_ini(path, property, value): ... p = SafeConfigParser() ... p.add_section('app:main') ... p.set('app:main', property, value) ... with open(os.path.join(config_dir, 'config', path), 'w') as f: p.write(f) >>> write_ini('tool_shed.ini', 'database_connection', 'sqlite:///pg/testdb1') >>> config = get_config(['manage_db.py', 'tool_shed'], cwd=config_dir) >>> config['repo'] 'lib/galaxy/webapps/tool_shed/model/migrate' >>> config['db_url'] 'sqlite:///pg/testdb1' >>> write_ini('galaxy.ini', 'database_file', 'moo.sqlite') >>> config = get_config(['manage_db.py'], cwd=config_dir) >>> config['db_url'] 'sqlite:///moo.sqlite?isolation_level=IMMEDIATE' >>> config['repo'] 'lib/galaxy/model/migrate' >>> rmtree(config_dir) """ config_file, config_section, database = _read_model_arguments( argv, use_argparse=use_argparse) database_defaults = DATABASE[database] if config_file is None: config_names = database_defaults.get('config_names', DEFAULT_CONFIG_NAMES) if cwd: cwd = [cwd, os.path.join(cwd, 'config')] config_file = find_config_file(config_names, dirs=cwd) repo = database_defaults['repo'] config_prefix = database_defaults.get('config_prefix', DEFAULT_CONFIG_PREFIX) config_override = database_defaults.get('config_override', 'GALAXY_CONFIG_') default_sqlite_file = database_defaults['default_sqlite_file'] if config_section is None: if not config_file or get_ext(config_file, ignore='sample') == 'yaml': config_section = database_defaults.get('config_section', None) else: # Just use the default found by load_app_properties. config_section = None properties = load_app_properties(config_file=config_file, config_prefix=config_override, config_section=config_section) if ("%sdatabase_connection" % config_prefix) in properties: db_url = properties["%sdatabase_connection" % config_prefix] elif ("%sdatabase_file" % config_prefix) in properties: database_file = properties["%sdatabase_file" % config_prefix] db_url = "sqlite:///%s?isolation_level=IMMEDIATE" % database_file else: db_url = "sqlite:///%s?isolation_level=IMMEDIATE" % default_sqlite_file return dict(db_url=db_url, repo=repo, config_file=config_file, database=database)
def _app_properties(args): # FIXME: you can use galaxy.util.path.extensions for this config_file = args.config_file or find_config_file(args.app) app_properties = load_app_properties(config_file=config_file, config_section=args.config_section) return app_properties
def config_file_from_args(args, legacy_config_override=None, app=None): app = app or getattr(args, "app", "galaxy") config_file = legacy_config_override or args.config_file or find_config_file(app) return config_file