pyinst.py 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. from PyInstaller.utils.win32.versioninfo import (
  2. VarStruct, VarFileInfo, StringStruct, StringTable,
  3. StringFileInfo, FixedFileInfo, VSVersionInfo, SetVersion,
  4. )
  5. import PyInstaller.__main__
  6. from datetime import datetime
  7. FILE_DESCRIPTION = 'Media Downloader'
  8. exec(compile(open('youtube_dlc/version.py').read(), 'youtube_dlc/version.py', 'exec'))
  9. _LATEST_VERSION = locals()['__version__']
  10. _OLD_VERSION = _LATEST_VERSION.rsplit("-", 1)
  11. if len(_OLD_VERSION) > 0:
  12. old_ver = _OLD_VERSION[0]
  13. old_rev = ''
  14. if len(_OLD_VERSION) > 1:
  15. old_rev = _OLD_VERSION[1]
  16. ver = f'{datetime.today():%Y.%m.%d}'
  17. rev = ''
  18. if old_ver == ver:
  19. if old_rev:
  20. rev = int(old_rev) + 1
  21. else:
  22. rev = 1
  23. _SEPARATOR = '-'
  24. version = _SEPARATOR.join(filter(None, [ver, str(rev)]))
  25. print(version)
  26. version_list = ver.split(".")
  27. _year, _month, _day = [int(value) for value in version_list]
  28. _rev = 0
  29. if rev:
  30. _rev = rev
  31. _ver_tuple = _year, _month, _day, _rev
  32. version_file = VSVersionInfo(
  33. ffi=FixedFileInfo(
  34. filevers=_ver_tuple,
  35. prodvers=_ver_tuple,
  36. mask=0x3F,
  37. flags=0x0,
  38. OS=0x4,
  39. fileType=0x1,
  40. subtype=0x0,
  41. date=(0, 0),
  42. ),
  43. kids=[
  44. StringFileInfo(
  45. [
  46. StringTable(
  47. "040904B0",
  48. [
  49. StringStruct("Comments", "Youtube-dlc Command Line Interface."),
  50. StringStruct("CompanyName", "theidel@uni-bremen.de"),
  51. StringStruct("FileDescription", FILE_DESCRIPTION),
  52. StringStruct("FileVersion", version),
  53. StringStruct("InternalName", "youtube-dlc"),
  54. StringStruct(
  55. "LegalCopyright",
  56. "theidel@uni-bremen.de | UNLICENSE",
  57. ),
  58. StringStruct("OriginalFilename", "youtube-dlc.exe"),
  59. StringStruct("ProductName", "Youtube-dlc"),
  60. StringStruct("ProductVersion", version + " | git.io/JUGsM"),
  61. ],
  62. )
  63. ]
  64. ),
  65. VarFileInfo([VarStruct("Translation", [0, 1200])])
  66. ]
  67. )
  68. PyInstaller.__main__.run([
  69. '--name=youtube-dlc',
  70. '--onefile',
  71. '--icon=win/icon/cloud.ico',
  72. 'youtube_dlc/__main__.py',
  73. ])
  74. SetVersion('dist/youtube-dlc.exe', version_file)