def _replace_stage_in_root(self, obj_filepath, config_filepath, stage_id):
    config_ext = os.path.splitext(config_filepath)[1]
    base_filepath = os.path.splitext(obj_filepath)[0]
    gma_filepath = (base_filepath + '.gma')
    tpl_filepath = (base_filepath + '.tpl')
    lz_raw_filepath = (base_filepath + '.lz.raw')
    lz_filepath = os.path.splitext(lz_raw_filepath)[0]
    needs_lz_raw_creation = (config_ext == '.xml')
    needs_lz_compression = ((config_ext == '.xml') or (config_ext == '.raw'))
    if ((not needs_lz_compression) and (not needs_lz_raw_creation) and (not os.path.exists(lz_filepath))):
        self._give_error_message('.lz file promised not found')
        return Status.WARN
    tool_id = 'GxModelViewer.exe'
    if (tool_id not in self._tool_filepaths):
        self._give_error_message((('Cannot find tool: ' + tool_id) + '\n\nPlease make sure the tool with this exact name is somewhere in the mbreplacer directory'))
        return Status.WARN
    gx_process = subprocess.Popen([self._tool_filepaths['GxModelViewer.exe'], obj_filepath])
    if needs_lz_raw_creation:
        tool_id = 'ws2lzfrontend.exe'
        if (tool_id not in self._tool_filepaths):
            self._give_error_message((('Cannot find tool: ' + tool_id) + '\n\nPlease make sure the tool with this exact name is somewhere in the mbreplacer directory'))
            return Status.WARN
        subprocess.call([self._tool_filepaths[tool_id], '-c', config_filepath, '-o', lz_raw_filepath, '-g', '2'])
    if (needs_lz_compression and (not os.path.exists(lz_raw_filepath))):
        self._give_error_message('Failure to create .lz.raw file, ensure the config/obj/mtl files are valid, as well as the ws2lzfrontend.exe tool')
        return Status.WARN
    if needs_lz_compression:
        tool_id = 'SMB_LZ_Tool.exe'
        if (tool_id not in self._tool_filepaths):
            self._give_error_message((('Cannot find tool: ' + tool_id) + '\n\nPlease make sure the tool with this exact name is somewhere in the mbreplacer directory'))
            return
        subprocess.call([self._tool_filepaths[tool_id], lz_raw_filepath])
    if (needs_lz_compression and (not os.path.exists((lz_raw_filepath + '.lz')))):
        self._give_error_message('Failure to create .lz.raw file, ensure the config/obj/mtl files are valid, as well as the ws2lzfrontend.exe tool')
        return Status.WARN
    if needs_lz_compression:
        if os.path.exists(lz_filepath):
            os.remove(lz_filepath)
        os.rename((lz_raw_filepath + '.lz'), lz_filepath)
        os.remove(lz_raw_filepath)
    gx_process.wait()
    if ((not os.path.exists(gma_filepath)) or (not os.path.exists(tpl_filepath))):
        self._give_error_message('Failure to create gma and tpl files, ensure these files are correct, as well as the GxModelViewer.exe (No GUI) tool')
        return Status.WARN
    stage_gma_filepath = os.path.join(self._root_folder_path, 'stage', (('st' + stage_id) + '.gma'))
    stage_tpl_filepath = os.path.join(self._root_folder_path, 'stage', (('st' + stage_id) + '.tpl'))
    stage_lz_filepath = os.path.join(self._root_folder_path, 'stage', (('STAGE' + stage_id) + '.lz'))
    shutil.copy(gma_filepath, stage_gma_filepath)
    shutil.copy(tpl_filepath, stage_tpl_filepath)
    shutil.copy(lz_filepath, stage_lz_filepath)
    return Status.OK
def _replace_stage_in_root(self, obj_filepath, config_filepath, stage_id):
    config_ext = os.path.splitext(config_filepath)[1]
    base_filepath = os.path.splitext(obj_filepath)[0]
    gma_filepath = (base_filepath + '.gma')
    tpl_filepath = (base_filepath + '.tpl')
    lz_raw_filepath = (base_filepath + '.lz.raw')
    lz_filepath = os.path.splitext(lz_raw_filepath)[0]
    needs_lz_raw_creation = (config_ext == '.xml')
    needs_lz_compression = ((config_ext == '.xml') or (config_ext == '.raw'))
    if ((not needs_lz_compression) and (not needs_lz_raw_creation) and (not os.path.exists(lz_filepath))):
        self._give_error_message('.lz file promised not found')
        return Status.WARN
    tool_id = 'GxModelViewer.exe'
    if (tool_id not in self._tool_filepaths):
        self._give_error_message((('Cannot find tool: ' + tool_id) + '\n\nPlease make sure the tool with this exact name is somewhere in the mbreplacer directory'))
        return Status.WARN
    gx_process = subprocess.Popen([self._tool_filepaths['GxModelViewer.exe'], obj_filepath])
    if needs_lz_raw_creation:
        tool_id = 'ws2lzfrontend.exe'
        if (tool_id not in self._tool_filepaths):
            self._give_error_message((('Cannot find tool: ' + tool_id) + '\n\nPlease make sure the tool with this exact name is somewhere in the mbreplacer directory'))
            return Status.WARN
        subprocess.call([self._tool_filepaths[tool_id], '-c', config_filepath, '-o', lz_raw_filepath, '-g', '2'])
    if (needs_lz_compression and (not os.path.exists(lz_raw_filepath))):
        self._give_error_message('Failure to create .lz.raw file, ensure the config/obj/mtl files are valid, as well as the ws2lzfrontend.exe tool')
        return Status.WARN
    if needs_lz_compression:
        tool_id = 'SMB_LZ_Tool.exe'
        if (tool_id not in self._tool_filepaths):
            self._give_error_message((('Cannot find tool: ' + tool_id) + '\n\nPlease make sure the tool with this exact name is somewhere in the mbreplacer directory'))
            return
        subprocess.call([self._tool_filepaths[tool_id], lz_raw_filepath])
    if (needs_lz_compression and (not os.path.exists((lz_raw_filepath + '.lz')))):
        self._give_error_message('Failure to create .lz.raw file, ensure the config/obj/mtl files are valid, as well as the ws2lzfrontend.exe tool')
        return Status.WARN
    if needs_lz_compression:
        if os.path.exists(lz_filepath):
            os.remove(lz_filepath)
        os.rename((lz_raw_filepath + '.lz'), lz_filepath)
        os.remove(lz_raw_filepath)
    gx_process.wait()
    if ((not os.path.exists(gma_filepath)) or (not os.path.exists(tpl_filepath))):
        self._give_error_message('Failure to create gma and tpl files, ensure these files are correct, as well as the GxModelViewer.exe (No GUI) tool')
        return Status.WARN
    stage_gma_filepath = os.path.join(self._root_folder_path, 'stage', (('st' + stage_id) + '.gma'))
    stage_tpl_filepath = os.path.join(self._root_folder_path, 'stage', (('st' + stage_id) + '.tpl'))
    stage_lz_filepath = os.path.join(self._root_folder_path, 'stage', (('STAGE' + stage_id) + '.lz'))
    shutil.copy(gma_filepath, stage_gma_filepath)
    shutil.copy(tpl_filepath, stage_tpl_filepath)
    shutil.copy(lz_filepath, stage_lz_filepath)
    return Status.OK