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.

205 lines
5.2 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. # -*- coding: utf-8 -*-
  3. """Youtube-dlg setup file.
  4. Note:
  5. If you get 'TypeError: decoding Unicode is not supported' when you run
  6. py2exe then apply the following patch:
  7. http://sourceforge.net/p/py2exe/patches/28/
  8. """
  9. import os
  10. import sys
  11. import shutil
  12. PY2EXE = len(sys.argv) >= 2 and sys.argv[1] == 'py2exe'
  13. if PY2EXE:
  14. try:
  15. import py2exe
  16. except ImportError as error:
  17. print error
  18. sys.exit(1)
  19. PY2APP = len(sys.argv) >= 2 and sys.argv[1] == 'py2app'
  20. if PY2APP:
  21. try:
  22. import py2app
  23. except ImportError as error:
  24. print error
  25. sys.exit(1)
  26. from distutils.core import setup
  27. from distutils.sysconfig import get_python_lib
  28. from youtube_dl_gui import (
  29. __author__,
  30. __appname__,
  31. __contact__,
  32. __version__,
  33. __license__,
  34. __projecturl__,
  35. __description__,
  36. __descriptionfull__
  37. )
  38. ICONS_SIZES = ('16x16', '32x32', '48x48', '64x64', '128x128', '256x256')
  39. ICONS_TEMPLATE = 'youtube_dl_gui/icons/youtube-dl-gui_{size}.png'
  40. ICONS_LIST = [ICONS_TEMPLATE.format(size=size) for size in ICONS_SIZES]
  41. # Set icons path
  42. PY2EXE_ICONS = 'icons'
  43. WINDOWS_ICONS = os.path.join(get_python_lib(), 'youtube_dl_gui', 'icons')
  44. LINUX_ICONS = '/usr/share/icons/hicolor/'
  45. LINUX_FALLBACK_ICONS = '/usr/share/pixmaps/'
  46. # Set localization files path
  47. LOCALE_PATH = os.path.join('youtube_dl_gui', 'locale')
  48. PY2EXE_LOCALE_DIR = 'locale'
  49. WIN_LOCALE_DIR = os.path.join(get_python_lib(), 'youtube_dl_gui', 'locale')
  50. LINUX_LOCALE_DIR = '/usr/share/{app_name}/locale/'.format(app_name=__appname__.lower())
  51. OSX_PREFIX = '/usr/local/Cellar/youtube-dl-gui/{version}'.format(version=__version__)
  52. OSX_LOCALE_DIR = '{prefix}/share/locale'.format(prefix=OSX_PREFIX)
  53. OSX_APP = '{prefix}/YoutubeDlGui.app'.format(prefix=OSX_PREFIX)
  54. def create_scripts():
  55. dest_dir = os.path.join('build', '_scripts')
  56. dest_file = os.path.join(dest_dir, 'youtube-dl-gui')
  57. src_file = os.path.join('youtube_dl_gui', '__main__.py')
  58. if not os.path.exists(dest_dir):
  59. os.makedirs(dest_dir)
  60. shutil.copyfile(src_file, dest_file)
  61. def set_locale_files(data_files):
  62. for directory in os.listdir(LOCALE_PATH):
  63. locale_lang = os.path.join(directory, 'LC_MESSAGES')
  64. src = os.path.join(LOCALE_PATH, locale_lang, 'youtube_dl_gui.mo')
  65. if PY2EXE:
  66. dst = os.path.join(PY2EXE_LOCALE_DIR, locale_lang)
  67. elif os.name == 'nt':
  68. dst = os.path.join(WIN_LOCALE_DIR, locale_lang)
  69. elif sys.platform == 'darwin':
  70. dst = os.path.join(OSX_LOCALE_DIR, locale_lang)
  71. else:
  72. dst = os.path.join(LINUX_LOCALE_DIR, locale_lang)
  73. data_files.append((dst, [src]))
  74. def py2exe_setup():
  75. create_scripts()
  76. py2exe_dependencies = [
  77. 'C:\\Windows\\System32\\ffmpeg.exe',
  78. 'C:\\Windows\\System32\\ffprobe.exe',
  79. 'C:\\python27\\DLLs\\MSVCP90.dll'
  80. ]
  81. py2exe_data_files = [
  82. ('', py2exe_dependencies),
  83. (PY2EXE_ICONS, ICONS_LIST)
  84. ]
  85. set_locale_files(py2exe_data_files)
  86. py2exe_options = {
  87. 'includes': ['wx.lib.pubsub.*',
  88. 'wx.lib.pubsub.core.*',
  89. 'wx.lib.pubsub.core.arg1.*']
  90. }
  91. py2exe_windows = {
  92. 'script': 'build\\_scripts\\youtube-dl-gui',
  93. 'icon_resources': [(0, 'youtube_dl_gui\\icons\\youtube-dl-gui.ico')]
  94. }
  95. params = {
  96. 'data_files': py2exe_data_files,
  97. 'windows': [py2exe_windows],
  98. 'options': {'py2exe': py2exe_options}
  99. }
  100. return params
  101. def py2app_setup():
  102. data_files = []
  103. create_scripts()
  104. set_locale_files(data_files)
  105. params = {
  106. 'data_files': data_files,
  107. 'app': ['build/_scripts/youtube-dl-gui'],
  108. 'setup_requires': ['py2app'],
  109. 'options': {'py2app': {'argv_emulation': True, 'iconfile': 'youtube_dl_gui/icons/osx/YoutubeDlGui.icns'}},
  110. }
  111. return params
  112. def normal_setup():
  113. data_files = list()
  114. if os.name == 'nt':
  115. icons_dir = (WINDOWS_ICONS, ICONS_LIST)
  116. data_files.append(icons_dir)
  117. set_locale_files(data_files)
  118. params = {'data_files': data_files}
  119. else:
  120. # Create all the hicolor icons
  121. for index, size in enumerate(ICONS_SIZES):
  122. icons_dest = os.path.join(LINUX_ICONS, size, 'apps')
  123. icons_dir = (icons_dest, [ICONS_LIST[index]])
  124. data_files.append(icons_dir)
  125. # Add the 48x48 icon as fallback
  126. fallback_icon = (LINUX_FALLBACK_ICONS, [ICONS_LIST[2]])
  127. data_files.append(fallback_icon)
  128. set_locale_files(data_files)
  129. create_scripts()
  130. params = {'data_files': data_files, 'scripts': ['build/_scripts/youtube-dl-gui']}
  131. return params
  132. if PY2EXE:
  133. params = py2exe_setup()
  134. else:
  135. if PY2APP:
  136. params = py2app_setup()
  137. else:
  138. params = normal_setup()
  139. setup(
  140. author = __author__,
  141. name = __appname__,
  142. version = __version__,
  143. license = __license__,
  144. author_email = __contact__,
  145. url = __projecturl__,
  146. description = __description__,
  147. long_description = __descriptionfull__,
  148. packages = ['youtube_dl_gui'],
  149. **params
  150. )