From 3786f58bb644990ff94157a3d8af9268eb8a201f Mon Sep 17 00:00:00 2001 From: lededev Date: Mon, 1 Nov 2021 05:07:53 +0800 Subject: [PATCH] opencc need in pyinstaller --add-data --- .github/workflows/main.yml | 2 ++ AV_Data_Capture.py | 11 ++++++++--- Makefile | 1 + py_to_exe.ps1 | 2 ++ wrapper/FreeBSD.sh | 1 + wrapper/Linux.sh | 1 + 6 files changed, 15 insertions(+), 3 deletions(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 289c88e..56e0068 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -42,6 +42,7 @@ jobs: --hidden-import ADC_function.py \ --hidden-import core.py \ --add-data "$(python -c 'import cloudscraper as _; print(_.__path__[0])' | tail -n 1):cloudscraper" \ + --add-data "$(python -c 'import opencc as _; print(_.__path__[0])' | tail -n 1):opencc" \ --add-data "Img:Img" \ --add-data "config.ini:." \ @@ -53,6 +54,7 @@ jobs: --hidden-import ADC_function.py ` --hidden-import core.py ` --add-data "$(python -c 'import cloudscraper as _; print(_.__path__[0])' | tail -n 1);cloudscraper" ` + --add-data "$(python -c 'import opencc as _; print(_.__path__[0])' | tail -n 1);opencc" ` --add-data "Img;Img" ` --add-data "config.ini;." ` diff --git a/AV_Data_Capture.py b/AV_Data_Capture.py index 3edf21b..afc56ea 100755 --- a/AV_Data_Capture.py +++ b/AV_Data_Capture.py @@ -7,7 +7,7 @@ import shutil import typing import urllib3 import signal -import opencc +from opencc import OpenCC import config from datetime import datetime, timedelta @@ -400,7 +400,7 @@ def create_data_and_move(file_path: str, zero_op, oCC): if zero_op: return if n_number: - core_main(file_path, n_number) + core_main(file_path, n_number, oCC) else: raise ValueError("number empty") print("[*]======================================================") @@ -491,7 +491,12 @@ def main(): # create OpenCC converter ccm = conf.cc_convert_mode() - oCC = None if ccm == 0 else opencc.OpenCC('t2s.json' if ccm == 1 else 's2t.json') + try: + oCC = None if ccm == 0 else OpenCC('t2s.json' if ccm == 1 else 's2t.json') + except: + # some OS no OpennCC cpython, try opencc-python-reimplemented. + # pip uninstall opencc && pip install opencc-python-reimplemented + oCC = None if ccm == 0 else OpenCC('t2s' if ccm == 1 else 's2t') if not single_file_path == '': #Single File print('[+]==================== Single File =====================') diff --git a/Makefile b/Makefile index 4c8960a..3af212f 100644 --- a/Makefile +++ b/Makefile @@ -17,6 +17,7 @@ make: @echo "[+]Pyinstaller make" pyinstaller --onefile AV_Data_Capture.py --hidden-import ADC_function.py --hidden-import core.py \ + --add-data "`python3 -c 'import opencc as _; print(_.__path__[0])' | tail -n 1`:opencc" \ --add-data "Img:Img" \ --add-data "config.ini:." \ diff --git a/py_to_exe.ps1 b/py_to_exe.ps1 index 77f169a..f45e98d 100644 --- a/py_to_exe.ps1 +++ b/py_to_exe.ps1 @@ -2,6 +2,7 @@ # Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Force $CLOUDSCRAPER_PATH=$(python -c 'import cloudscraper as _; print(_.__path__[0])' | select -Last 1) +$OPENCC_PATH=$(python -c 'import opencc as _; print(_.__path__[0])' | select -Last 1) mkdir build mkdir __pycache__ @@ -10,6 +11,7 @@ pyinstaller --onefile AV_Data_Capture.py ` --hidden-import ADC_function.py ` --hidden-import core.py ` --add-data "$CLOUDSCRAPER_PATH;cloudscraper" ` + --add-data "$OPENCC_PATH;opencc" ` --add-data "Img;Img" ` --add-data "config.ini;." ` diff --git a/wrapper/FreeBSD.sh b/wrapper/FreeBSD.sh index 9717ef4..98f25f6 100755 --- a/wrapper/FreeBSD.sh +++ b/wrapper/FreeBSD.sh @@ -2,6 +2,7 @@ pkg install python38 py38-requests py38-pip py38-lxml py38-pillow py38-cloudscra pip install pyquery pyinstaller pyinstaller --onefile AV_Data_Capture.py --hidden-import ADC_function.py --hidden-import core.py \ --add-data "$(python3.8 -c 'import cloudscraper as _; print(_.__path__[0])' | tail -n 1):cloudscraper" \ + --add-data "$(python3.8 -c 'import opencc as _; print(_.__path__[0])' | tail -n 1):opencc" \ --add-data "Img:Img" \ --add-data "config.ini:." \ diff --git a/wrapper/Linux.sh b/wrapper/Linux.sh index 63e3b1c..043c8bf 100755 --- a/wrapper/Linux.sh +++ b/wrapper/Linux.sh @@ -14,6 +14,7 @@ pip3 install -r requirements.txt pip3 install cloudscraper==1.2.52 pyinstaller --onefile AV_Data_Capture.py --hidden-import ADC_function.py --hidden-import core.py \ --add-data "$(python3 -c 'import cloudscraper as _; print(_.__path__[0])' | tail -n 1):cloudscraper" \ + --add-data "$(python3 -c 'import opencc as _; print(_.__path__[0])' | tail -n 1):opencc" \ --add-data "Img:Img" \ --add-data "config.ini:." \