'Creates a staging directory for uploading.
This is where we perform the necessary actions to create an application
directory for the update command to work properly - files are organized
into the static folder, and yaml files are generated where they can be
found later.
Args:
tools_dir: Path to the SDK tools directory
(typically .../google/appengine/tools)
Returns:
The path to a new temporary directory which contains generated yaml files
and a static file directory. For the most part, the rest of the update and
upload flow can resume identically to Python/PHP/Go applications.
Raises:
CompileError: if compilation of JSPs failed.
ConfigurationError: if the app to be staged has a configuration error.
IOError: if there was an I/O problem, for example when scanning jar files.'

def CreateStagingDirectory(self, tools_dir):

    stage_dir = tempfile.mkdtemp(prefix='appcfgpy')
    static_dir = os.path.join(stage_dir, '__static__')
    os.mkdir(static_dir)
    self._CopyOrLink(self.basepath, stage_dir, static_dir, False)
    self.app_engine_web_xml.app_root = stage_dir
    if self.options.compile_jsps:
        self._CompileJspsIfAny(tools_dir, stage_dir)
    web_inf = os.path.join(stage_dir, 'WEB-INF')
    web_inf_lib = os.path.join(web_inf, 'lib')
    api_jar_dict = _FindApiJars(web_inf_lib)
    api_versions = set(api_jar_dict.values())
    if (not api_versions):
        api_version = None
    elif (len(api_versions) == 1):
        api_version = api_versions.pop()
    else:
        raise ConfigurationError(('API    jars    have    inconsistent    versions:    %s' % api_jar_dict))
    for staged_api_jar in api_jar_dict:
        os.remove(staged_api_jar)
    appengine_generated = os.path.join(stage_dir, 'WEB-INF', 'appengine-generated')
    self._GenerateAppYaml(stage_dir, api_version, appengine_generated)
    app_id = (self.options.app_id or self.app_engine_web_xml.app_id)
    assert app_id, 'Missing    app    id'
    for parser in self._XML_PARSERS:
        xml_name = os.path.join(web_inf, parser.xml_name)
        if os.path.exists(xml_name):
            with open(xml_name) as xml_file:
                xml_string = xml_file.read()
            yaml_string = parser.xml_to_yaml_function(app_id, xml_string)
            yaml_file = os.path.join(appengine_generated, parser.yaml_name)
            with open(yaml_file, 'w') as yaml:
                yaml.write(yaml_string)
    indexes = []
    for xml_name in ('datastore-indexes.xml', os.path.join('appengine-generated', 'datastore-indexes-auto.xml')):
        xml_name = os.path.join(self.basepath, 'WEB-INF', xml_name)
        if os.path.exists(xml_name):
            with open(xml_name) as xml_file:
                xml_string = xml_file.read()
            index_definitions = datastore_index_xml.IndexesXmlToIndexDefinitions(xml_string)
            indexes.extend(index_definitions.indexes)
    if indexes:
        yaml_string = datastore_index.IndexDefinitions(indexes=indexes).ToYAML()
        yaml_file = os.path.join(appengine_generated, 'index.yaml')
        with open(yaml_file, 'w') as yaml:
            yaml.write(yaml_string)
    return stage_dir
