#!/usr/bin/env python3 # -*- coding:utf-8 -*- import os import platform import PyInstaller.__main__ import argparse import shutil from datetime import datetime from version import app_version from shutil import copyfile import subprocess system = platform.system() APPNAME = 'GPCT-standalone' VERSION = '1.0.0' build = os.path.join(os.getcwd(), 'build') dist = os.path.join(os.getcwd(), 'dist') spec = os.path.join(os.getcwd(), 'spec') pycache = os.path.join(os.getcwd(), '__pycache__') logPath = os.path.join(os.getcwd(), 'logFile') main = os.path.join(os.getcwd(), 'main.py') sep = ';' if system == 'Windows' else ':' cmdBase = [ main, '--clean', '--workpath', build, '--specpath', spec, '--distpath', dist, '--noconfirm', '--windowed', '--log-level', 'WARN', '--name', APPNAME, # '--add-binary', f'../influxd.exe{sep}.', '--add-data', f'../dataFile/config.json{sep}.', '--add-data', f'../Syunew3D_x64.dll{sep}.', '--add-data', f'../version.json{sep}.', '--add-data', f'../help.md{sep}.', '--add-data', f'../help_task.md{sep}.', '--add-data', f'../dataFile/data.db{sep}.', '--add-data', f'../default_cosl.py{sep}.', '--add-data', f'../default_general.py{sep}.', '--add-data', f'../default_http.py{sep}.', '--add-data', f'../default_scpi.py{sep}.', '--add-data', f'../default_task.py{sep}.', '--add-data', f'../logo{sep}logo', '--add-data', f'../qml{sep}qml', '--add-data', f'../scripts{sep}scripts', '--add-data', f'../sqls{sep}sqls', # '--add-data', f'../grafana{sep}grafana' ] BASE_DIR = os.path.dirname(os.path.abspath(__file__)) three_d_part_path = os.path.join(BASE_DIR, '3dpart') cmdBase += [ f'--add-data={os.path.join(three_d_part_path, i)};{i}' for i in os.listdir(three_d_part_path) ] cmdList = { 'Darwin':cmdBase + [ '--icon','../logo/logo.icns', '--osx-bundle-identifier','com.ningxuezhi', ], 'Windows':cmdBase + [ '--icon','../logo/logo.ico', '--exclude-module', 'PyQt5', '--exclude-module', 'PySide2', '--exclude-module', 'PySide6', '--version-file','../version.info', ] } proList = { 'default':'project_000001', 'zsh':'project_000002' } class Main(): def __init__(self): super().__init__() def run(self): print('The system is : ', system) versionInfo = app_version.data parser = argparse.ArgumentParser() parser.add_argument( '-c', '--clean', action='store_true', help='clean' ) parser.add_argument( '-b', '--build', action='store_true', help='build' ) parser.add_argument( '-d', '--dog', help='dog' ) parser.add_argument( '-v', '--version', action='version', version= versionInfo["version"] ) args = parser.parse_args() print(args) if args.clean: for i in [build, dist, spec, pycache, logPath]: shutil.rmtree(i, ignore_errors=True) if args.build: # if args.dog: # dog_directory = args.dog # print('dog_directory:', dog_directory) copyfile("default_config.json", "./dataFile/config.json") copyfile("default_data.db", "./dataFile/data.db") # copyfile("./dog/"+dog_directory+"/Psyunew3.pyc", "./Psyunew3.pyc") # versionInfo['proId'] = dog_directory in proList and proList[dog_directory] or '' versionInfo['releaseTime'] = datetime.now().strftime('%Y-%m-%d %H:%M:%S') app_version.update(versionInfo) PyInstaller.__main__.run(cmdList[system]) # else: # print("Please provide the dog directory using -d option") if __name__ == '__main__': main = Main() main.run()