'Parses the app.yaml file.
Args:
basepath: The directory of the application.
basename: The relative file path, from basepath, to search for.
Returns:
An AppInfoExternal object.'

def _ParseAppInfoFromYaml(self, basepath, basename='app'):

    try:
        appyaml = self._ParseYamlFile(basepath, basename, appinfo_includes.Parse)
    except yaml_errors.EventListenerError as e:
        self.parser.error(('Error    parsing    %s.yaml:    %s.' % (os.path.join(basepath, basename), e)))
    if (not appyaml):
        if JavaSupported():
            if appcfg_java.IsWarFileWithoutYaml(basepath):
                java_app_update = appcfg_java.JavaAppUpdate(basepath, self.options)
                appyaml_string = java_app_update.GenerateAppYamlString([])
                appyaml = appinfo.LoadSingleAppInfo(appyaml_string)
            if (not appyaml):
                self.parser.error(('Directory    contains    neither    an    %s.yaml    configuration    file    nor    a    WEB-INF    subdirectory    with    web.xml    and    appengine-web.xml.' % basename))
        else:
            self.parser.error(('Directory    %r    does    not    contain    configuration    file    %s.yaml' % (os.path.abspath(basepath), basename)))
    orig_application = appyaml.application
    orig_module = appyaml.module
    orig_version = appyaml.version
    if self.options.app_id:
        appyaml.application = self.options.app_id
    if self.options.module:
        appyaml.module = self.options.module
    if self.options.version:
        appyaml.version = self.options.version
    if self.options.runtime:
        appyaml.SetEffectiveRuntime(self.options.runtime)
    if self.options.env_variables:
        if (appyaml.env_variables is None):
            appyaml.env_variables = appinfo.EnvironmentVariables()
        appyaml.env_variables.update(self.options.env_variables)
    if self.options.source_ref:
        try:
            combined_refs = '\n'.join(self.options.source_ref)
            appinfo.ValidateCombinedSourceReferencesString(combined_refs)
            if (appyaml.beta_settings is None):
                appyaml.beta_settings = appinfo.BetaSettings()
            appyaml.beta_settings['source_reference'] = combined_refs
        except validation.ValidationError as e:
            self.parser.error(e.message)
    if (not appyaml.application):
        self.parser.error(('Expected    -A    app_id    when    application    property    in    file    %s.yaml    is    not    set.' % basename))
    msg = ('Application:    %s' % appyaml.application)
    if (appyaml.application != orig_application):
        msg += ('    (was:    %s)' % orig_application)
    if (self.action.function is 'Update'):
        if ((appyaml.module is not None) and (appyaml.module != appinfo.DEFAULT_MODULE)):
            msg += (';    module:    %s' % appyaml.module)
            if (appyaml.module != orig_module):
                msg += ('    (was:    %s)' % orig_module)
        msg += (';    version:    %s' % appyaml.version)
        if (appyaml.version != orig_version):
            msg += ('    (was:    %s)' % orig_version)
    StatusUpdate(msg, self.error_fh)
    return appyaml
