# /*
#  * 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 .docx_parser import DOCXParser

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

    def convert_wps_to_docx(self, file_path):
        docx_file_path = file_path.replace(".wps", ".docx")
        subprocess.run(["unoconv", "-f", "docx", "--output", docx_file_path, file_path], check=True)
        print(f"文件已成功从 {file_path} 转换为 {docx_file_path}")
        return docx_file_path


    def parser(self, file_path) -> str:
        """
        解析wps文件
        """
        docx_file_path = self.convert_wps_to_docx(file_path)

        docx = DOCXParser()
        content_list = docx.parser_docx(docx_file_path)

        os.remove(docx_file_path)
        return content_list


if __name__ == "__main__":
    parser = WPSParser()
    print(parser.parser("/home/kylin/wangyan/qqq.wps"))
