def _config_files_from_dir(self, dir_path): """Return a list of the configuration files found in the given directory. If the directory contains a subdirectory WEB-INF then we expect to find web.xml and application-web.xml in that subdirectory. The returned list will consist of the path to application-web.xml, which we treat as if it included web.xml. Otherwise, we expect to find an app.yaml and optionally a backends.yaml, and we return those in the list. Args: dir_path: a string that is the path to a directory. Returns: A list of strings that are file paths. """ web_inf = os.path.join(dir_path, 'WEB-INF') if java_supported() and os.path.isdir(web_inf): return self._config_files_from_web_inf_dir(web_inf) app_yamls = self._files_in_dir_matching(dir_path, ['app.yaml', 'app.yml']) if not app_yamls: or_web_inf = ' or a WEB-INF subdirectory' if java_supported( ) else '' raise errors.AppConfigNotFoundError( '"%s" is a directory but does not contain app.yaml or app.yml%s' % (dir_path, or_web_inf)) backend_yamls = self._files_in_dir_matching( dir_path, ['backends.yaml', 'backends.yml']) return app_yamls + backend_yamls
def _config_files_from_web_inf_dir(self, web_inf): required = ['appengine-web.xml', 'web.xml'] missing = [f for f in required if not os.path.exists(os.path.join(web_inf, f))] if missing: raise errors.AppConfigNotFoundError( 'The "%s" subdirectory exists but is missing %s' % (web_inf, ' and '.join(missing))) return [os.path.join(web_inf, required[0])]
def _config_files_from_web_inf_dir(self, web_inf): """Return a list of the configuration files found in a WEB-INF directory. We expect to find web.xml and application-web.xml in the directory. Args: web_inf: a string that is the path to a WEB-INF directory. Raises: AppConfigNotFoundError: If the xml files are not found. Returns: A list of strings that are file paths. """ required = ['appengine-web.xml', 'web.xml'] missing = [f for f in required if not os.path.exists(os.path.join(web_inf, f))] if missing: raise errors.AppConfigNotFoundError( 'The "%s" subdirectory exists but is missing %s' % (web_inf, ' and '.join(missing))) return [os.path.join(web_inf, required[0])]
def __init__(self, yaml_paths): """Initializer for ApplicationConfiguration. Args: yaml_paths: A list of strings containing the paths to yaml files. """ self.modules = [] self.dispatch = None if len(yaml_paths) == 1 and os.path.isdir(yaml_paths[0]): directory_path = yaml_paths[0] for app_yaml_path in [os.path.join(directory_path, 'app.yaml'), os.path.join(directory_path, 'app.yml')]: if os.path.exists(app_yaml_path): yaml_paths = [app_yaml_path] break else: raise errors.AppConfigNotFoundError( 'no app.yaml file at %r' % directory_path) for backends_yaml_path in [os.path.join(directory_path, 'backends.yaml'), os.path.join(directory_path, 'backends.yml')]: if os.path.exists(backends_yaml_path): yaml_paths.append(backends_yaml_path) break for yaml_path in yaml_paths: if os.path.isdir(yaml_path): raise errors.InvalidAppConfigError( '"%s" is a directory and a yaml configuration file is required' % yaml_path) elif (yaml_path.endswith('backends.yaml') or yaml_path.endswith('backends.yml')): # TODO: Reuse the ModuleConfiguration created for the app.yaml # instead of creating another one for the same file. self.modules.extend( BackendsConfiguration(yaml_path.replace('backends.y', 'app.y'), yaml_path).get_backend_configurations()) elif (yaml_path.endswith('dispatch.yaml') or yaml_path.endswith('dispatch.yml')): if self.dispatch: raise errors.InvalidAppConfigError( 'Multiple dispatch.yaml files specified') self.dispatch = DispatchConfiguration(yaml_path) else: module_configuration = ModuleConfiguration(yaml_path) self.modules.append(module_configuration) application_ids = set(module.application for module in self.modules) if len(application_ids) > 1: raise errors.InvalidAppConfigError( 'More than one application ID found: %s' % ', '.join(sorted(application_ids))) self._app_id = application_ids.pop() module_names = set() for module in self.modules: if module.module_name in module_names: raise errors.InvalidAppConfigError('Duplicate module: %s' % module.module_name) module_names.add(module.module_name) if self.dispatch: if appinfo.DEFAULT_MODULE not in module_names: raise errors.InvalidAppConfigError( 'A default module must be specified.') missing_modules = ( set(module_name for _, module_name in self.dispatch.dispatch) - module_names) if missing_modules: raise errors.InvalidAppConfigError( 'Modules %s specified in dispatch.yaml are not defined by a yaml ' 'file.' % sorted(missing_modules))