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.

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