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.

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