# /*
#  * Copyright 2024 KylinSoft Co., Ltd.
#  *
#  * This program is free software: you can redistribute it and/or modify it under
#  * the terms of the GNU General Public License as published by the Free Software
#  * Foundation, either version 3 of the License, or (at your option) any later
#  * version.
#  *
#  * This program is distributed in the hope that it will be useful, but WITHOUT
#  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
#  * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
#  * details.
#  *
#  * You should have received a copy of the GNU General Public License along with
#  * this program. If not, see <https://www.gnu.org/licenses/>.
#  */

import subprocess
import os
from .base_parser import BaseParser
from .pptx_parser import PPTXParser

"""
ppt文件解析器,由于包的依赖问题，暂时不用
"""
class PPTParser(BaseParser):

    def convert_ppt_to_pptx(self, file_path):
        pptx_file_path = file_path.replace(".ppt", ".pptx")

        subprocess.run(["unoconv", "-f", "pptx", "--output", pptx_file_path, file_path], check=True)
        print(f"文件已成功从 {file_path} 转换为 {pptx_file_path}")

        return pptx_file_path

    def parser(self, file_path) -> str:
        pptx_file_path = self.convert_ppt_to_pptx(file_path)
        pptx_parser = PPTXParser()
        pptx_content = pptx_parser.parser(pptx_file_path)

        os.remove(pptx_file_path)
        return pptx_content


if __name__ == "__main__":
    ppt = PPTParser()
    text = ppt.parser("/home/kylin/wangyan/可信设计方法.ppt")
