_assemble_launchers.py 833 B

123456789101112131415161718192021222324252627282930313233
  1. """This is run during installation to assemble command-line exe launchers
  2. Each launcher contains: exe base + shebang + zipped Python code
  3. """
  4. import glob
  5. import os
  6. import sys
  7. b_shebang = '#!"{}"\r\n'.format(sys.executable).encode('utf-8')
  8. def assemble_exe(path, b_launcher):
  9. exe_path = path[:-len('-append.zip')] + '.exe'
  10. with open(exe_path, 'wb') as f:
  11. f.write(b_launcher)
  12. f.write(b_shebang)
  13. with open(path, 'rb') as f2:
  14. f.write(f2.read())
  15. def main(argv=None):
  16. if argv is None:
  17. argv = sys.argv
  18. target_dir = argv[1]
  19. with open(os.path.join(target_dir, 'launcher_exe.dat'), 'rb') as f:
  20. b_launcher = f.read()
  21. for path in glob.glob(os.path.join(target_dir, '*-append.zip')):
  22. assemble_exe(path, b_launcher)
  23. if __name__ == '__main__':
  24. main()