def get_app_kwds(cls, config_section, app_name=None): kwds = { 'config_file': None, 'config_section': config_section, } uwsgi_opt = uwsgi.opt config_file = None # check for --set galaxy_config_file=<path>, this overrides whatever config file uWSGI was loaded with (which # may not actually include a Galaxy config) if uwsgi_opt.get("galaxy_config_file"): config_file = uwsgi_opt.get("galaxy_config_file") # check for --yaml or --json uWSGI config options next if config_file is None: config_file = (UWSGIApplicationStack._get_config_file(uwsgi_opt.get("yaml"), yaml.safe_load, config_section) or UWSGIApplicationStack._get_config_file(uwsgi_opt.get("json"), json.load, config_section)) # --ini and --ini-paste don't behave the same way, but this method will only be called by mules if the main # application was loaded with --ini-paste, so we can make some assumptions, most notably, uWSGI does not have # any way to set the app name when loading with paste.deploy:loadapp(), so hardcoding the alternate section # name to `app:main` is fine. has_ini_config = config_file is None and uwsgi_opt.get("ini") or uwsgi_opt.get("ini-paste") has_ini_config = has_ini_config or (config_file and has_ext(config_file, "ini", aliases=True, ignore="sample")) if has_ini_config: config_file = config_file or uwsgi_opt.get("ini") or uwsgi_opt.get("ini-paste") parser = nice_config_parser(config_file) if not parser.has_section(config_section) and parser.has_section('app:main'): kwds['config_section'] = 'app:main' kwds['config_file'] = unicodify(config_file) return kwds
def get_app_kwds(cls, config_section, app_name=None): kwds = { 'config_file': None, 'config_section': config_section, } uwsgi_opt = uwsgi.opt config_file = None # check for --set galaxy_config_file=<path>, this overrides whatever config file uWSGI was loaded with (which # may not actually include a Galaxy config) if uwsgi_opt.get("galaxy_config_file"): config_file = uwsgi_opt.get("galaxy_config_file") # check for --yaml or --json uWSGI config options next if config_file is None: config_file = (UWSGIApplicationStack._get_config_file(uwsgi_opt.get("yaml"), yaml.safe_load, config_section) or UWSGIApplicationStack._get_config_file(uwsgi_opt.get("json"), json.load, config_section)) # --ini and --ini-paste don't behave the same way, but this method will only be called by mules if the main # application was loaded with --ini-paste, so we can make some assumptions, most notably, uWSGI does not have # any way to set the app name when loading with paste.deploy:loadapp(), so hardcoding the alternate section # name to `app:main` is fine. has_ini_config = config_file is None and uwsgi_opt.get("ini") or uwsgi_opt.get("ini-paste") has_ini_config = has_ini_config or (config_file and has_ext(config_file, "ini", aliases=True, ignore="sample")) if has_ini_config: config_file = config_file or uwsgi_opt.get("ini") or uwsgi_opt.get("ini-paste") parser = nice_config_parser(config_file) if not parser.has_section(config_section) and parser.has_section('app:main'): kwds['config_section'] = 'app:main' kwds['config_file'] = config_file return kwds
def _find_app_options(app_desc, path): """Load app (as opposed to server) options from specified path. Supplied ``path`` may be either YAML or ini file. """ if _is_ini(path): p = nice_config_parser(path) app_items = _find_app_options_from_config_parser(p) else: raw_config = _order_load_path(path) app_items = raw_config.get(app_desc.app_name, None) or {} return app_items
def __add_config_file_arg(args, config_file, app): ext = None if config_file: ext = get_ext(config_file) if ext in ('yaml', 'json'): __add_arg(args, ext, config_file) elif ext == 'ini': config = nice_config_parser(config_file) has_logging = config.has_section('loggers') if config.has_section('app:main'): # uWSGI does not have any way to set the app name when loading with paste.deploy:loadapp(), so hardcoding # the name to `main` is fine __add_arg(args, 'ini-paste' if not has_logging else 'ini-paste-logged', config_file) return # do not add --module else: __add_arg(args, ext, config_file) if has_logging: __add_arg(args, 'paste-logger', True)
def _run_conversion(args, app_desc): ini_config = _find_config(args, app_desc) if ini_config and not _is_ini(ini_config): _warn( "Cannot convert YAML file %s, this option is only for ini config files." % ini_config) sys.exit(1) elif not ini_config: _warn("Failed to find a config to convert - exiting without changes.") sys.exit(1) p = nice_config_parser(ini_config) server_section = None filters = {} for section in p.sections(): if section.startswith("server:"): if server_section: _warn(EXTRA_SERVER_MESSAGE % (server_section, section)) else: server_section = section if section.startswith("filter:"): filter_name = section[len("filter:"):] filter_type = p.get(section, "use") if filter_type is None: MISSING_FILTER_TYPE_MESSAGE message = EXTRA_SERVER_MESSAGE % section _warn(message) continue if filter_type == "egg:PasteDeploy#prefix": prefix = p.get(section, "prefix") filters[filter_name] = PrefixFilter(filter_name, prefix) elif filter_type == "egg:Paste#gzip": filters[filter_name] = GzipFilter(filter_name) else: message = UNHANDLED_FILTER_TYPE_MESSAGE % (filter_type, section) _warn(message) continue if not server_section: _warn( "No server section found, using default uwsgi server definition.") server_config = OrderedDict() else: server_config = OrderedDict(p.items(server_section)) app_items = _find_app_options_from_config_parser(p) applied_filters = [] if filters: for key, value in app_items.items(): if key == "filter-with": if value in filters: applied_filters.append(filters[value]) else: _warn("Unknown filter found [%s], exiting..." % value) sys.exit(1) uwsgi_dict = _server_paste_to_uwsgi(app_desc, server_config, applied_filters) app_dict = OrderedDict({}) schema = app_desc.schema for key, value in app_items.items(): if key in ["__file__", "here"]: continue if key in OPTION_ACTIONS: option_action = OPTION_ACTIONS.get(key) new_value = option_action.converted(args, app_desc, key, value) if new_value: if isinstance(new_value, tuple): key, value = new_value else: value = new_value if value is DROP_OPTION_VALUE: continue option = schema.get_app_option(key) if option["unknown_option"]: _warn(UNKNOWN_OPTION_MESSAGE % key) option_value = OptionValue(key, value, option) app_dict[key] = option_value f = StringIO() _write_section(args, f, "uwsgi", uwsgi_dict, uwsgi_hack=True) _write_section(args, f, app_desc.app_name, app_dict) destination = os.path.join(args.galaxy_root, app_desc.destination) _replace_file(args, f, app_desc, ini_config, destination)
def _run_conversion(args, app_desc): ini_config = _find_config(args, app_desc) if ini_config and not _is_ini(ini_config): _warn("Cannot convert YAML file %s, this option is only for ini config files." % ini_config) sys.exit(1) elif not ini_config: _warn("Failed to find a config to convert - exiting without changes.") sys.exit(1) p = nice_config_parser(ini_config) server_section = None filters = {} for section in p.sections(): if section.startswith("server:"): if server_section: _warn(EXTRA_SERVER_MESSAGE % (server_section, section)) else: server_section = section if section.startswith("filter:"): filter_name = section[len("filter:"):] filter_type = p.get(section, "use") if filter_type is None: MISSING_FILTER_TYPE_MESSAGE message = EXTRA_SERVER_MESSAGE % section _warn(message) continue if filter_type == "egg:PasteDeploy#prefix": prefix = p.get(section, "prefix") filters[filter_name] = PrefixFilter(filter_name, prefix) elif filter_type == "egg:Paste#gzip": filters[filter_name] = GzipFilter(filter_name) else: message = UNHANDLED_FILTER_TYPE_MESSAGE % (filter_type, section) _warn(message) continue if not server_section: _warn("No server section found, using default uwsgi server definition.") server_config = OrderedDict() else: server_config = OrderedDict(p.items(server_section)) app_items = _find_app_options_from_config_parser(p) applied_filters = [] if filters: for key, value in app_items.items(): if key == "filter-with": if value in filters: applied_filters.append(filters[value]) else: _warn("Unknown filter found [%s], exiting..." % value) sys.exit(1) uwsgi_dict = _server_paste_to_uwsgi(app_desc, server_config, applied_filters) app_dict = OrderedDict({}) schema = app_desc.schema for key, value in app_items.items(): if key in ["__file__", "here"]: continue if key in OPTION_ACTIONS: option_action = OPTION_ACTIONS.get(key) new_value = option_action.converted(args, app_desc, key, value) if new_value: if isinstance(new_value, tuple): key, value = new_value else: value = new_value if value is DROP_OPTION_VALUE: continue option = schema.get_app_option(key) if option["unknown_option"]: _warn(UNKNOWN_OPTION_MESSAGE % key) option_value = OptionValue(key, value, option) app_dict[key] = option_value f = StringIO() _write_section(args, f, "uwsgi", uwsgi_dict, uwsgi_hack=True) _write_section(args, f, app_desc.app_name, app_dict) destination = os.path.join(args.galaxy_root, app_desc.destination) _replace_file(args, f, app_desc, ini_config, destination)