grab_version.py 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. #-----------------------------------------------------------------------------
  2. # Copyright (c) 2013-2021, PyInstaller Development Team.
  3. #
  4. # Distributed under the terms of the GNU General Public License (version 2
  5. # or later) with exception for distributing the bootloader.
  6. #
  7. # The full license is in the file COPYING.txt, distributed with this software.
  8. #
  9. # SPDX-License-Identifier: (GPL-2.0-or-later WITH Bootloader-exception)
  10. #-----------------------------------------------------------------------------
  11. import codecs
  12. import argparse
  13. def run():
  14. parser = argparse.ArgumentParser(
  15. epilog = ('The printed output may be saved to a file, edited and '
  16. 'used as the input for a version resource on any of the '
  17. 'executable targets in an Installer spec file.'))
  18. parser.add_argument('exe_file', metavar='exe-file',
  19. help="full pathname of a Windows executable")
  20. parser.add_argument('out_filename', metavar='out-filename', nargs='?',
  21. default='file_version_info.txt',
  22. help=("filename where the grabbed version info "
  23. "will be saved"))
  24. args = parser.parse_args()
  25. try:
  26. import PyInstaller.utils.win32.versioninfo
  27. vs = PyInstaller.utils.win32.versioninfo.decode(args.exe_file)
  28. if not vs:
  29. raise SystemExit("Error: VersionInfo resource not found in exe")
  30. with codecs.open(args.out_filename, 'w', 'utf-8') as fp:
  31. fp.write(u"%s" % (vs,))
  32. print('Version info written to: %s' % args.out_filename)
  33. except KeyboardInterrupt:
  34. raise SystemExit("Aborted by user request.")
  35. if __name__ == '__main__':
  36. run()