|
1 | 1 | import os
|
| 2 | +import sys |
| 3 | +import subprocess |
2 | 4 |
|
3 |
| -os.system( |
4 |
| - "pyinstaller app/Tuttle.py --noconsole --noconfirm --add-data 'tuttle_tests/data/TuttleDemo-TimeTracking.ics:.'" |
5 |
| -) |
| 5 | +from loguru import logger |
| 6 | + |
| 7 | +added_files = [ |
| 8 | + ("tuttle_tests/data", "demo_data"), |
| 9 | + ("templates", "templates"), |
| 10 | +] |
| 11 | + |
| 12 | +added_data_options = [f"--add-data={src}:{dst}" for src, dst in added_files] |
| 13 | + |
| 14 | + |
| 15 | +def build_macos(): |
| 16 | + pyinstaller_options = [ |
| 17 | + "--noconfirm", |
| 18 | + "--windowed", |
| 19 | + "--clean", |
| 20 | + "--onefile", |
| 21 | + # "--onedir", |
| 22 | + ] |
| 23 | + |
| 24 | + options = pyinstaller_options + added_data_options |
| 25 | + |
| 26 | + logger.info(f"calling pyinstaller with options: {' '.join(options)}") |
| 27 | + subprocess.call( |
| 28 | + ["pyinstaller", "app/Tuttle.py"] + options, |
| 29 | + shell=False, |
| 30 | + ) |
| 31 | + |
| 32 | + |
| 33 | +def build_linux(): |
| 34 | + pyinstaller_options = [ |
| 35 | + "--noconfirm", |
| 36 | + "--windowed", |
| 37 | + "--clean", |
| 38 | + "--onefile", |
| 39 | + # "--onedir", |
| 40 | + ] |
| 41 | + |
| 42 | + options = pyinstaller_options + added_data_options |
| 43 | + |
| 44 | + logger.info(f"calling pyinstaller with options: {' '.join(options)}") |
| 45 | + subprocess.call( |
| 46 | + ["pyinstaller", "app/Tuttle.py"] + options, |
| 47 | + shell=False, |
| 48 | + ) |
| 49 | + |
| 50 | + |
| 51 | +def build_windows(): |
| 52 | + pyinstaller_options = [ |
| 53 | + "--noconfirm", |
| 54 | + "--windowed", |
| 55 | + "--clean", |
| 56 | + "--onefile", |
| 57 | + # "--onedir", |
| 58 | + ] |
| 59 | + |
| 60 | + options = pyinstaller_options + added_data_options |
| 61 | + |
| 62 | + logger.info(f"calling pyinstaller with options: {' '.join(options)}") |
| 63 | + subprocess.call( |
| 64 | + ["pyinstaller", "app/Tuttle.py"] + options, |
| 65 | + shell=False, |
| 66 | + ) |
| 67 | + |
| 68 | + |
| 69 | +def main(): |
| 70 | + # which operating system? |
| 71 | + if sys.platform.startswith("linux"): |
| 72 | + logger.info("building for Linux") |
| 73 | + build_linux() |
| 74 | + elif sys.platform.startswith("darwin"): |
| 75 | + logger.info("building for macOS") |
| 76 | + build_macos() |
| 77 | + elif sys.platform.startswith("win"): |
| 78 | + logger.info("building for Windows") |
| 79 | + build_windows() |
| 80 | + else: |
| 81 | + raise RuntimeError("Unsupported operating system") |
| 82 | + |
| 83 | + |
| 84 | +if __name__ == "__main__": |
| 85 | + main() |
| 86 | + |
| 87 | +# os.system( |
| 88 | +# "pyinstaller app/Tuttle.py --onefile --noconsole --noconfirm --add-data 'tuttle_tests/data/TuttleDemo-TimeTracking.ics:.'" |
| 89 | +# ) |
0 commit comments