pack.py 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. import os, sys, shutil
  2. if os.path.exists("kflash_py/__pycache__"):
  3. shutil.rmtree("kflash_py/__pycache__")
  4. if os.path.exists("build"):
  5. shutil.rmtree("build")
  6. if os.path.exists("dist"):
  7. shutil.rmtree("dist")
  8. # pyinstaller generate files
  9. if sys.platform.startswith("win32"):
  10. cmd = 'pyinstaller --add-binary="kflash_gui_data;kflash_gui_data" --add-binary="kflash_py;kflash_py" -i="kflash_gui_data/assets/logo.ico" -w kflash_gui.py'
  11. elif sys.platform.startswith("darwin"):
  12. # NOTE: must use --add-data under darwin, or you will get "Unknown Mach-O header" error
  13. cmd = 'pyinstaller --add-data="kflash_gui_data:kflash_gui_data" --add-data="kflash_py:kflash_py" -i="kflash_gui_data/assets/logo.icns" -w kflash_gui.py'
  14. else:
  15. cmd = 'pyinstaller --add-binary="kflash_gui_data:kflash_gui_data" --add-binary="kflash_py:kflash_py" -i="kflash_gui_data/assets/logo.png" -w kflash_gui.py'
  16. result = os.system(cmd)
  17. if result != 0:
  18. exit(1)
  19. # create packages
  20. if sys.platform.startswith("win32"):
  21. if os.path.exists("./dist/kflash_gui.7z"):
  22. os.remove("./dist/kflash_gui.7z")
  23. cmd = """bash.exe -c \
  24. " \
  25. cd ./dist || exit -1 ; \
  26. 7z a "kflash_gui.7z" "kflash_gui" -bd -mx9 || exit -1 ; \
  27. " \
  28. """
  29. elif sys.platform.startswith("darwin"):
  30. if os.path.exists("./dist/kflash_gui.dmg"):
  31. os.remove("./dist/kflash_gui.dmg")
  32. cmd = """create-dmg \
  33. --volname "KFlash GUI Installer" \
  34. --volicon "kflash_gui_data/assets/logo.icns" \
  35. --background "kflash_gui_data/assets/installer_background_mac.png" \
  36. --window-pos 200 120 \
  37. --window-size 800 400 \
  38. --icon-size 100 \
  39. --icon "kflash_gui.app" 200 190 \
  40. --hide-extension "kflash_gui.app" \
  41. --app-drop-link 600 185 \
  42. "./dist/kflash_gui.dmg" \
  43. "./dist/kflash_gui.app"
  44. """
  45. else:
  46. if os.path.exists("./dist/kflash_gui.tar.xz"):
  47. os.remove("./dist/kflash_gui.tar.xz")
  48. cmd = """sh -c \
  49. " \
  50. cd ./dist || exit -1 ; \
  51. XZ_OPT=-9 tar -Jcf kflash_gui.tar.xz kflash_gui || exit -1 ; \
  52. " \
  53. """
  54. result = os.system(cmd)
  55. if result != 0:
  56. exit(1)