-
Notifications
You must be signed in to change notification settings - Fork 0
/
build_standalone_dist.py
95 lines (79 loc) · 5.31 KB
/
build_standalone_dist.py
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
import os
import subprocess
import datetime
import struct
from shutil import copyfile
from shutil import rmtree
from shutil import copytree
from loguru import logger
timer_start = datetime.datetime.now()
# Variablen für den Build-Prozess (64 bit Python-Umgebung):
include_providerspecific_modules = False
qt_lib_path = "C:\\Users\\OGoetze\\venv\\build\\ddbmappings_build\\Lib\\site-packages\\PyQt5\\Qt\\bin"
msvc_path = "C:\\Program Files (x86)\\Windows Kits\\10\\Redist\\10.0.19041.0\\ucrt\\DLLs\\x64"
icon_path = "gui_components/ui_templates/resources/datapreparationtool.ico"
data_files = []
# Angepasste Variablen für 32 bit Python-Umgebung:
python_arch = struct.calcsize("P") * 8
if python_arch == 32: # 32 bit Python
qt_lib_path = "C:\\Users\\OGoetze\\venv\\build\\ddbmappings_build_32bit\\Lib\\site-packages\\PyQt5\\Qt\\bin"
msvc_path = "C:\\Program Files (x86)\\Windows Kits\\10\\Redist\\10.0.19041.0\\ucrt\\DLLs\\x86"
logger.info("Baue stand-alone Distribution für Windows ({architecture} bit).", architecture=str(python_arch))
# Aufräumen:
logger.info("Entferne Verzeichnisse 'dist' und 'build', falls aus vorherigem Build-Prozess vorhanden.")
if os.path.isdir("dist"):
rmtree("dist")
if os.path.isdir("build"):
rmtree("build")
# Ausführen des PyInstaller-Skripts als Subprozess:
execute_string = 'pyinstaller --clean --onefile -p "{}" -p "{}" --name "datapreparationtool" --icon "{}" main_gui.py'.format(qt_lib_path, msvc_path, icon_path)
logger.info("Führe PyInstaller-Script aus: {execute_string}", execute_string=execute_string)
subprocess.call(execute_string)
# Kopieren benötigter Data-Files:
logger.info("Kopiere benötigte Data-Files ...")
logger.info("Erstellen von Unterzeichnissen ...")
os.makedirs("dist/gui_session/templates")
os.makedirs("dist/utils/xml_enriched_with_uuids")
os.makedirs("dist/modules/ead2mets")
os.makedirs("dist/modules/common/provider_metadata")
os.makedirs("dist/modules/analysis/enrichment")
os.makedirs("dist/modules/serializers/eadddb")
os.makedirs("dist/modules/provider_specific")
logger.info("Kopieren der gui_session Daten ...")
copyfile("gui_session/templates/processing_status.xml", "dist/gui_session/templates/processing_status.xml")
copyfile("gui_session/templates/session.xml", "dist/gui_session/templates/session.xml")
copyfile("gui_session/templates/thread_actions.xml", "dist/gui_session/templates/thread_actions.xml")
copyfile("gui_session/version.xml", "dist/gui_session/version.xml")
logger.info("Kopieren der UI-Ressourcen ...")
copytree("gui_components/ui_templates/resources/html", "dist/gui_components/ui_templates/resources/html")
copyfile("gui_components/ui_templates/resources/list.png", "dist/gui_components/ui_templates/resources/list.png")
copytree("gui_components/ui_templates/resources/i18n", "dist/gui_components/ui_templates/resources/i18n")
logger.info("Kopieren der providerspezifischen Anpassungen, inkl. modules/provider_specific/aggregator_mapping.xml ...")
if include_providerspecific_modules:
copytree("modules/provider_specific", "dist/modules/provider_specific")
os.remove("dist/modules/provider_specific/handle_provider_aggregator_mapping.py")
os.remove("dist/modules/provider_specific/handle_provider_rights.py")
os.remove("dist/modules/provider_specific/handle_provider_scripts.py")
if os.path.isdir("dist/modules/provider_specific/__pycache__"):
rmtree("dist/modules/provider_specific/__pycache__")
else:
copyfile("modules/provider_specific/aggregator_mapping.xml", "dist/modules/provider_specific/aggregator_mapping.xml")
copyfile("modules/provider_specific/provider_script_sets_mapping.xml", "dist/modules/provider_specific/provider_script_sets_mapping.xml")
copyfile("modules/provider_specific/provider_script_template.py", "dist/modules/provider_specific/provider_script_template.py")
copytree("modules/provider_specific/common", "dist/modules/provider_specific/common")
logger.info("Kopieren des Templates zur METS/MODS-Generierung ...")
copyfile("modules/ead2mets/mets_template.xml", "dist/modules/ead2mets/mets_template.xml")
logger.info("Kopieren der externen Ressourcen der Common-Skripte ...")
copyfile("modules/common/provider_metadata/provider_template.xml", "dist/modules/common/provider_metadata/provider_template.xml")
logger.info("Kopieren der externen Ressourcen der Analyse-Skripte ...")
copyfile("modules/analysis/enrichment/fake_tektonik_template.xml", "dist/modules/analysis/enrichment/fake_tektonik_template.xml")
copytree("modules/analysis/previews/helpers/templates", "dist/modules/analysis/previews/helpers/templates")
copytree("modules/analysis/statistics/helpers/templates", "dist/modules/analysis/statistics/helpers/templates")
copytree("modules/analysis/validation/helpers/templates", "dist/modules/analysis/validation/helpers/templates")
logger.info("Kopieren der externen Ressourcen der Connector- und Serialisierungs-Skripte ...")
copyfile("modules/serializers/eadddb/ead_template_findbuch.xml", "dist/modules/serializers/eadddb/ead_template_findbuch.xml")
copyfile("modules/serializers/eadddb/ead_template_tektonik.xml", "dist/modules/serializers/eadddb/ead_template_tektonik.xml")
logger.info("Build-Prozess abgeschlossen. Ausgabe im Ordner 'dist'.")
timer_end = datetime.datetime.now()
processing_duration = timer_end - timer_start
logger.info("Prozessierungsdauer: {processing_duration}", processing_duration=processing_duration)