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.

169 lines
4.1 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. if not os.path.exists('build/_scripts/'):
  46. os.makedirs('build/_scripts')
  47. shutil.copyfile('youtube_dl_gui/__main__.py', 'build/_scripts/youtube-dl-gui')
  48. def set_locale_files(data_files):
  49. for directory in os.listdir(LOCALE_PATH):
  50. locale_lang = os.path.join(directory, 'LC_MESSAGES')
  51. src = os.path.join(LOCALE_PATH, locale_lang, 'youtube_dl_gui.mo')
  52. if PY2EXE:
  53. dst = os.path.join(PY2EXE_LOCALE_DIR, locale_lang)
  54. elif os.name == 'nt':
  55. dst = os.path.join(WIN_LOCALE_DIR, locale_lang)
  56. else:
  57. dst = os.path.join(LINUX_LOCALE_DIR, locale_lang)
  58. data_files.append((dst, [src]))
  59. def py2exe_setup():
  60. py2exe_dependencies = [
  61. 'C:\\Windows\\System32\\ffmpeg.exe',
  62. 'C:\\Windows\\System32\\ffprobe.exe',
  63. 'C:\\python27\\DLLs\\MSVCP90.dll'
  64. ]
  65. py2exe_data_files = [
  66. ('', py2exe_dependencies),
  67. (PY2EXE_ICONS, ICONS_LIST)
  68. ]
  69. set_locale_files(py2exe_data_files)
  70. py2exe_options = {
  71. 'includes': ['wx.lib.pubsub.*',
  72. 'wx.lib.pubsub.core.*',
  73. 'wx.lib.pubsub.core.arg1.*']
  74. }
  75. py2exe_windows = {
  76. 'script': 'youtube_dl_gui\\__main__.py',
  77. 'icon_resources': [(0, 'youtube_dl_gui\\icons\\youtube-dl-gui.ico')]
  78. }
  79. params = {
  80. 'data_files': py2exe_data_files,
  81. 'windows': [py2exe_windows],
  82. 'options': {'py2exe': py2exe_options}
  83. }
  84. return params
  85. def normal_setup():
  86. data_files = list()
  87. if os.name == 'nt':
  88. icons_dir = (WINDOWS_ICONS, ICONS_LIST)
  89. data_files.append(icons_dir)
  90. set_locale_files(data_files)
  91. params = {'data_files': data_files}
  92. else:
  93. # Create all the hicolor icons
  94. for index, size in enumerate(ICONS_SIZES):
  95. icons_dest = os.path.join(LINUX_ICONS, size, 'apps')
  96. icons_dir = (icons_dest, [ICONS_LIST[index]])
  97. data_files.append(icons_dir)
  98. # Add the 48x48 icon as fallback
  99. fallback_icon = (LINUX_FALLBACK_ICONS, [ICONS_LIST[2]])
  100. data_files.append(fallback_icon)
  101. set_locale_files(data_files)
  102. create_scripts()
  103. params = {'data_files': data_files, 'scripts': ['build/_scripts/youtube-dl-gui']}
  104. return params
  105. if PY2EXE:
  106. params = py2exe_setup()
  107. else:
  108. params = normal_setup()
  109. setup(
  110. author = __author__,
  111. name = __appname__,
  112. version = __version__,
  113. license = __license__,
  114. author_email = __contact__,
  115. url = __projecturl__,
  116. description = __description__,
  117. long_description = __descriptionfull__,
  118. packages = ['youtube_dl_gui'],
  119. **params
  120. )