Skip to content

Commit c35f0bc

Browse files
committed
First edition released
0 parents  commit c35f0bc

23 files changed

Lines changed: 3422 additions & 0 deletions

.gitignore

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
.idea
2+
.venv
3+
.env
4+
.vscode
5+
*.code-workspace
6+
.DS_Store
7+
__pycache__
8+
dist
9+
build
10+
python_sql_backup.egg-info
11+
config.ini
12+
config
13+
resources/icon.ico
14+
resources/icon.icns

BUILD.md

Lines changed: 151 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
# MySQL备份工具构建指南
2+
3+
本文档提供了如何使用`build_executable.py`脚本构建MySQL备份工具可执行文件的详细说明。该构建系统支持为Windows、macOS和Linux平台生成独立可执行文件,同时支持多种CPU架构。
4+
5+
## 前提条件
6+
7+
在开始构建过程之前,确保您已安装以下软件:
8+
9+
1. **Python 3.10或更高版本**
10+
2. **PyInstaller**:用于创建独立可执行文件
11+
```bash
12+
pip install pyinstaller
13+
```
14+
3. **项目依赖项**:所有在`requirements.txt`中列出的依赖项
15+
```bash
16+
pip install -r requirements.txt
17+
```
18+
19+
## 构建选项
20+
21+
`build_executable.py`脚本提供了多种构建选项,允许您为特定平台和架构构建可执行文件。
22+
23+
### 基本用法
24+
25+
```bash
26+
python build_executable.py [选项]
27+
```
28+
29+
### 可用选项
30+
31+
| 选项 | 描述 |
32+
|------|------|
33+
| `--target-platform PLATFORM` | 目标平台 (windows, macos, linux) |
34+
| `--target-arch ARCH` | 目标架构 (x86, x86_64, arm64) |
35+
| `--all` | 为所有支持的平台和架构构建 |
36+
| `--output-dir DIR` | 可执行文件输出目录(默认:dist) |
37+
| `--verbose` | 启用详细输出 |
38+
| `--clean` | 构建前清理构建目录 |
39+
| `--help` | 显示帮助信息 |
40+
41+
## 构建示例
42+
43+
### 为当前平台和架构构建
44+
45+
```bash
46+
python build_executable.py
47+
```
48+
49+
### 为特定平台构建
50+
51+
```bash
52+
python build_executable.py --target-platform windows
53+
```
54+
55+
### 为特定平台和架构构建
56+
57+
```bash
58+
python build_executable.py --target-platform linux --target-arch x86_64
59+
```
60+
61+
### 为所有支持的平台和架构构建
62+
63+
```bash
64+
python build_executable.py --all
65+
```
66+
67+
### 构建并指定输出目录
68+
69+
```bash
70+
python build_executable.py --output-dir /path/to/output
71+
```
72+
73+
## 跨平台构建注意事项
74+
75+
### Windows构建
76+
77+
- 在Windows平台上构建Windows可执行文件效果最佳
78+
- 如果需要在非Windows系统上构建Windows可执行文件,您可能需要安装Wine
79+
- Windows可执行文件将具有`.exe`扩展名
80+
81+
### macOS构建
82+
83+
- 在macOS平台上构建macOS可执行文件效果最佳
84+
- 为Intel (x86_64)和Apple Silicon (arm64)构建Universal Binary需要在macOS上进行
85+
- macOS构建可以生成标准可执行文件或`.app`
86+
87+
### Linux构建
88+
89+
- Linux构建通常可以在任何Linux发行版上运行,但最好在与目标系统类似的发行版上构建
90+
- 为确保最大兼容性,可以在较旧的Linux发行版上构建
91+
92+
## 构建输出
93+
94+
构建脚本会在指定的输出目录(默认为`dist`)中创建以下结构:
95+
96+
```
97+
dist/
98+
├── windows-x86_64/
99+
│ └── python-sql-backup.exe
100+
├── macos-x86_64/
101+
│ └── python-sql-backup
102+
├── macos-arm64/
103+
│ └── python-sql-backup
104+
├── linux-x86_64/
105+
│ └── python-sql-backup
106+
└── config/
107+
├── config.ini.example
108+
└── README.md
109+
```
110+
111+
## 构建配置包
112+
113+
构建脚本也会创建一个配置包,其中包含示例配置文件和文档。这个配置包可以与可执行文件一起分发,让用户能够快速开始使用。
114+
115+
## 故障排除
116+
117+
### 常见问题
118+
119+
1. **缺少依赖项**
120+
121+
确保您已安装所有必要的依赖项:
122+
```bash
123+
pip install -r requirements.txt
124+
pip install pyinstaller
125+
```
126+
127+
2. **图标文件问题**
128+
129+
如果遇到图标相关错误,可以尝试删除或替换`resources`目录中的图标文件。
130+
131+
3. **跨平台构建失败**
132+
133+
跨平台构建可能受到限制,最好在目标平台上进行本地构建。
134+
135+
4. **可执行文件大小过大**
136+
137+
PyInstaller生成的可执行文件通常较大,因为它们包含了完整的Python解释器和所有依赖项。使用`--clean`选项可以删除临时文件,但不会显著减小最终可执行文件的大小。
138+
139+
5. **构建速度慢**
140+
141+
构建过程可能需要几分钟时间,特别是在构建多个平台和架构时。请耐心等待。
142+
143+
## 高级配置
144+
145+
### 修改PyInstaller规范文件
146+
147+
如果您需要对构建过程进行更精细的控制,可以直接编辑`python_sql_backup.spec`文件。这个文件包含了PyInstaller构建配置,可以用来添加额外的资源、更改图标、设置启动选项等。
148+
149+
### 自定义构建脚本
150+
151+
您也可以修改`build_executable.py`脚本来满足特定需求,如添加新的目标平台、更改构建参数或添加post-build处理步骤。

0 commit comments

Comments
 (0)