4 Star 7 Fork 1

SleepySoft / History

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
build.py 2.89 KB
一键复制 编辑 原始数据 按行查看 历史
SleepySoft 提交于 2019-11-01 09:21 . Add rlease link in readme.
import time
from sys import executable as py_executable
from PyInstaller.__main__ import run as _build_exe
import os as _os
import platform
_here = _os.path.abspath(_os.path.dirname(__file__))
_os.chdir(_here)
_py_executable_path = _os.path.abspath(_os.path.dirname(py_executable))
if platform.system() == 'Windows':
_build_exe_args = (
'--clean',
'--i', 'res/logo.ico',
# '--paths', "{}/Lib/site-packages/PyQt5/Qt/bin".format(_py_executable_path),
'--paths', "./",
'-n', 'application',
'-y',
"main.py"
)
else:
_build_exe_args = (
'--clean',
'--i', 'res/logo.ico',
'--paths', "./",
'-n', 'application',
'-y',
"main.py"
)
def build_exe():
_build_exe(pyi_args=_build_exe_args)
pass
def add_data_file():
src_path = 'depot'
dist_path = 'dist/application/depot'
from shutil import copytree, rmtree
if _os.path.exists(dist_path):
rmtree(dist_path)
copytree(src_path, dist_path)
pass
def __only_py(src, names):
ret = []
for sub_name in names:
if not sub_name.endswith('.py'):
ret.append(sub_name)
pass
return ret
pass
def __add_dir_in_zip(_zip_f, dir_name, arc_pre_path=''):
file_list = []
if arc_pre_path and not arc_pre_path.endswith('/'):
arc_pre_path = '{}/'.format(arc_pre_path)
if _os.path.isfile(dir_name):
file_list.append(dir_name)
else:
for root, dirs, files in _os.walk(dir_name):
for name in files:
file_list.append(_os.path.join(root, name))
for file in file_list:
arc_name = file[len(dir_name):]
print(arc_name)
_zip_f.write(file, arc_pre_path + arc_name)
pass
def packing_app(app_pkg_name):
print('Packing application...')
if _os.path.exists(app_pkg_name):
_os.remove(app_pkg_name)
print(app_pkg_name, 'is removed')
from zipfile import ZipFile
with ZipFile(app_pkg_name, 'w') as zip_f:
__add_dir_in_zip(zip_f, 'dist/application', 'History.Sleepy')
pass
def format_app_package_name():
from readme import VERSION as _app_version
name_format = 'History-{version}-{os_name}_{os_machine}_{date}.zip'
_os_name = platform.system() + platform.release()
_os_machine = platform.machine()
return name_format.format(os_name=_os_name,
os_machine=_os_machine,
version=_app_version,
date=time.strftime("%Y%m%d", time.localtime(time.time()))).lower()
pass
if __name__ == "__main__":
try:
build_exe()
add_data_file()
packing_app('dist/{}'.format(format_app_package_name()))
except Exception as exception:
print('ERROR:', 'Build failed!', exception)
import traceback
traceback.print_exc()
input()
pass
pass
1
https://gitee.com/SleepySoft/History.git
git@gitee.com:SleepySoft/History.git
SleepySoft
History
History
master

搜索帮助