-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbuild_config.py
More file actions
169 lines (137 loc) · 4.2 KB
/
Copy pathbuild_config.py
File metadata and controls
169 lines (137 loc) · 4.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
import os
import sys
import shutil
import subprocess
from pathlib import Path
def get_tesseract_path():
"""Sistemdeki Tesseract yolunu belirle"""
if sys.platform == "win32":
return r"C:\Program Files\Tesseract-OCR"
return "/usr/local/bin" # Mac için
def get_poppler_path():
"""Sistemdeki Poppler yolunu belirle"""
if sys.platform == "win32":
return r"C:\Program Files\poppler-23.11.0\Library\bin"
return "/usr/local/bin" # Mac için
def create_build_folders():
"""Build klasörlerini oluştur"""
Path("build").mkdir(exist_ok=True)
Path("dist").mkdir(exist_ok=True)
def copy_dependencies():
"""Bağımlılıkları kopyala"""
# Tesseract ve dil dosyalarını kopyala
tesseract_path = get_tesseract_path()
if sys.platform == "win32":
shutil.copytree(tesseract_path, "build/tesseract", dirs_exist_ok=True)
# Poppler'ı kopyala
poppler_path = get_poppler_path()
if sys.platform == "win32":
shutil.copytree(poppler_path, "build/poppler", dirs_exist_ok=True)
def create_executable():
"""PyInstaller ile executable oluştur"""
spec_content = """# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
added_files = [
('templates', 'templates'),
('static', 'static'),
('build/tesseract', 'tesseract'),
('build/poppler', 'poppler'),
('app.ico', '.') # app.ico
]
a = Analysis(
['app.py'],
pathex=[],
binaries=[],
datas=added_files,
hiddenimports=[
'PyPDF2',
'pdf2image',
'pytesseract',
'werkzeug.middleware.proxy_fix',
'PIL', # Pillow için
'flask', # Flask için
],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
win_no_prefer_redirects=False,
win_private_assemblies=False,
cipher=block_cipher,
noarchive=False
)
pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher)
exe = EXE(
pyz,
a.scripts,
[],
exclude_binaries=True,
name='MuseumPDFTool',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True, # UPX sıkıştırmasını etkinleştir
console=True,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
icon='app.ico' # Ikon dosyası
)
coll = COLLECT(
exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True, # UPX sıkıştırmasını etkinleştir
upx_exclude=[],
name='MuseumPDFTool'
)
"""
with open("museumapp.spec", "w", encoding='utf-8') as f:
f.write(spec_content)
# PyInstaller'ı çalıştır
subprocess.run(["pyinstaller", "--noconfirm", "museumapp.spec"])
def create_launcher():
"""Bir başlatıcı scripti oluştur"""
launcher_content = """import os
import sys
def setup_environment():
# Uygulama dizinini belirle
base_path = getattr(sys, '_MEIPASS', os.path.abspath(os.path.dirname(__file__)))
# Tesseract yolunu ayarla
tesseract_path = os.path.join(base_path, 'tesseract')
os.environ['PATH'] = tesseract_path + os.pathsep + os.environ.get('PATH', '')
os.environ['TESSDATA_PREFIX'] = os.path.join(tesseract_path, 'tessdata')
# Poppler yolunu ayarla
poppler_path = os.path.join(base_path, 'poppler')
os.environ['PATH'] = poppler_path + os.pathsep + os.environ.get('PATH', '')
if __name__ == '__main__':
setup_environment()
from app import app
app.run(debug=False)
"""
with open("launcher.py", "w", encoding='utf-8') as f:
f.write(launcher_content)
def main():
"""Ana build işlemi"""
try:
print("Build işlemi başlıyor...")
create_build_folders()
print("Bağımlılıklar kopyalanıyor...")
copy_dependencies()
print("Executable oluşturuluyor...")
create_executable()
print("Launcher oluşturuluyor...")
create_launcher()
print("Build işlemi tamamlandı!")
# Dist klasörünü ZIP yap
shutil.make_archive("MuseumPDFTool", "zip", "dist/MuseumPDFTool")
print("Zip dosyası oluşturuldu: MuseumPDFTool.zip")
except Exception as e:
print(f"Hata: {str(e)}")
sys.exit(1)
if __name__ == "__main__":
main()