grab_version.py 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  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 argparse
  12. import codecs
  13. def run():
  14. parser = argparse.ArgumentParser(
  15. epilog=(
  16. 'The printed output may be saved to a file, edited and used as the input for a version resource on any of '
  17. 'the executable targets in a PyInstaller .spec file.'
  18. )
  19. )
  20. parser.add_argument(
  21. 'exe_file',
  22. metavar='exe-file',
  23. help="full pathname of a Windows executable",
  24. )
  25. parser.add_argument(
  26. 'out_filename',
  27. metavar='out-filename',
  28. nargs='?',
  29. default='file_version_info.txt',
  30. help="filename where the grabbed version info will be saved",
  31. )
  32. args = parser.parse_args()
  33. try:
  34. import PyInstaller.utils.win32.versioninfo
  35. vs = PyInstaller.utils.win32.versioninfo.decode(args.exe_file)
  36. if not vs:
  37. raise SystemExit("Error: VersionInfo resource not found in exe")
  38. with codecs.open(args.out_filename, 'w', 'utf-8') as fp:
  39. fp.write(str(vs))
  40. print('Version info written to: %s' % args.out_filename)
  41. except KeyboardInterrupt:
  42. raise SystemExit("Aborted by user request.")
  43. if __name__ == '__main__':
  44. run()