You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

158 lines
4.0 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
  1. #!/usr/bin/env python2
  2. import os
  3. import sys
  4. import shutil
  5. PY2EXE = len(sys.argv) >= 2 and sys.argv[1] == 'py2exe'
  6. if PY2EXE:
  7. try:
  8. import py2exe
  9. except ImportError as error:
  10. print error
  11. sys.exit(1)
  12. from distutils.core import setup
  13. from distutils.sysconfig import get_python_lib
  14. from youtube_dl_gui import (
  15. __author__,
  16. __appname__,
  17. __contact__,
  18. __version__,
  19. __license__,
  20. __projecturl__,
  21. __description__,
  22. __descriptionfull__
  23. )
  24. ICONS_SIZES = ('16x16', '32x32', '48x48', '64x64', '128x128', '256x256')
  25. ICONS_TEMPLATE = 'youtube_dl_gui/icons/youtube-dl-gui_{size}.png'
  26. ICONS_LIST = [ICONS_TEMPLATE.format(size=size) for size in ICONS_SIZES]
  27. # Set icons path
  28. PY2EXE_ICONS = 'icons'
  29. WINDOWS_ICONS = os.path.join(get_python_lib(), 'youtube_dl_gui', 'icons')
  30. LINUX_ICONS = '/usr/share/icons/hicolor/'
  31. LINUX_FALLBACK_ICONS = '/usr/share/pixmaps/'
  32. # Set localization files path
  33. LOCALE_PATH = os.path.join('youtube_dl_gui', 'locale')
  34. PY2EXE_LOCALE_DIR = 'locale'
  35. WIN_LOCALE_DIR = os.path.join(get_python_lib(), 'youtube_dl_gui', 'locale')
  36. LINUX_LOCALE_DIR = '/usr/share/{app_name}/locale/'.format(app_name=__appname__.lower())
  37. def create_scripts():
  38. if not os.path.exists('build/_scripts/'):
  39. os.makedirs('build/_scripts')
  40. shutil.copyfile('youtube_dl_gui/__main__.py', 'build/_scripts/youtube-dl-gui')
  41. def set_locale_files(data_files):
  42. for directory in os.listdir(LOCALE_PATH):
  43. locale_lang = os.path.join(directory, 'LC_MESSAGES')
  44. src = os.path.join(LOCALE_PATH, locale_lang, 'youtube_dl_gui.mo')
  45. if PY2EXE:
  46. dst = os.path.join(PY2EXE_LOCALE_DIR, locale_lang)
  47. elif os.name == 'nt':
  48. dst = os.path.join(WIN_LOCALE_DIR, locale_lang)
  49. else:
  50. dst = os.path.join(LINUX_LOCALE_DIR, locale_lang)
  51. data_files.append((dst, [src]))
  52. def py2exe_setup():
  53. py2exe_dependencies = [
  54. 'C:\\Windows\\System32\\ffmpeg.exe',
  55. 'C:\\Windows\\System32\\ffprobe.exe',
  56. 'C:\\python27\\DLLs\\MSVCP90.dll'
  57. ]
  58. py2exe_data_files = [
  59. ('', py2exe_dependencies),
  60. (PY2EXE_ICONS, ICONS_LIST)
  61. ]
  62. set_locale_files(py2exe_data_files)
  63. py2exe_options = {
  64. 'includes': ['wx.lib.pubsub.*',
  65. 'wx.lib.pubsub.core.*',
  66. 'wx.lib.pubsub.core.arg1.*']
  67. }
  68. py2exe_windows = {
  69. 'script': 'youtube_dl_gui\\__main__.py',
  70. 'icon_resources': [(0, 'youtube_dl_gui\\icons\\youtube-dl-gui.ico')]
  71. }
  72. params = {
  73. 'data_files': py2exe_data_files,
  74. 'windows': [py2exe_windows],
  75. 'options': {'py2exe': py2exe_options}
  76. }
  77. return params
  78. def normal_setup():
  79. data_files = list()
  80. if os.name == 'nt':
  81. icons_dir = (WINDOWS_ICONS, ICONS_LIST)
  82. data_files.append(icons_dir)
  83. set_locale_files(data_files)
  84. params = {'data_files': data_files}
  85. else:
  86. # Create all the hicolor icons
  87. for index, size in enumerate(ICONS_SIZES):
  88. icons_dest = os.path.join(LINUX_ICONS, size, 'apps')
  89. icons_dir = (icons_dest, [ICONS_LIST[index]])
  90. data_files.append(icons_dir)
  91. # Add the 48x48 icon as fallback
  92. fallback_icon = (LINUX_FALLBACK_ICONS, [ICONS_LIST[2]])
  93. data_files.append(fallback_icon)
  94. set_locale_files(data_files)
  95. create_scripts()
  96. params = {'data_files': data_files, 'scripts': ['build/_scripts/youtube-dl-gui']}
  97. return params
  98. if PY2EXE:
  99. params = py2exe_setup()
  100. else:
  101. params = normal_setup()
  102. setup(
  103. author = __author__,
  104. name = __appname__,
  105. version = __version__,
  106. license = __license__,
  107. author_email = __contact__,
  108. url = __projecturl__,
  109. description = __description__,
  110. long_description = __descriptionfull__,
  111. packages = ['youtube_dl_gui'],
  112. **params
  113. )