'Check the backends.yaml file is sane and which backends to update.'

def BackendsYamlCheck(self, basepath, appyaml, backend=None):

    if appyaml.backends:
        self.parser.error('Backends    are    not    allowed    in    app.yaml.')
    backends_yaml = self._ParseBackendsYaml(basepath)
    appyaml.backends = backends_yaml.backends
    if (not appyaml.backends):
        self.parser.error('No    backends    found    in    backends.yaml.')
    backends = []
    for backend_entry in appyaml.backends:
        entry = backendinfo.LoadBackendEntry(backend_entry.ToYAML())
        if (entry.name in backends):
            self.parser.error(('Duplicate    entry    for    backend:    %s.' % entry.name))
        else:
            backends.append(entry.name)
    backends_to_update = []
    if backend:
        if (backend in backends):
            backends_to_update = [backend]
        else:
            self.parser.error(("Backend    '%s'    not    found    in    backends.yaml." % backend))
    else:
        backends_to_update = backends
    return backends_to_update
